pep8 conversion of python algos (#7942)

* pep8 conversion of python algos

* adding 10 more pep8 converted algos
This commit is contained in:
Ashutosh
2024-04-18 23:44:56 +05:30
committed by GitHub
parent ed351c8726
commit 1cae47ab25
15 changed files with 363 additions and 360 deletions
@@ -14,36 +14,36 @@
from AlgorithmImports import *
### <summary>
### Regression algorithm asserting the behavior of Universe.Selected collection
### Regression algorithm asserting the behavior of Universe.SELECTED collection
### </summary>
class UniverseSelectedRegressionAlgorithm(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2014, 3, 25)
self.SetEndDate(2014, 3, 27)
def initialize(self):
self.set_start_date(2014, 3, 25)
self.set_end_date(2014, 3, 27)
self.UniverseSettings.Resolution = Resolution.Daily
self.universe_settings.resolution = Resolution.DAILY
self._universe = self.AddUniverse(self.SelectionFunction)
self.selectionCount = 0
self._universe = self.add_universe(self.selection_function)
self.selection_count = 0
def SelectionFunction(self, fundamentals):
sortedByDollarVolume = sorted(fundamentals, key=lambda x: x.DollarVolume, reverse=True)
def selection_function(self, fundamentals):
sorted_by_dollar_volume = sorted(fundamentals, key=lambda x: x.dollar_volume, reverse=True)
sortedByDollarVolume = sortedByDollarVolume[self.selectionCount:]
self.selectionCount = self.selectionCount + 1
sorted_by_dollar_volume = sorted_by_dollar_volume[self.selection_count:]
self.selection_count = self.selection_count + 1
# return the symbol objects of the top entries from our sorted collection
return [ x.Symbol for x in sortedByDollarVolume[:self.selectionCount] ]
return [ x.symbol for x in sorted_by_dollar_volume[:self.selection_count] ]
def OnData(self, data):
if Symbol.Create("TSLA", SecurityType.Equity, Market.USA) in self._universe.Selected:
def on_data(self, data):
if Symbol.create("TSLA", SecurityType.EQUITY, Market.USA) in self._universe.selected:
raise ValueError(f"TSLA shouldn't of been selected")
self.Buy(next(iter(self._universe.Selected)), 1)
self.buy(next(iter(self._universe.selected)), 1)
def OnEndOfAlgorithm(self):
if self.selectionCount != 3:
raise ValueError(f"Unexpected selection count {self.selectionCount}")
if self._universe.Selected.Count != 3 or self._universe.Selected.Count == self._universe.Members.Count:
raise ValueError(f"Unexpected universe selected count {self._universe.Selected.Count}")
def on_end_of_algorithm(self):
if self.selection_count != 3:
raise ValueError(f"Unexpected selection count {self.selection_count}")
if self._universe.selected.count != 3 or self._universe.selected.count == self._universe.members.count:
raise ValueError(f"Unexpected universe selected count {self._universe.selected.count}")