pep8 conversion of python algos #5 (#7943)

* pep8 conversion

* Fix: detect python object of python classes derived from c# classes

* Minor PEP8 updates/fixes

---------

Co-authored-by: Jhonathan Abreu <jdabreu25@gmail.com>
This commit is contained in:
Louis Szeto
2024-04-19 02:53:32 +08:00
committed by GitHub
parent 5eb236834f
commit c2ad893f32
28 changed files with 847 additions and 858 deletions
@@ -16,37 +16,37 @@ from AlgorithmImports import *
### Regression algorithm to demonstrate the use of SetBenchmark() with custom data
### </summary>
class CustomDataBenchmarkRegressionAlgorithm(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2017, 8, 18) # Set Start Date
self.SetEndDate(2017, 8, 21) # Set End Date
self.SetCash(100000) # Set Strategy Cash
def initialize(self):
self.set_start_date(2017, 8, 18) # Set Start Date
self.set_end_date(2017, 8, 21) # Set End Date
self.set_cash(100000) # Set Strategy Cash
self.AddEquity("SPY", Resolution.Hour)
self.add_equity("SPY", Resolution.HOUR)
# Load benchmark data
self.customSymbol = self.AddData(ExampleCustomData, "ExampleCustomData", Resolution.Hour).Symbol
self.SetBenchmark(self.customSymbol)
self.custom_symbol = self.add_data(ExampleCustomData, "ExampleCustomData", Resolution.HOUR).symbol
self.set_benchmark(self.custom_symbol)
def OnData(self, data):
if not self.Portfolio.Invested:
self.SetHoldings("SPY", 1)
def on_data(self, data):
if not self.portfolio.invested:
self.set_holdings("SPY", 1)
def OnEndOfAlgorithm(self):
securityBenchmark = self.Benchmark;
if securityBenchmark.Security.Price == 0:
def on_end_of_algorithm(self):
security_benchmark = self.benchmark;
if security_benchmark.security.price == 0:
raise Exception("Security benchmark price was not expected to be zero")
class ExampleCustomData(PythonData):
def GetSource(self, config, date, isLive):
def get_source(self, config, date, is_live):
source = "https://www.dl.dropboxusercontent.com/s/d83xvd7mm9fzpk0/path_to_my_csv_data.csv?dl=0";
return SubscriptionDataSource(source, SubscriptionTransportMedium.RemoteFile)
return SubscriptionDataSource(source, SubscriptionTransportMedium.REMOTE_FILE)
def Reader(self, config, line, date, isLive):
def reader(self, config, line, date, is_live):
data = line.split(',')
obj_data = ExampleCustomData()
obj_data.Symbol = config.Symbol
obj_data.Time = datetime.strptime(data[0], '%Y-%m-%d %H:%M:%S') + timedelta(hours=20)
obj_data.Value = float(data[4])
obj_data.symbol = config.symbol
obj_data.time = datetime.strptime(data[0], '%Y-%m-%d %H:%M:%S') + timedelta(hours=20)
obj_data.value = float(data[4])
obj_data["Open"] = float(data[1])
obj_data["High"] = float(data[2])
obj_data["Low"] = float(data[3])