pep8 conversion of python algos (#7948)

* pep8 conversion of python algos

* adding 10 more pep8 converted algos

* PEP8 updates/fixes

---------

Co-authored-by: Jhonathan Abreu <jdabreu25@gmail.com>
This commit is contained in:
Ashutosh
2024-04-19 19:36:48 +05:30
committed by GitHub
parent 77591f90c7
commit 3c30e255fe
21 changed files with 490 additions and 491 deletions
@@ -19,41 +19,40 @@ from collections import deque
### specifically when this class is a subclass of a C# class.
### </summary>
class SecurityDynamicPropertyPythonClassAlgorithm(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2013, 10, 7)
self.SetEndDate(2013, 10, 7)
def initialize(self):
self.set_start_date(2013, 10, 7)
self.set_end_date(2013, 10, 7)
self.spy = self.AddEquity("SPY", Resolution.Minute)
self.spy = self.add_equity("SPY", Resolution.MINUTE)
customSMA = CustomSimpleMovingAverage('custom', 60)
self.spy.CustomSMA = customSMA
customSMA.Security = self.spy
custom_sma = CustomSimpleMovingAverage('custom', 60)
self.spy.custom_sma = custom_sma
custom_sma.security = self.spy
self.RegisterIndicator(self.spy.Symbol, self.spy.CustomSMA, Resolution.Minute)
self.register_indicator(self.spy.symbol, self.spy.custom_sma, Resolution.MINUTE)
def on_warmup_finished(self) -> None:
if type(self.spy.custom_sma) != CustomSimpleMovingAverage:
raise Exception("spy.custom_sma is not an instance of CustomSimpleMovingAverage")
def OnWarmupFinished(self) -> None:
if type(self.spy.CustomSMA) != CustomSimpleMovingAverage:
raise Exception("spy.CustomSMA is not an instance of CustomSimpleMovingAverage")
if self.spy.CustomSMA.Security is None:
raise Exception("spy.CustomSMA.Security is None")
if self.spy.custom_sma.security is None:
raise Exception("spy.custom_sma.security is None")
else:
self.Debug(f"spy.CustomSMA.Security.Symbol: {self.spy.CustomSMA.Security.Symbol}")
self.debug(f"spy.custom_sma.security.symbol: {self.spy.custom_sma.security.symbol}")
def OnData(self, slice: Slice) -> None:
if self.spy.CustomSMA.IsReady:
self.Debug(f"CustomSMA: {self.spy.CustomSMA.Current.Value}")
def on_data(self, slice: Slice) -> None:
if self.spy.custom_sma.is_ready:
self.debug(f"CustomSMA: {self.spy.custom_sma.current.value}")
class CustomSimpleMovingAverage(PythonIndicator):
def __init__(self, name, period):
super().__init__()
self.Name = name
self.Value = 0
self.name = name
self.value = 0
self.queue = deque(maxlen=period)
def Update(self, input):
self.queue.appendleft(input.Value)
def update(self, input):
self.queue.appendleft(input.value)
count = len(self.queue)
self.Value = np.sum(self.queue) / count
self.value = np.sum(self.queue) / count
return count == self.queue.maxlen