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:
Louis Szeto
2025-04-14 20:43:03 +08:00
committed by GitHub
parent fe46e5ec3b
commit 020cf013df
55 changed files with 717 additions and 738 deletions
@@ -18,41 +18,40 @@ from AlgorithmImports import *
### </summary>
class CustomShortableProviderRegressionAlgorithm(QCAlgorithm):
def initialize(self):
def initialize(self) -> None:
self.set_cash(10000000)
self.set_start_date(2013,10,4)
self.set_end_date(2013,10,6)
self.spy = self.add_security(SecurityType.EQUITY, "SPY", Resolution.DAILY)
self.spy.set_shortable_provider(CustomShortableProvider())
self._spy = self.add_security(SecurityType.EQUITY, "SPY", Resolution.DAILY)
self._spy.set_shortable_provider(CustomShortableProvider())
def on_data(self, data):
spy_shortable_quantity = self.spy.shortable_provider.shortable_quantity(self.spy.symbol, self.time)
if spy_shortable_quantity > 1000:
self.order_id = self.sell("SPY", int(spy_shortable_quantity))
def on_data(self, data: Slice) -> None:
spy_shortable_quantity = self._spy.shortable_provider.shortable_quantity(self._spy.symbol, self.time)
if spy_shortable_quantity and spy_shortable_quantity > 1000:
self._order_id = self.sell("SPY", int(spy_shortable_quantity)).order_id
def on_end_of_algorithm(self):
def on_end_of_algorithm(self) -> None:
transactions = self.transactions.orders_count
if transactions != 1:
raise AssertionError("Algorithm should have just 1 order, but was " + str(transactions))
order_quantity = self.transactions.get_order_by_id(self.order_id).quantity
order_quantity = self.transactions.get_order_by_id(self._order_id).quantity
if order_quantity != -1001:
raise AssertionError("Quantity of order " + str(_order_id) + " should be " + str(-1001)+", but was {order_quantity}")
raise AssertionError(f"Quantity of order {self._order_id} should be -1001 but was {order_quantity}")
fee_rate = self.spy.shortable_provider.fee_rate(self.spy.symbol, self.time)
fee_rate = self._spy.shortable_provider.fee_rate(self._spy.symbol, self.time)
if fee_rate != 0.0025:
raise AssertionError(f"Fee rate should be 0.0025, but was {fee_rate}")
rebate_rate = self.spy.shortable_provider.rebate_rate(self.spy.symbol, self.time)
rebate_rate = self._spy.shortable_provider.rebate_rate(self._spy.symbol, self.time)
if rebate_rate != 0.0507:
raise AssertionError(f"Rebate rate should be 0.0507, but was {rebate_rate}")
class CustomShortableProvider(NullShortableProvider):
def fee_rate(self, symbol: Symbol, local_time: DateTime):
def fee_rate(self, symbol: Symbol, local_time: datetime) -> float:
return 0.0025
def rebate_rate(self, symbol: Symbol, local_time: DateTime):
def rebate_rate(self, symbol: Symbol, local_time: datetime) -> float:
return 0.0507
def shortable_quantity(self, symbol: Symbol, local_time: DateTime):
def shortable_quantity(self, symbol: Symbol, local_time: datetime) -> int:
if local_time < datetime(2013,10,4,16,0,0):
return 10
else:
return 1001
return 1001