Fix bug/syntax in python examples (#8658)
* CustomDataRegressionAlgorithm * DescendingCustomDataObjectStoreRegressionAlgorithm * CustomDataPropertiesRegressionAlgorithm * DateTime -> should be datetime * KerasNeuralNetworkAlgorithm * OptionIndicatorsMirrorContractsRegressionAlgorithm * BybitCustomDataCryptoRegressionAlgorithm * DropboxBaseDataUniverseSelectionAlgorithm * UserDefinedUniverseAlgorithm * CompleteOrderTagUpdateAlgorithm * BasicTemplateOptionEquityStrategyAlgorithm hint * ETFConstituentUniverseFrameworkRegressionAlgorithm * FutureStopMarketOrderOnExtendedHoursRegressionAlgorithm * SecurityDynamicPropertyPythonClassAlgorithm * hint * hinting * CallbackCommandRegressionAlgorithm * CustomWarmUpPeriodIndicatorAlgorithm * CrunchDAOSignalExportDemonstrationAlgorithm * ExpiryHelperAlphaModelFrameworkAlgorithm * ClassicRenkoConsolidatorAlgorithm * SmaCrossUniverseSelectionAlgorithm * PEP8 Fix: Assigning to a Method * SliceGetByTypeRegressionAlgorithm * MarketOnCloseOrderBufferExtendedMarketHoursRegressionAlgorithm * MarketOnCloseOrderBufferRegressionAlgorithm * CustomIndicatorAlgorithm * ScheduledQueuingAlgorithm * ComboOrdersFillModelAlgorithm * CustomIndicatorWithExtensionAlgorithm * IndicatorWithRenkoBarsRegressionAlgorithm * CoarseFineOptionUniverseChainRegressionAlgorithm * NumeraiSignalExportDemonstrationAlgorithm * DropboxUniverseSelectionAlgorithm * WeeklyUniverseSelectionRegressionAlgorithm * AutoRegressiveIntegratedMovingAverageRegressionAlgorithm * DropboxBaseDataUniverseSelectionAlgorithm * IronCondorStrategyAlgorithm * LongAndShortButterflyPutStrategiesAlgorithm * FutureStopMarketOrderOnExtendedHoursRegressionAlgorithm * LongAndShortCallCalendarSpreadStrategiesAlgorithm * KerasNeuralNetworkAlgorithm * LongAndShortPutCalendarSpreadStrategiesAlgorithm * OptionPriceModelForOptionStylesBaseRegressionAlgorithm * TensorFlowNeuralNetworkAlgorithm * MarketOnCloseOrderBufferRegressionAlgorithm * MarketOnCloseOrderBufferExtendedMarketHoursRegressionAlgorithm * typing * ComboOrderTicketDemoAlgorithm * PytorchNeuralNetworkAlgorithm * MultipleSymbolConsolidationAlgorithm * fixes * revert getattr mypy syntax * address peer review * Addresses Peer-Review --------- Co-authored-by: Alexandre Catarino <AlexCatarino@users.noreply.github.com>
This commit is contained in:
@@ -19,7 +19,7 @@ from AlgorithmImports import *
|
||||
class ExpiryHelperAlphaModelFrameworkAlgorithm(QCAlgorithm):
|
||||
'''Expiry Helper framework algorithm uses Expiry helper class in an Alpha Model'''
|
||||
|
||||
def initialize(self):
|
||||
def initialize(self) -> None:
|
||||
''' Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.'''
|
||||
|
||||
# Set requested data resolution
|
||||
@@ -40,23 +40,22 @@ class ExpiryHelperAlphaModelFrameworkAlgorithm(QCAlgorithm):
|
||||
|
||||
self.insights_generated += self.on_insights_generated
|
||||
|
||||
def on_insights_generated(self, s, e):
|
||||
def on_insights_generated(self, s: IAlgorithm, e: GeneratedInsightsCollection) -> None:
|
||||
for insight in e.insights:
|
||||
self.log(f"{e.date_time_utc.isoweekday()}: Close Time {insight.close_time_utc} {insight.close_time_utc.isoweekday()}")
|
||||
|
||||
class ExpiryHelperAlphaModel(AlphaModel):
|
||||
next_update = None
|
||||
direction = InsightDirection.UP
|
||||
_next_update = None
|
||||
_direction = InsightDirection.UP
|
||||
|
||||
def update(self, algorithm, data):
|
||||
|
||||
if self.next_update is not None and self.next_update > algorithm.time:
|
||||
def update(self, algorithm: QCAlgorithm, data: Slice) -> list[Insight]:
|
||||
if self._next_update and self._next_update > algorithm.time:
|
||||
return []
|
||||
|
||||
expiry = Expiry.END_OF_DAY
|
||||
|
||||
# Use the Expiry helper to calculate a date/time in the future
|
||||
self.next_update = expiry(algorithm.time)
|
||||
self._next_update = expiry(algorithm.time)
|
||||
|
||||
weekday = algorithm.time.isoweekday()
|
||||
|
||||
@@ -64,15 +63,15 @@ class ExpiryHelperAlphaModelFrameworkAlgorithm(QCAlgorithm):
|
||||
for symbol in data.bars.keys():
|
||||
# Expected CloseTime: next month on the same day and time
|
||||
if weekday == 1:
|
||||
insights.append(Insight.price(symbol, Expiry.ONE_MONTH, self.direction))
|
||||
insights.append(Insight.price(symbol, Expiry.ONE_MONTH, self._direction))
|
||||
# Expected CloseTime: next month on the 1st at market open time
|
||||
elif weekday == 2:
|
||||
insights.append(Insight.price(symbol, Expiry.END_OF_MONTH, self.direction))
|
||||
insights.append(Insight.price(symbol, Expiry.END_OF_MONTH, self._direction))
|
||||
# Expected CloseTime: next Monday at market open time
|
||||
elif weekday == 3:
|
||||
insights.append(Insight.price(symbol, Expiry.END_OF_WEEK, self.direction))
|
||||
insights.append(Insight.price(symbol, Expiry.END_OF_WEEK, self._direction))
|
||||
# Expected CloseTime: next day (Friday) at market open time
|
||||
elif weekday == 4:
|
||||
insights.append(Insight.price(symbol, Expiry.END_OF_DAY, self.direction))
|
||||
insights.append(Insight.price(symbol, Expiry.END_OF_DAY, self._direction))
|
||||
|
||||
return insights
|
||||
|
||||
Reference in New Issue
Block a user