Skip to content

Commit a91da2b

Browse files
LouisSzetoAlexCatarino
authored andcommitted
ClassicRenkoConsolidatorAlgorithm
1 parent eebf2af commit a91da2b

3 files changed

Lines changed: 13 additions & 14 deletions

File tree

Algorithm.Python/ClassicRangeConsolidatorAlgorithm.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
### Example algorithm of how to use ClassicRangeConsolidator
2020
### </summary>
2121
class ClassicRangeConsolidatorAlgorithm(RangeConsolidatorAlgorithm):
22-
def create_range_consolidator(self):
22+
def create_range_consolidator(self) -> ClassicRangeConsolidator:
2323
return ClassicRangeConsolidator(self.get_range())
2424

25-
def on_data_consolidated(self, sender, range_bar):
25+
def on_data_consolidated(self, sender: object, range_bar: RangeBar):
2626
super().on_data_consolidated(sender, range_bar)
2727

2828
if range_bar.volume == 0:

Algorithm.Python/ClassicRenkoConsolidatorAlgorithm.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@
2323
class ClassicRenkoConsolidatorAlgorithm(QCAlgorithm):
2424
'''Demonstration of how to initialize and use the RenkoConsolidator'''
2525

26-
def initialize(self):
27-
26+
def initialize(self) -> None:
2827
self.set_start_date(2012, 1, 1)
2928
self.set_end_date(2013, 1, 1)
3029

@@ -48,11 +47,11 @@ def initialize(self):
4847

4948

5049
# We're doing our analysis in the on_renko_bar method, but the framework verifies that this method exists, so we define it.
51-
def on_data(self, data):
50+
def on_data(self, data: Slice) -> None:
5251
pass
5352

5453

55-
def handle_renko_close(self, sender, data):
54+
def handle_renko_close(self, sender: object, data: RenkoBar) -> None:
5655
'''This function is called by our renko_close consolidator defined in Initialize()
5756
Args:
5857
data: The new renko bar produced by the consolidator'''
@@ -62,7 +61,7 @@ def handle_renko_close(self, sender, data):
6261
self.log(f"CLOSE - {data.time} - {data.open} {data.close}")
6362

6463

65-
def handle_renko7_bar(self, sender, data):
64+
def handle_renko7_bar(self, sender: object, data: RenkoBar) -> None:
6665
'''This function is called by our renko7bar consolidator defined in Initialize()
6766
Args:
6867
data: The new renko bar produced by the consolidator'''

Algorithm.Python/RangeConsolidatorAlgorithm.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
### Example algorithm of how to use RangeConsolidator
1818
### </summary>
1919
class RangeConsolidatorAlgorithm(QCAlgorithm):
20-
def get_resolution(self):
20+
def get_resolution(self) -> Resolution:
2121
return Resolution.DAILY
2222

23-
def get_range(self):
23+
def get_range(self) -> int:
2424
return 100
2525

26-
def initialize(self):
26+
def initialize(self) -> None:
2727
self.set_start_and_end_dates();
2828
self.add_equity("SPY", self.get_resolution())
2929
range_consolidator = self.create_range_consolidator()
@@ -32,18 +32,18 @@ def initialize(self):
3232

3333
self.subscription_manager.add_consolidator("SPY", range_consolidator)
3434

35-
def set_start_and_end_dates(self):
35+
def set_start_and_end_dates(self) -> None:
3636
self.set_start_date(2013, 10, 7)
3737
self.set_end_date(2013, 10, 11)
3838

39-
def on_end_of_algorithm(self):
39+
def on_end_of_algorithm(self) -> None:
4040
if self.first_data_consolidated == None:
4141
raise AssertionError("The consolidator should have consolidated at least one RangeBar, but it did not consolidated any one")
4242

43-
def create_range_consolidator(self):
43+
def create_range_consolidator(self) -> RangeConsolidator:
4444
return RangeConsolidator(self.get_range())
4545

46-
def on_data_consolidated(self, sender, range_bar):
46+
def on_data_consolidated(self, sender: object, range_bar: RangeBar) -> None:
4747
if (self.first_data_consolidated is None):
4848
self.first_data_consolidated = range_bar
4949

0 commit comments

Comments
 (0)