instruction
stringclasses
1 value
input
stringlengths
81
758
output
stringlengths
420
23.9k
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : Basic template algorithm simply initializes the date range and cash. This is a skeleton framework you can use for designing an algorithm.
```python from AlgorithmImports import * class BasicTemplateAlgorithm(QCAlgorithm): '''Basic template algorithm simply initializes the date range and cash''' def initialize(self): '''Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorith...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : This regression algorithm tests Out of The Money (OTM) future option expiry for short calls. We expect 2 orders from the algorithm, which are: * Initial entry, sell ES Call Option (expiring OTM) - Profit the option premium, since the option was not assi...
```python from AlgorithmImports import * class FutureOptionShortCallOTMExpiryRegressionAlgorithm(QCAlgorithm): def initialize(self): self.set_start_date(2020, 1, 5) self.set_end_date(2020, 6, 30) self.es19m20 = self.add_future_contract( Symbol.create_future( ...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : Regression algorithm to assert the behavior of <see cref="RsiAlphaModel"/>.
```python from AlgorithmImports import * from BaseFrameworkRegressionAlgorithm import BaseFrameworkRegressionAlgorithm from Alphas.RsiAlphaModel import RsiAlphaModel class RsiAlphaModelFrameworkRegressionAlgorithm(BaseFrameworkRegressionAlgorithm): def initialize(self): super().initialize() self...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : This algorithm showcases some features of the IObjectStore feature.
```python from AlgorithmImports import * from io import StringIO class ObjectStoreExampleAlgorithm(QCAlgorithm): '''This algorithm showcases some features of the IObjectStore feature. One use case is to make consecutive backtests run faster by caching the results of potentially time consuming operations....
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : Regression test for consistency of hour data over a reverse split event in US equities.
```python from AlgorithmImports import * class HourSplitRegressionAlgorithm(QCAlgorithm): def initialize(self): self.set_start_date(2014, 6, 6) self.set_end_date(2014, 6, 9) self.set_cash(100000) self.set_benchmark(lambda x: 0) self._symbol = self.add_equity("AAPL", Reso...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : Regression algorithm to test zeroed benchmark through BrokerageModel override
```python from AlgorithmImports import * class ZeroedBenchmarkRegressionAlgorithm(QCAlgorithm): def initialize(self): self.set_cash(100000) self.set_start_date(2013,10,7) self.set_end_date(2013,10,8) # Add Equity self.add_equity("SPY", Resolution.HOUR) # Use our...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : This algorithm sends a list of portfolio targets from algorithm's Portfolio to Collective2 API every time the ema indicators crosses between themselves.
```python from AlgorithmImports import * class Collective2PortfolioSignalExportDemonstrationAlgorithm(QCAlgorithm): def initialize(self): ''' Initialize the date and add all equity symbols present in list _symbols ''' self.set_start_date(2013, 10, 7) #Set Start Date self.set_end_date(...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : Regression algorithm reproducing data type bugs in the Consolidate API. Related to GH 4205.
```python from AlgorithmImports import * from CustomDataRegressionAlgorithm import Bitcoin class ConsolidateRegressionAlgorithm(QCAlgorithm): # Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized. def initialize(self): ...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : Demostrates the use of <see cref="VolumeRenkoConsolidator"/> for creating constant volume bar
```python from AlgorithmImports import * class VolumeRenkoConsolidatorAlgorithm(QCAlgorithm): def initialize(self): self.set_start_date(2013, 10, 7) self.set_end_date(2013, 10, 11) self.set_cash(100000) self._sma = SimpleMovingAverage(10) self._tick_consolidated = False ...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : This regression algorithm tests option exercise and assignment functionality We open two positions and go with them into expiration. We expect to see our long position exercised and short position assigned.
```python from AlgorithmImports import * class OptionSplitRegressionAlgorithm(QCAlgorithm): def initialize(self): # this test opens position in the first day of trading, lives through stock split (7 for 1), # and closes adjusted position on the second day self.set_cash(1000000) ...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : Demonstration of how to define a universe using the fundamental data
```python from AlgorithmImports import * class FundamentalRegressionAlgorithm(QCAlgorithm): def initialize(self): self.set_start_date(2014, 3, 26) self.set_end_date(2014, 4, 7) self.universe_settings.resolution = Resolution.DAILY self._universe = self.add_universe(self.selectio...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : This regression algorithm tests that we receive the expected data when we add future option contracts individually using <see cref="AddFutureOptionContract"/>
```python from AlgorithmImports import * class AddFutureOptionContractDataStreamingRegressionAlgorithm(QCAlgorithm): def initialize(self): self.on_data_reached = False self.invested = False self.symbols_received = [] self.expected_symbols_received = [] self.data_received =...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : Test algorithm generating insights with custom tags
```python from AlgorithmImports import * from Selection.ManualUniverseSelectionModel import ManualUniverseSelectionModel from Portfolio.EqualWeightingPortfolioConstructionModel import EqualWeightingPortfolioConstructionModel from Execution.ImmediateExecutionModel import ImmediateExecutionModel class InsightTagAlpha...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : In this algorithm we demonstrate how to perform some technical analysis as part of your coarse fundamental universe selection
```python from AlgorithmImports import * class EmaCrossUniverseSelectionAlgorithm(QCAlgorithm): def initialize(self): '''Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.''' self.set_start_date(2010,1,1) #S...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : This example algorithm defines its own custom coarse/fine fundamental selection model with equally weighted portfolio and a maximum sector exposure.
```python from AlgorithmImports import * from Portfolio.EqualWeightingPortfolioConstructionModel import EqualWeightingPortfolioConstructionModel from Alphas.ConstantAlphaModel import ConstantAlphaModel from Execution.ImmediateExecutionModel import ImmediateExecutionModel from Risk.MaximumSectorExposureRiskManagementM...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : Tests the mapping of the ETF symbol that has a constituent universe attached to it and ensures that data is loaded after the mapping event takes place.
```python from AlgorithmImports import * class ETFConstituentUniverseFilterFunctionRegressionAlgorithm(QCAlgorithm): def initialize(self): self.set_start_date(2011, 2, 1) self.set_end_date(2011, 4, 4) self.set_cash(100000) self.filter_date_constituent_symbol_count = {} se...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : Regression algorithm to assert the behavior of <see cref="MaximumUnrealizedProfitPercentPerSecurity"/>.
```python from AlgorithmImports import * from BaseFrameworkRegressionAlgorithm import BaseFrameworkRegressionAlgorithm from Risk.MaximumUnrealizedProfitPercentPerSecurity import MaximumUnrealizedProfitPercentPerSecurity class MaximumUnrealizedProfitPercentPerSecurityFrameworkRegressionAlgorithm(BaseFrameworkRegressi...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : This regression algorithm tests In The Money (ITM) index option expiry for short calls. We expect 2 orders from the algorithm, which are: * Initial entry, sell SPX Call Option (expiring ITM) * Option assignment Additionally, we test delistings for index ...
```python from AlgorithmImports import * class IndexOptionShortCallITMExpiryRegressionAlgorithm(QCAlgorithm): def initialize(self): self.set_start_date(2021, 1, 4) self.set_end_date(2021, 1, 31) self.set_cash(1000000) self.portfolio.set_margin_call_model(MarginCallModel.NULL); ...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : This regression algorithm tests Out of The Money (OTM) index option expiry for short calls. We expect 2 orders from the algorithm, which are: * Initial entry, sell SPX Call Option (expiring OTM) - Profit the option premium, since the option was not assi...
```python from AlgorithmImports import * class IndexOptionShortCallOTMExpiryRegressionAlgorithm(QCAlgorithm): def initialize(self): self.set_start_date(2021, 1, 4) self.set_end_date(2021, 1, 31) self.spx = self.add_index("SPX", Resolution.MINUTE).symbol # Select a index option ...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : def initialize(self) -> None:
```python from AlgorithmImports import * class BasicTemplateIndexOptionsAlgorithm(QCAlgorithm): def initialize(self) -> None: self.set_start_date(2021, 1, 4) self.set_end_date(2021, 2, 1) self.set_cash(1000000) self.spx = self.add_index("SPX", Resolution.MINUTE).symbol sp...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : Regression algorithm showing how to define a custom insight scoring function and using the insight manager
```python from AlgorithmImports import * class InsightScoringRegressionAlgorithm(QCAlgorithm): '''Regression algorithm showing how to define a custom insight evaluator''' def initialize(self): ''' Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : The algorithm creates new indicator value with the existing indicator method by Indicator Extensions Demonstration of using the external custom data to request the IBM and SPY daily data
```python from AlgorithmImports import * from HistoryAlgorithm import * class CustomDataIndicatorExtensionsAlgorithm(QCAlgorithm): # Initialize the data and resolution you require for your strategy def initialize(self): self.set_start_date(2014,1,1) self.set_end_date(2018,1,1) self....
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : Demonstrate the usage of the BrokerageModel property to help improve backtesting accuracy through simulation of a specific brokerage's rules around restrictions on submitting orders as well as fee structure.
```python from AlgorithmImports import * class BrokerageModelAlgorithm(QCAlgorithm): def initialize(self): self.set_cash(100000) # Set Strategy Cash self.set_start_date(2013,10,7) # Set Start Date self.set_end_date(2013,10,11) # Set End Date self.add_equity("SPY...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : Regression test to check python indicator is keeping backwards compatibility with indicators that do not set WarmUpPeriod or do not inherit from PythonIndicator class.
```python from AlgorithmImports import * from collections import deque class CustomWarmUpPeriodIndicatorAlgorithm(QCAlgorithm): def initialize(self) -> None: self.set_start_date(2013, 10, 7) self.set_end_date(2013, 10, 11) self.add_equity("SPY", Resolution.SECOND) # Create three ...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : Demonstration of using an external custom datasource. LEAN Engine is incredibly flexible and allows you to define your own data source. This includes any data source which has a TIME and VALUE. These are the *only* requirements. To demonstrate this we're loadi...
```python from AlgorithmImports import * import pytz class CustomDataBitcoinAlgorithm(QCAlgorithm): def initialize(self): self.set_start_date(2011, 9, 13) self.set_end_date(datetime.now().date() - timedelta(1)) self.set_cash(100000) # Define the symbol and "type" of our generic ...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : This algorithm shows how to set a custom security initializer. A security initializer is run immediately after a new security object has been created and can be used to security models and other settings, such as data normalization mode
```python from AlgorithmImports import * class CustomSecurityInitializerAlgorithm(QCAlgorithm): def initialize(self): # set our initializer to our custom type self.set_brokerage_model(BrokerageName.INTERACTIVE_BROKERS_BROKERAGE) func_security_seeder = FuncSecuritySeeder...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : Demonstration algorithm of time in force order settings.
```python from AlgorithmImports import * class TimeInForceAlgorithm(QCAlgorithm): # Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized. def initialize(self): self.set_start_date(2013,10,7) self.set_end_dat...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : Black-Litterman framework algorithm Uses the HistoricalReturnsAlphaModel and the BlackLittermanPortfolioConstructionModel to create an algorithm that rebalances the portfolio according to Black-Litterman portfolio optimization
```python from AlgorithmImports import * from Alphas.HistoricalReturnsAlphaModel import HistoricalReturnsAlphaModel from Portfolio.BlackLittermanOptimizationPortfolioConstructionModel import * from Portfolio.UnconstrainedMeanVariancePortfolioOptimizer import UnconstrainedMeanVariancePortfolioOptimizer from Risk.Null...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : Algorithm demonstrating the usage of custom brokerage message handler and the new brokerage-side order handling/filtering. This test is supposed to be ran by the CustomBrokerageMessageHandlerTests unit test fixture. All orders are sent from the brokerage, non...
```python from AlgorithmImports import * class CustomBrokerageSideOrderHandlingRegressionAlgorithm(QCAlgorithm): '''Algorithm demonstrating the usage of custom brokerage message handler and the new brokerage-side order handling/filtering. This test is supposed to be ran by the CustomBrokerageMessageHandlerT...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : Demonstration of how to chain a coarse and fine universe selection with an option chain universe selection model that will add and remove an'OptionChainUniverse' for each symbol selected on fine
```python from AlgorithmImports import * class CoarseFineOptionUniverseChainRegressionAlgorithm(QCAlgorithm): 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.''' self.set_st...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : Expiry Helper algorithm uses Expiry helper class in an Alpha Model
```python from AlgorithmImports import * class ExpiryHelperAlphaModelFrameworkAlgorithm(QCAlgorithm): '''Expiry Helper framework algorithm uses Expiry helper class in an Alpha Model''' def initialize(self) -> None: ''' Initialise the data and resolution required, as well as the cash and start-end da...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : Regression algorithm that validates that when using a continuous future (without a filter) the option chains are correctly populated using the mapped symbol.
```python from AlgorithmImports import * class FutureOptionContinuousFutureRegressionAlgorithm(QCAlgorithm): def initialize(self): self.set_start_date(2020, 1, 4) self.set_end_date(2020, 1, 8) self.future = self.add_future(Futures.Indices.SP_500_E_MINI, Resolution.MINUTE, Market....
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : Custom data universe selection regression algorithm asserting it's behavior. See GH issue #6396
```python from AlgorithmImports import * class CustomDataUniverseRegressionAlgorithm(QCAlgorithm): def initialize(self): '''Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.''' self.set_start_date(2014, 3, 24)...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : Basic template framework algorithm uses framework components to define the algorithm. Liquid ETF Competition template
```python from AlgorithmImports import * from Portfolio.EqualWeightingPortfolioConstructionModel import EqualWeightingPortfolioConstructionModel from Execution.ImmediateExecutionModel import ImmediateExecutionModel class LiquidETFUniverseFrameworkAlgorithm(QCAlgorithm): '''Basic template framework algorithm use...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : Show cases how to use the CompositeRiskManagementModel.
```python from AlgorithmImports import * class CompositeRiskManagementModelFrameworkAlgorithm(QCAlgorithm): '''Show cases how to use the CompositeRiskManagementModel.''' def initialize(self): # Set requested data resolution self.universe_settings.resolution = Resolution.MINUTE self...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : Framework algorithm that uses the G10CurrencySelectionModel, a Universe Selection Model that inherits from ManualUniverseSelectionModel
```python from AlgorithmImports import * from Selection.ManualUniverseSelectionModel import ManualUniverseSelectionModel class G10CurrencySelectionModel(ManualUniverseSelectionModel): '''Provides an implementation of IUniverseSelectionModel that simply subscribes to G10 currencies''' def __init__(self): ...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : Example algorithm of using MeanReversionPortfolioConstructionModel
```python from AlgorithmImports import * from Portfolio.MeanReversionPortfolioConstructionModel import * class MeanReversionPortfolioAlgorithm(QCAlgorithm): '''Example algorithm of using MeanReversionPortfolioConstructionModel''' def initialize(self): # Set starting date, cash and ending date of the...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : This regression algorithm tests In The Money (ITM) future option calls across different strike prices. We expect 6 orders from the algorithm, which are: * (1) Initial entry, buy ES Call Option (ES19M20 expiring ITM) * (2) Initial entry, sell ES Call Optio...
```python from AlgorithmImports import * class FutureOptionBuySellCallIntradayRegressionAlgorithm(QCAlgorithm): def initialize(self): self.set_start_date(2020, 1, 5) self.set_end_date(2020, 6, 30) self.es20h20 = self.add_future_contract( Symbol.create_future( ...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : Strategy example using a portfolio of ETF Global Rotation
```python from AlgorithmImports import * class ETFGlobalRotationAlgorithm(QCAlgorithm): def initialize(self): self.set_cash(25000) self.set_start_date(2007,1,1) self.last_rotation_time = datetime.min self.rotation_interval = timedelta(days=30) self.first = True ...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : Regression algorithm illustrating the usage of the <see cref="QCAlgorithm.FuturesChain(Symbol, bool)"/> method to get a future chain.
```python from AlgorithmImports import * class FuturesChainFullDataRegressionAlgorithm(QCAlgorithm): def initialize(self): self.set_start_date(2013, 10, 7) self.set_end_date(2013, 10, 7) future = self.add_future(Futures.Indices.SP_500_E_MINI, Resolution.MINUTE).symbol chain = s...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : Regression algorithm to test we can specify a custom brokerage model, and override some of its methods
```python from AlgorithmImports import * class CustomBrokerageModelRegressionAlgorithm(QCAlgorithm): def initialize(self): self.set_start_date(2013,10,7) self.set_end_date(2013,10,11) self.set_brokerage_model(CustomBrokerageModel()) self.add_equity("SPY", Resolution.DAILY) ...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : This regression algorithm tests In The Money (ITM) index option calls across different strike prices. We expect 4* orders from the algorithm, which are: * (1) Initial entry, buy SPX Call Option (SPXF21 expiring ITM) * (2) Initial entry, sell SPX Call Opti...
```python from AlgorithmImports import * class IndexOptionBuySellCallIntradayRegressionAlgorithm(QCAlgorithm): def initialize(self): self.set_start_date(2021, 1, 4) self.set_end_date(2021, 1, 31) spx = self.add_index("SPX", Resolution.MINUTE).symbol # Select a index option expi...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : Regression algorithm demonstrating use of map files with custom data
```python from AlgorithmImports import * class CustomDataUsingMapFileRegressionAlgorithm(QCAlgorithm): def initialize(self): # Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized. self.set_start_date(2013, 6, 27...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : A demonstration algorithm to check there can be placed an order of a pair not present in the brokerage using the conversion between stablecoins
```python from AlgorithmImports import * class StableCoinsRegressionAlgorithm(QCAlgorithm): def initialize(self): self.set_start_date(2018, 5, 1) self.set_end_date(2018, 5, 2) self.set_cash("USDT", 200000000) self.set_brokerage_model(BrokerageName.BINANCE, AccountType.CASH) ...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : Adds a universe with a custom data type and retrieves historical data while preserving the custom data type.
```python from datetime import timedelta from AlgorithmImports import * class PersistentCustomDataUniverseRegressionAlgorithm(QCAlgorithm): def Initialize(self): self.set_start_date(2018, 6, 1) self.set_end_date(2018, 6, 19) universe = self.add_universe(StockDataSource, "my-stock-data-s...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : Algorithm asserting that when setting custom models for canonical securities, a one-time warning is sent informing the user that the contracts models are different (not the custom ones).
```python from AlgorithmImports import * class OptionModelsConsistencyRegressionAlgorithm(QCAlgorithm): def initialize(self) -> None: security = self.initialize_algorithm() self.set_models(security) # Using a custom security initializer derived from BrokerageModelSecurityInitializer ...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : Basic algorithm demonstrating how to place LimitIfTouched orders.
```python from AlgorithmImports import * from collections import deque class LimitIfTouchedRegressionAlgorithm(QCAlgorithm): asynchronous_orders = False def initialize(self): self.set_start_date(2013, 10, 7) self.set_end_date(2013, 10, 11) self.set_cash(100000) self.add_equi...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : This regression algorithm is expected to fail and verifies that a training event created in Initialize will get run AND it will cause the algorithm to fail if it exceeds the "algorithm-manager-time-loop-maximum" config value, which the regression test sets to ...
```python from AlgorithmImports import * from time import sleep class TrainingInitializeRegressionAlgorithm(QCAlgorithm): '''Example algorithm showing how to use QCAlgorithm.train method''' def initialize(self): self.set_start_date(2013, 10, 7) self.set_end_date(2013, 10, 11) self....
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : This example demonstrates how to add and trade SPX index weekly options
```python from AlgorithmImports import * class BasicTemplateSPXWeeklyIndexOptionsAlgorithm(QCAlgorithm): def initialize(self): self.set_start_date(2021, 1, 4) self.set_end_date(2021, 1, 10) self.set_cash(1000000) # regular option SPX contracts self.spx_options = self.add_...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : This example demonstrates how to add options for a given underlying equity security. It also shows how you can prefilter contracts easily based on strikes and expirations, and how you can inspect the option chain to pick a specific option contract to trade.
```python from AlgorithmImports import * class BasicTemplateOptionsDailyAlgorithm(QCAlgorithm): underlying_ticker = "AAPL" def initialize(self): self.set_start_date(2015, 12, 15) self.set_end_date(2016, 2, 1) self.set_cash(100000) self.option_expired = False equity =...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : This regression algorithm tests Out of The Money (OTM) index option expiry for short calls. We expect 2 orders from the algorithm, which are: * Initial entry, sell SPX Call Option (expiring OTM) - Profit the option premium, since the option was not assi...
```python from AlgorithmImports import * class IndexOptionShortCallOTMExpiryRegressionAlgorithm(QCAlgorithm): def initialize(self): self.set_start_date(2021, 1, 4) self.set_end_date(2021, 1, 31) self.spx = self.add_index("SPX", Resolution.MINUTE).symbol # Select a index option ...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : def initialize(self) -> None:
```python from AlgorithmImports import * class BasicTemplateIndexAlgorithm(QCAlgorithm): def initialize(self) -> None: self.set_start_date(2021, 1, 4) self.set_end_date(2021, 1, 18) self.set_cash(1000000) # Use indicator for signal; but it cannot be traded self.spx = self...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : This regression algorithm tests In The Money (ITM) index option expiry for calls. We expect 2 orders from the algorithm, which are: * Initial entry, buy SPX Call Option (expiring ITM) * Option exercise, settles into cash Additionally, we test delistings ...
```python from AlgorithmImports import * class IndexOptionCallITMExpiryRegressionAlgorithm(QCAlgorithm): def initialize(self): self.set_start_date(2021, 1, 4) self.set_end_date(2021, 1, 31) self.set_cash(100000) self.spx = self.add_index("SPX", Resolution.MINUTE).symbol ...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : Basic algorithm using SetAccountCurrency
```python from AlgorithmImports import * class BasicSetAccountCurrencyAlgorithm(QCAlgorithm): def initialize(self): '''Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.''' self.set_start_date(2018, 4, 4) #Se...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : Custom data universe selection regression algorithm asserting it's behavior. See GH issue #6396
```python from AlgorithmImports import * class NoUniverseSelectorRegressionAlgorithm(QCAlgorithm): def initialize(self): '''Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.''' self.set_start_date(2014, 3, 24)...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : Regression algorithm asserting we can specify a custom portfolio optimizer with a MeanVarianceOptimizationPortfolioConstructionModel
```python from AlgorithmImports import * from MeanVarianceOptimizationFrameworkAlgorithm import MeanVarianceOptimizationFrameworkAlgorithm class CustomPortfolioOptimizerRegressionAlgorithm(MeanVarianceOptimizationFrameworkAlgorithm): def initialize(self): super().initialize() self.set_portfolio_c...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : Basic algorithm demonstrating how to place stop limit orders.
```python from AlgorithmImports import * class StopLimitOrderRegressionAlgorithm(QCAlgorithm): '''Basic algorithm demonstrating how to place stop limit orders.''' tolerance = 0.001 fast_period = 30 slow_period = 60 asynchronous_orders = False def initialize(self): self.set_start_dat...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : Regression algorithm used to verify that get_data(type) correctly retrieves the latest custom data stored in the security cache.
```python from AlgorithmImports import * from CustomDataRegressionAlgorithm import Bitcoin class CustomDataSecurityCacheGetDataRegressionAlgorithm(QCAlgorithm): def initialize(self) -> None: self.set_start_date(2020,1,5) self.set_end_date(2020,1,10) self.add_data(Bitcoin, "BTC", Resolut...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : Regression algorithm illustrating the usage of the <see cref="QCAlgorithm.OptionChains(IEnumerable{Symbol})"/> method to get multiple future option chains.
```python from AlgorithmImports import * class FutureOptionChainsMultipleFullDataRegressionAlgorithm(QCAlgorithm): def initialize(self): self.set_start_date(2020, 1, 6) self.set_end_date(2020, 1, 6) es_future_contract = self.add_future_contract( Symbol.create_future(Futures....
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : This algorithm sends a list of portfolio targets to Collective2 API every time the ema indicators crosses between themselves.
```python from AlgorithmImports import * class Collective2SignalExportDemonstrationAlgorithm(QCAlgorithm): def initialize(self): ''' Initialize the date and add all equity symbols present in list _symbols ''' self.set_start_date(2013, 10, 7) #Set Start Date self.set_end_date(2013, 10,...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : Regression algorithm demonstrating how to get order events in custom execution models and asserting that they match the algorithm's order events.
```python from AlgorithmImports import * class ExecutionModelOrderEventsRegressionAlgorithm(QCAlgorithm): def initialize(self): self._order_events = [] self.universe_settings.resolution = Resolution.MINUTE self.set_start_date(2013, 10, 7) self.set_end_date(2013, 10, 11) s...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : Basic template algorithm simply initializes the date range and cash. This is a skeleton framework you can use for designing an algorithm.
```python from AlgorithmImports import * class IndicatorSuiteAlgorithm(QCAlgorithm): '''Demonstration algorithm of popular indicators and plotting them.''' def initialize(self): '''Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : This algorithm demonstrates the various ways to handle History pandas DataFrame
```python from AlgorithmImports import * class PandasDataFrameHistoryAlgorithm(QCAlgorithm): def initialize(self): self.set_start_date(2014, 6, 9) # Set Start Date self.set_end_date(2014, 6, 9) # Set End Date self.spy = self.add_equity("SPY", Resolution.DAILY).symbol self....
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : Related to GH issue 4275, reproduces a failed string to symbol implicit conversion asserting the exception thrown contains the used ticker
```python from AlgorithmImports import * class StringToSymbolImplicitConversionRegressionAlgorithm(QCAlgorithm): def initialize(self): '''Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.''' self.set_start_dat...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : Algorithm for testing submit/update/cancel for combo orders
```python import itertools from AlgorithmImports import * class ComboOrderTicketDemoAlgorithm(QCAlgorithm): def initialize(self) -> None: self.set_start_date(2015, 12, 24) self.set_end_date(2015, 12, 24) self.set_cash(100000) equity = self.add_equity("GOOG", leverage=4, fill_for...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : Regression algorithm to test the OptionChainedUniverseSelectionModel class
```python from AlgorithmImports import * class OptionChainedUniverseSelectionModelRegressionAlgorithm(QCAlgorithm): def initialize(self): self.universe_settings.resolution = Resolution.MINUTE self.set_start_date(2014, 6, 6) self.set_end_date(2014, 6, 6) self.set_cash(100000) ...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : Uses daily data and a simple moving average cross to place trades and an ema for stop placement
```python from AlgorithmImports import * class DailyAlgorithm(QCAlgorithm): def initialize(self): '''Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.''' self.set_start_date(2013,1,1) #Set Start Date ...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : This example demonstrates how to add options for a given underlying equity security. It also shows how you can prefilter contracts easily based on strikes and expirations, and how you can inspect the option chain to pick a specific option contract to trade.
```python from AlgorithmImports import * class BasicTemplateOptionsHourlyAlgorithm(QCAlgorithm): underlying_ticker = "AAPL" def initialize(self): self.set_start_date(2014, 6, 6) self.set_end_date(2014, 6, 9) self.set_cash(100000) equity = self.add_equity(self.underlying_tick...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : Provides an example algorithm showcasing the Security.data features
```python from AlgorithmImports import * from QuantConnect.Data.Custom.IconicTypes import * class DynamicSecurityDataRegressionAlgorithm(QCAlgorithm): def initialize(self): self.set_start_date(2015, 10, 22) self.set_end_date(2015, 10, 30) ticker = "GOOGL" self._equity = self.add...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : This regression algorithm asserts that futures have data at extended market hours when this is enabled.
```python from AlgorithmImports import * class FuturesExtendedMarketHoursRegressionAlgorithm(QCAlgorithm): def initialize(self): self.set_start_date(2013, 10, 6) self.set_end_date(2013, 10, 11) self._es = self.add_future(Futures.Indices.SP_500_E_MINI, Resolution.HOUR, fill_forward=True,...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : This regression algorithm tests Out of The Money (OTM) future option expiry for puts. We expect 2 orders from the algorithm, which are: * Initial entry, buy ES Put Option (expiring OTM) - contract expires worthless, not exercised, so never opened a posi...
```python from AlgorithmImports import * class FutureOptionPutOTMExpiryRegressionAlgorithm(QCAlgorithm): def initialize(self): self.set_start_date(2020, 1, 5) self.set_end_date(2020, 6, 30) self.es19m20 = self.add_future_contract( Symbol.create_future( Future...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : Basic template framework algorithm uses framework components to define the algorithm.
```python from AlgorithmImports import * class BasicTemplateIndiaAlgorithm(QCAlgorithm): '''Basic template framework algorithm uses framework components to define the algorithm.''' def initialize(self): '''initialise the data and resolution required, as well as the cash and start-end dates for your ...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : Demonstration of using the ETFConstituentsUniverseSelectionModel
```python from AlgorithmImports import * from Selection.ETFConstituentsUniverseSelectionModel import * class ETFConstituentsFrameworkAlgorithm(QCAlgorithm): def initialize(self): self.set_start_date(2020, 12, 1) self.set_end_date(2020, 12, 7) self.set_cash(100000) self.universe_...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : Regression test for consistency of hour data over a reverse split event in US equities.
```python from AlgorithmImports import * class HourReverseSplitRegressionAlgorithm(QCAlgorithm): def initialize(self): self.set_start_date(2013, 11, 7) self.set_end_date(2013, 11, 8) self.set_cash(100000) self.set_benchmark(lambda x: 0) self._symbol = self.add_equity("VX...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : This algorithm shows some of the various helper methods available when defining universes
```python from AlgorithmImports import * class UniverseSelectionDefinitionsAlgorithm(QCAlgorithm): def initialize(self): # subscriptions added via universe selection will have this resolution self.universe_settings.resolution = Resolution.DAILY self.set_start_date(2014,3,24) # Set St...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : In this algorithm, we fetch a list of tickers with corresponding dates from a file on Dropbox. We then create a fine fundamental universe which contains those symbols on their respective dates.###
```python from AlgorithmImports import * class DropboxCoarseFineAlgorithm(QCAlgorithm): def initialize(self): self.set_start_date(2019, 9, 23) # Set Start Date self.set_end_date(2019, 9, 30) # Set End Date self.set_cash(100000) # Set Strategy Cash self.add_universe(self.select_c...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : Algorithm demonstrating and ensuring that Bybit crypto futures brokerage model works as expected
```python from cmath import isclose from AlgorithmImports import * class BybitCryptoFuturesRegressionAlgorithm(QCAlgorithm): def initialize(self): '''Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.''' self...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : Test algorithm using a 'ConstituentsUniverse' with test data
```python from AlgorithmImports import * class ConstituentsUniverseRegressionAlgorithm(QCAlgorithm): def initialize(self): self.set_start_date(2013, 10, 7) #Set Start Date self.set_end_date(2013, 10, 11) #Set End Date self.set_cash(100000) #Set Strategy Cash self...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : Regression test to demonstrate setting custom Symbol Properties and Market Hours for a custom data import
```python import json from AlgorithmImports import * class CustomDataPropertiesRegressionAlgorithm(QCAlgorithm): def initialize(self) -> None: self.set_start_date(2020, 1, 5) # Set Start Date self.set_end_date(2020, 1, 10) # Set End Date self.set_cash(100000) # Set Strat...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : Regression algorithm asserting that the option chain APIs return consistent values. See QCAlgorithm.OptionChain(Symbol) and QCAlgorithm.OptionChainProvider
```python from datetime import datetime from AlgorithmImports import * class OptionChainApisConsistencyRegressionAlgorithm(QCAlgorithm): def initialize(self) -> None: test_date = self.get_test_date() self.set_start_date(test_date) self.set_end_date(test_date) option = self.get_...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : Shows how setting to use the SecurityMarginModel.null (or BuyingPowerModel.NULL) to disable the sufficient margin call verification. See also: <see cref="OptionEquityBullCallSpreadRegressionAlgorithm"/>
```python from AlgorithmImports import * class NullBuyingPowerOptionBullCallSpreadAlgorithm(QCAlgorithm): def initialize(self): self.set_start_date(2015, 12, 24) self.set_end_date(2015, 12, 24) self.set_cash(200000) self.set_security_initializer(lambda security: security.set_mar...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : This regression algorithm tests In The Money (ITM) index option expiry for puts. We expect 2 orders from the algorithm, which are: * Initial entry, buy ES Put Option (expiring ITM) (buy, qty 1) * Option exercise, receiving cash (sell, qty -1) Additionall...
```python from AlgorithmImports import * class IndexOptionPutITMExpiryRegressionAlgorithm(QCAlgorithm): def initialize(self): self.set_start_date(2021, 1, 4) self.set_end_date(2021, 1, 31) self.spx = self.add_index("SPX", Resolution.MINUTE).symbol # Select a index option expiri...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : This regression algorithm tests In The Money (ITM) future option expiry for short puts. We expect 3 orders from the algorithm, which are: * Initial entry, sell ES Put Option (expiring ITM) * Option assignment, buy 1 contract of the underlying (ES) * Fut...
```python from AlgorithmImports import * class FutureOptionShortPutITMExpiryRegressionAlgorithm(QCAlgorithm): def initialize(self): self.set_start_date(2020, 1, 5) self.set_end_date(2020, 6, 30) self.es19m20 = self.add_future_contract( Symbol.create_future( F...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : Options Open Interest data regression test.
```python from AlgorithmImports import * class OptionOpenInterestRegressionAlgorithm(QCAlgorithm): def initialize(self): self.set_cash(1000000) self.set_start_date(2014,6,5) self.set_end_date(2014,6,6) option = self.add_option("TWX") # set our strike/expiry filter for t...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : We add an option contract using 'QCAlgorithm.add_option_contract' and place a trade, the underlying gets deselected from the universe selection but should still be present since we manually added the option contract. Later we call 'QCAlgorithm.remove_option_co...
```python from AlgorithmImports import * class AddOptionContractExpiresRegressionAlgorithm(QCAlgorithm): def initialize(self): '''Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.''' self.set_start_date(2014,...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : Regression algorithm demonstrating the use of custom data sourced from multiple "files" in the object store
```python from AlgorithmImports import * class CustomDataMultiFileObjectStoreRegressionAlgorithm(QCAlgorithm): custom_data = "2017-08-18 01:00:00,5749.5,5852.95,5749.5,5842.2,214402430,8753.33\n2017-08-18 02:00:00,5834.1,5904.35,5822.2,5898.85,144794030,5405.72\n2017-08-18 03:00:00,5885.5,5898.8,5852.3,5857.55,1...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : This algorithm sends a list of current portfolio targets to Numerai API before each trading day See (https://docs.numer.ai/numerai-signals/signals-overview) for more information about accepted symbols, signals, etc.
```python from AlgorithmImports import * class NumeraiSignalExportDemonstrationAlgorithm(QCAlgorithm): _securities = [] def initialize(self) -> None: ''' Initialize the date and add all equity symbols present in list _symbols ''' self.set_start_date(2020, 10, 7) #Set Start Date s...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : This example demonstrates how to add options for a given underlying equity security. It also shows how you can prefilter contracts easily based on strikes and expirations, and how you can inspect the option chain to pick a specific option contract to trade.
```python from AlgorithmImports import * class BasicTemplateOptionsAlgorithm(QCAlgorithm): underlying_ticker = "GOOG" def initialize(self): self.set_start_date(2015, 12, 24) self.set_end_date(2015, 12, 24) self.set_cash(100000) equity = self.add_equity(self.underlying_ticker...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : Regression algorithm asserting that historical data can be requested with tick resolution without requiring a tick resolution subscription
```python from datetime import timedelta from AlgorithmImports import * class TickHistoryRequestWithoutTickSubscriptionRegressionAlgorithm(QCAlgorithm): def initialize(self): self.set_start_date(2013, 10, 8) self.set_end_date(2013, 10, 8) # Subscribing SPY and IBM with daily and hour re...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : Basic algorithm demonstrating how to place trailing stop orders.
```python from AlgorithmImports import * class TrailingStopOrderRegressionAlgorithm(QCAlgorithm): '''Basic algorithm demonstrating how to place trailing stop orders.''' buy_trailing_amount = 2 sell_trailing_amount = 0.5 asynchronous_orders = False def initialize(self): self.set_start_d...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : Regression algorithm asserting the behavior of different callback commands call
```python from AlgorithmImports import * class InvalidCommand(): variable = 10 class VoidCommand(): quantity = 0 target = [] parameters = {} targettime = None def run(self, algo: IAlgorithm) -> bool: if not self.targettime or self.targettime != algo.time: return False ...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : Algorithm demonstrating custom charting support in QuantConnect. The entire charting system of quantconnect is adaptable. You can adjust it to draw whatever you'd like. Charts can be stacked, or overlayed on each other. Series can be candles, lines or scatter ...
```python from AlgorithmImports import * class CustomChartingAlgorithm(QCAlgorithm): def initialize(self): self.set_start_date(2016,1,1) self.set_end_date(2017,1,1) self.set_cash(100000) spy = self.add_equity("SPY", Resolution.DAILY).symbol # In your initialize method: ...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : def initialize(self):
```python from AlgorithmImports import * class CustomDataTypeHistoryAlgorithm(QCAlgorithm): def initialize(self): self.set_start_date(2017, 8, 20) self.set_end_date(2017, 8, 20) self._symbol = self.add_data(CustomDataType, "CustomDataType", Resolution.HOUR).symbol history = list...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : Basic template algorithm simply initializes the date range and cash
```python from AlgorithmImports import * class BasicTemplateFillForwardAlgorithm(QCAlgorithm): '''Basic template algorithm simply initializes the date range and cash''' def initialize(self): '''initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. A...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : We add an option contract using 'QCAlgorithm.add_option_contract' and place a trade, the underlying gets deselected from the universe selection but should still be present since we manually added the option contract. Later we call 'QCAlgorithm.remove_option_co...
```python from AlgorithmImports import * class AddOptionContractFromUniverseRegressionAlgorithm(QCAlgorithm): def initialize(self): '''Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.''' self.set_start_date(...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : Example algorithm of how to use RangeConsolidator
```python from AlgorithmImports import * class RangeConsolidatorAlgorithm(QCAlgorithm): def get_resolution(self) -> Resolution: return Resolution.DAILY def get_range(self) -> int: return 100 def initialize(self) -> None: self.set_start_and_end_dates() self.add_equity("SP...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : Alpha model for ETF constituents, where we generate insights based on the weighting of the ETF constituent
```python from AlgorithmImports import * constituent_data = [] class ETFConstituentAlphaModel(AlphaModel): def on_securities_changed(self, algorithm: QCAlgorithm, changes: SecurityChanges) -> None: pass ### <summary> ### Creates new insights based on constituent data and their weighting ###...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : This regression algorithm verifies automatic option contract assignment behavior.
```python from AlgorithmImports import * class OptionAssignmentRegressionAlgorithm(QCAlgorithm): def initialize(self): self.set_start_date(2015, 12, 23) self.set_end_date(2015, 12, 28) self.set_cash(100000) self.stock = self.add_equity("GOOG", Resolution.MINUTE) contract...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : Regression algorithm for fractional forex pair
```python from AlgorithmImports import * class FractionalQuantityRegressionAlgorithm(QCAlgorithm): def initialize(self): self.set_start_date(2015, 11, 12) self.set_end_date(2016, 4, 1) self.set_cash(100000) self.set_brokerage_model(BrokerageName.GDAX, AccountType.CASH) ...
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework.
Generate a LEAN Algorithm that can be described like this : CapmAlphaRankingFrameworkAlgorithm: example of custom scheduled universe selection model Universe Selection inspired by https://www.quantconnect.com/tutorials/strategy-library/capm-alpha-ranking-strategy-on-dow-30-companies
```python from AlgorithmImports import * class CapmAlphaRankingFrameworkAlgorithm(QCAlgorithm): '''CapmAlphaRankingFrameworkAlgorithm: example of custom scheduled universe selection model''' def initialize(self): ''' Initialise the data and resolution required, as well as the cash and start-end date...