Skip to content

Commit b81bcf0

Browse files
Minor syntax fixes for python algorithms (#8705)
1 parent e34a7e0 commit b81bcf0

11 files changed

+13
-16
lines changed

Algorithm.Python/AllShortableSymbolsCoarseSelectionRegressionAlgorithm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def __init__(self):
109109
Gets a list of all shortable Symbols, including the quantity shortable as a Dictionary.
110110
"""
111111
def all_shortable_symbols(self, localtime):
112-
shortable_data_directory = os.path.join(Globals.DataFolder, "equity", Market.USA, "shortable", self.brokerage)
112+
shortable_data_directory = os.path.join(Globals.data_folder, "equity", Market.USA, "shortable", self.brokerage)
113113
all_symbols = {}
114114

115115
"""

Algorithm.Python/BasicTemplateOptionStrategyAlgorithm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def on_data(self,slice):
5555
if len(contracts) == 0: continue
5656
atm_straddle = contracts[0]
5757
if atm_straddle != None:
58-
self.sell(OptionStrategies.STRADDLE(self.option_symbol, atm_straddle.strike, atm_straddle.expiry), 2)
58+
self.sell(OptionStrategies.straddle(self.option_symbol, atm_straddle.strike, atm_straddle.expiry), 2)
5959
else:
6060
self.liquidate()
6161

Algorithm.Python/CapmAlphaRankingFrameworkAlgorithm.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class CapmAlphaRankingUniverseSelectionModel(UniverseSelectionModel):
4444
benchmark = "SPY"
4545

4646
# Symbols of Dow 30 companies.
47-
symbols = [Symbol.create(x, SecurityType.EQUITY, Market.USA)
47+
_symbols = [Symbol.create(x, SecurityType.EQUITY, Market.USA)
4848
for x in ["AAPL", "AXP", "BA", "CAT", "CSCO", "CVX", "DD", "DIS", "GE", "GS",
4949
"HD", "IBM", "INTC", "JPM", "KO", "MCD", "MMM", "MRK", "MSFT",
5050
"NKE","PFE", "PG", "TRV", "UNH", "UTX", "V", "VZ", "WMT", "XOM"]]
@@ -60,8 +60,7 @@ def create_universes(self, algorithm):
6060
algorithm.date_rules.month_start(self.benchmark),
6161
algorithm.time_rules.after_market_open(self.benchmark),
6262
lambda datetime: self.select_pair(algorithm, datetime),
63-
algorithm.universe_settings,
64-
algorithm.security_initializer)]
63+
algorithm.universe_settings)]
6564

6665
def select_pair(self, algorithm, date):
6766
'''Selects the pair (two stocks) with the highest alpha'''
@@ -95,7 +94,7 @@ def roc_updated(s, item):
9594

9695
rate_of_change.updated += roc_updated
9796

98-
history = history.close.reset_index(level=0, drop=True).iteritems()
97+
history = history.close.reset_index(level=0, drop=True).items()
9998

10099
for time, value in history:
101100
rate_of_change.update(time, value)

Algorithm.Python/CustomDataUniverseRegressionAlgorithm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def OnSecuritiesChanged(self, changes):
8181
class MyPyCustomData(PythonData):
8282

8383
def get_source(self, config, date, is_live_mode):
84-
source = f"{Globals.DataFolder}/equity/usa/daily/{LeanData.generate_zip_file_name(config.symbol, date, config.resolution, config.tick_type)}"
84+
source = f"{Globals.data_folder}/equity/usa/daily/{LeanData.generate_zip_file_name(config.symbol, date, config.resolution, config.tick_type)}"
8585
return SubscriptionDataSource(source)
8686

8787
def reader(self, config, line, date, is_live_mode):

Algorithm.Python/CustomDataUniverseScheduledRegressionAlgorithm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def on_end_of_algorithm(self):
7272
class MyPyCustomData(PythonData):
7373

7474
def get_source(self, config, date, is_live_mode):
75-
source = f"{Globals.DataFolder}/equity/usa/daily/{LeanData.generate_zip_file_name(config.symbol, date, config.resolution, config.tick_type)}"
75+
source = f"{Globals.data_folder}/equity/usa/daily/{LeanData.generate_zip_file_name(config.symbol, date, config.resolution, config.tick_type)}"
7676
return SubscriptionDataSource(source)
7777

7878
def reader(self, config, line, date, is_live_mode):

Algorithm.Python/CustomIndicatorAlgorithm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def initialize(self) -> None:
3131
self._custom = CustomSimpleMovingAverage('custom', 60)
3232

3333
# The python custom class must inherit from PythonIndicator to enable Updated event handler
34-
self._custom.updated += self._custom_updated
34+
self._custom.updated += self.custom_updated
3535

3636
self._custom_window = RollingWindow[IndicatorDataPoint](5)
3737
self.register_indicator("SPY", self._custom, Resolution.MINUTE)

Algorithm.Python/CustomModelsPEP8Algorithm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def has_sufficient_buying_power_for_order(self, parameters):
117117

118118
class SimpleCustomFillModelPEP8(FillModel):
119119
def __init__(self):
120-
super().__init()
120+
super().__init__()
121121

122122
def _create_order_event(self, asset, order):
123123
utc_time = Extensions.convert_to_utc(asset.local_time, asset.exchange.time_zone)

Algorithm.Python/CustomSecurityInitializerAlgorithm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def initialize(self):
2929
# set our initializer to our custom type
3030
self.set_brokerage_model(BrokerageName.INTERACTIVE_BROKERS_BROKERAGE)
3131

32-
func_security_seeder = FuncSecuritySeeder(Func[Security, BaseData](self.custom_seed_function))
32+
func_security_seeder = FuncSecuritySeeder(self.custom_seed_function)
3333
self.set_security_initializer(CustomSecurityInitializer(self.brokerage_model, func_security_seeder, DataNormalizationMode.RAW))
3434

3535
self.set_start_date(2013,10,1)

Algorithm.Python/FuturesChainFullDataRegressionAlgorithm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def initialize(self):
3232

3333
for index, row in df.iterrows():
3434
if row['bidprice'] == 0 and row['askprice'] == 0 and row['volume'] == 0:
35-
raise Exception("FuturesChain() returned contract with no data.");
35+
raise AssertionError("FuturesChain() returned contract with no data.");
3636

3737
# Get contracts expiring within 6 months, with the latest expiration date, and lowest price
3838
contracts = df.loc[(df.expiry <= self.time + timedelta(days=180))]

Algorithm.Python/HistoryAlgorithm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def assert_history_count(self, method_call, trade_bar_history, expected):
141141
class CustomDataEquity(PythonData):
142142
def get_source(self, config, date, is_live):
143143
zip_file_name = LeanData.generate_zip_file_name(config.Symbol, date, config.Resolution, config.TickType)
144-
source = Globals.DataFolder + "/equity/usa/daily/" + zip_file_name
144+
source = Globals.data_folder + "/equity/usa/daily/" + zip_file_name
145145
return SubscriptionDataSource(source)
146146

147147
def reader(self, config, line, date, is_live):

0 commit comments

Comments
 (0)