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
: Regression algorithm for the VolumeWeightedAveragePriceExecutionModel.
This algorithm shows how the execution model works to split up orders and
submit them only when the price is on the favorable side of the intraday VWAP. | ```python
from AlgorithmImports import *
from Alphas.RsiAlphaModel import RsiAlphaModel
from Portfolio.EqualWeightingPortfolioConstructionModel import EqualWeightingPortfolioConstructionModel
from Execution.VolumeWeightedAveragePriceExecutionModel import VolumeWeightedAveragePriceExecutionModel
class VolumeWeightedA... |
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 coarse and fine universe selection together to filter down a smaller universe of stocks. | ```python
from AlgorithmImports import *
class CoarseFundamentalTop3Algorithm(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) #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
: Basic template framework algorithm uses framework components to define the algorithm.
Shows EqualWeightingPortfolioConstructionModel.long_only() application | ```python
from AlgorithmImports import *
from Portfolio.EqualWeightingPortfolioConstructionModel import EqualWeightingPortfolioConstructionModel
from Execution.ImmediateExecutionModel import ImmediateExecutionModel
from Selection.ManualUniverseSelectionModel import ManualUniverseSelectionModel
class LongOnlyAlphaSt... |
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 FOREX asset types and requesting history on them in bulk. As FOREX uses
QuoteBars you should request slices | ```python
from AlgorithmImports import *
class BasicTemplateForexAlgorithm(QCAlgorithm):
def initialize(self):
# Set the cash we'd like to use for our backtest
self.set_cash(100000)
# Start and end dates for the backtest.
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
: Basic template algorithm that implements a fill model with combo orders
<meta name="tag" content="trading and orders" /> | ```python
from AlgorithmImports import *
class ComboOrdersFillModelAlgorithm(QCAlgorithm):
'''Basic template algorithm that implements a fill model with combo orders'''
def initialize(self) -> None:
self.set_start_date(2019, 1, 1)
self.set_end_date(2019, 1, 20)
self.spy = self.add_e... |
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 futures for a given underlying asset.
It also shows how you can prefilter contracts easily based on expirations, and how you
can inspect the futures chain to pick a specific contract to trade. | ```python
from AlgorithmImports import *
class BasicTemplateFuturesWithExtendedMarketAlgorithm(QCAlgorithm):
def initialize(self):
self.set_start_date(2013, 10, 8)
self.set_end_date(2013, 10, 10)
self.set_cash(1000000)
self.contract_symbol = None
# Subscribe and set 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
: Demonstration of using custom fee, slippage, fill, and buying power models for modelling transactions in backtesting.
QuantConnect allows you to model all orders as deeply and accurately as you need. | ```python
from AlgorithmImports import *
import random
class CustomModelsAlgorithm(QCAlgorithm):
'''Demonstration of using custom fee, slippage, fill, and buying power models for modelling transactions in backtesting.
QuantConnect allows you to model all orders as deeply and accurately as you need.'''
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
: Algorithm asserting that security dynamic properties keep Python references to the Python class they are instances of,
specifically when this class is a subclass of a C# class. | ```python
from AlgorithmImports import *
from collections import deque
import numpy as np
class SecurityDynamicPropertyPythonClassAlgorithm(QCAlgorithm):
def initialize(self) -> None:
self.set_start_date(2013, 10, 7)
self.set_end_date(2013, 10, 7)
self._spy = self.add_equity("SPY", 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
: _valid_order_ticket = None | ```python
from AlgorithmImports import *
class MarketOnCloseOrderBufferRegressionAlgorithm(QCAlgorithm):
_valid_order_ticket = None
_invalid_order_ticket = None
def initialize(self) -> None:
self.set_start_date(2013,10,7) #Set Start Date
self.set_end_date(2013,10,8) #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 for testing that period-based history requests are not allowed with tick resolution | ```python
from AlgorithmImports import *
class PeriodBasedHistoryRequestNotAllowedWithTickResolutionRegressionAlgorithm(QCAlgorithm):
def initialize(self):
self.set_start_date(2013, 10, 8)
self.set_end_date(2013, 10, 9)
spy = self.add_equity("SPY", Resolution.TICK).symbol
# 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
: Test algorithm using 'AccumulativeInsightPortfolioConstructionModel.py' and 'ConstantAlphaModel'
generating a constant 'Insight' | ```python
from AlgorithmImports import *
class AccumulativeInsightPortfolioRegressionAlgorithm(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.'''
# Set requested data... |
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework. | Generate a LEAN AlphaModel that can be described like this
: Regression algorithm to test ImmediateExecutionModel places orders with the
correct quantity (taking into account the fee's) so that the fill quantity
is the expected one. | ```python
# region imports
from AlgorithmImports import *
from Execution.ImmediateExecutionModel import ImmediateExecutionModel
from QuantConnect.Orders import OrderEvent
# endregion
class ImmediateExecutionModelWorksWithBinanceFeeModel(QCAlgorithm):
def Initialize(self):
# *** initial configurations an... |
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 vBsase API | ```python
from AlgorithmImports import *
class VBaseSignalExportDemonstrationAlgorithm(QCAlgorithm):
def initialize(self):
''' Initialize the date'''
self.set_start_date(2013,10, 7)
self.set_end_date(2013,10,11)
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
: Basic template framework algorithm uses framework components to define the algorithm. | ```python
from AlgorithmImports import *
class IndiaDataRegressionAlgorithm(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
: This regression algorithm tests various overloads of the Consolidate method
using RenkoBar, VolumeRenkoBar, and RangeBar types,
as well as common bars like TradeBar and QuoteBar with a maxCount parameter.
It ensures each overload behaves as expected and that t... | ```python
from AlgorithmImports import *
class ConsolidateWithSizeAttributeRegressionAlgorithm(QCAlgorithm):
def initialize(self):
self.set_start_date(2013, 10, 7)
self.set_end_date(2013, 10, 7)
self.set_cash(100000)
self.add_equity("SPY", Resolution.MINUTE)
self.sma_indi... |
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 calls.
We expect 2 orders from the algorithm, which are:
* Initial entry, buy SPX Call Option (expiring OTM)
- contract expires worthless, not exercised, so never opened a po... | ```python
from AlgorithmImports import *
class IndexOptionCallOTMExpiryRegressionAlgorithm(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 call ... |
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 universe additions and removals with open positions | ```python
from AlgorithmImports import *
class WeeklyUniverseSelectionRegressionAlgorithm(QCAlgorithm):
def initialize(self) -> None:
self.set_cash(100000)
self.set_start_date(2013,10,1)
self.set_end_date(2013,10,31)
self.universe_settings.resolution = Resolution.HOUR
#... |
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 futures framework algorithm uses framework components
to define an algorithm that trades futures. | ```python
from AlgorithmImports import *
from Alphas.ConstantAlphaModel import ConstantAlphaModel
from Selection.FutureUniverseSelectionModel import FutureUniverseSelectionModel
class BasicTemplateFuturesFrameworkAlgorithm(QCAlgorithm):
def initialize(self):
self.universe_settings.resolution = 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
: Demonstration of using custom margin interest rate model in backtesting. | ```python
from AlgorithmImports import *
class CustomMarginInterestRateModelAlgorithm(QCAlgorithm):
def initialize(self):
self.set_start_date(2013, 10, 1)
self.set_end_date(2013, 10, 31)
security = self.add_equity("SPY", Resolution.HOUR)
self._spy = security.symbol
# set... |
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 asserts Stochastic indicator, registered with a different resolution consolidator,
is warmed up properly by calling QCAlgorithm.WarmUpIndicator | ```python
from datetime import timedelta
from AlgorithmImports import *
class StochasticIndicatorWarmsUpProperlyRegressionAlgorithm(QCAlgorithm):
def initialize(self):
self.set_start_date(2020, 1, 1) # monday = holiday..
self.set_end_date(2020, 2, 1)
self.set_cash(100000)
self.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
: Basic template algorithm that implements a fill model with partial fills
<meta name="tag" content="trading and orders" /> | ```python
from AlgorithmImports import *
class CustomPartialFillModelAlgorithm(QCAlgorithm):
'''Basic template algorithm that implements a fill model with partial fills'''
def initialize(self):
self.set_start_date(2019, 1, 1)
self.set_end_date(2019, 3, 1)
equity = self.add_equity("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 regression algorithm tests Out of The Money (OTM) future option expiry for short puts.
We expect 2 orders from the algorithm, which are:
* Initial entry, sell ES Put Option (expiring OTM)
- Profit the option premium, since the option was not assign... | ```python
from AlgorithmImports import *
class FutureOptionShortPutOTMExpiryRegressionAlgorithm(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
: # Keep new created instance of stop_market_order | ```python
from AlgorithmImports import *
# <summary>
# This example demonstrates how to create future 'stop_market_order' in extended Market Hours time
# </summary>
class FutureStopMarketOrderOnExtendedHoursRegressionAlgorithm(QCAlgorithm):
# Keep new created instance of stop_market_order
_stop_market_ticke... |
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 history and warm up using the data available in open source. | ```python
from AlgorithmImports import *
class IndicatorWarmupAlgorithm(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, 10, 8) #Set Sta... |
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 use the coarse fundamental data to define a universe as the top dollar volume and set the algorithm to use raw prices | ```python
from AlgorithmImports import *
class RawPricesCoarseUniverseAlgorithm(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.'''
# what resolution should the data *... |
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="MaximumDrawdownPercentPortfolio"/>. | ```python
from AlgorithmImports import *
from BaseFrameworkRegressionAlgorithm import BaseFrameworkRegressionAlgorithm
from Risk.CompositeRiskManagementModel import CompositeRiskManagementModel
from Risk.MaximumDrawdownPercentPortfolio import MaximumDrawdownPercentPortfolio
class MaximumDrawdownPercentPortfolioFrame... |
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 testing ScheduledUniverseSelectionModel scheduling functions. | ```python
from AlgorithmImports import *
class ScheduledUniverseSelectionModelRegressionAlgorithm(QCAlgorithm):
'''Regression algorithm for testing ScheduledUniverseSelectionModel scheduling functions.'''
def initialize(self):
self.universe_settings.resolution = Resolution.HOUR
# Order 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
: Demonstration of requesting daily resolution data for US Equities.
This is a simple regression test algorithm using a skeleton algorithm and requesting daily data. | ```python
from AlgorithmImports import *
class BasicTemplateDailyAlgorithm(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 alg... |
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 the Option Chain Provider -- a much faster mechanism for manually specifying the option contracts you'd like to recieve
data for and manually subscribing to them. | ```python
from AlgorithmImports import *
class OptionChainProviderAlgorithm(QCAlgorithm):
def initialize(self):
self.set_start_date(2015, 12, 24)
self.set_end_date(2015, 12, 24)
self.set_cash(100000)
# add the underlying asset
self.equity = self.add_equity("GOOG", Resolu... |
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 OptionExerciseAssignRegressionAlgorithm(QCAlgorithm):
underlying_ticker = "GOOG"
def initialize(self):
self.set_cash(100000)
self.set_start_date(2015,12,24)
self.set_end_date(2015,12,28)
self.equity = self.add_equity(self.under... |
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 the correct values for the deployment target and algorithm mode. | ```python
from AlgorithmImports import *
class AlgorithmModeAndDeploymentTargetAlgorithm(QCAlgorithm):
def initialize(self):
self.set_start_date(2013,10, 7)
self.set_end_date(2013,10,11)
self.set_cash(100000)
#translate commented code from c# to python
self.debug(f"Algori... |
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 options framework algorithm uses framework components
to define an algorithm that trades options. | ```python
from AlgorithmImports import *
from Alphas.ConstantAlphaModel import ConstantAlphaModel
from Selection.OptionUniverseSelectionModel import OptionUniverseSelectionModel
from Execution.ImmediateExecutionModel import ImmediateExecutionModel
from Risk.NullRiskManagementModel import NullRiskManagementModel
cl... |
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
: Live Trading Functionality Demonstration algorithm including SMS, Email and Web hook notifications. | ```python
from AlgorithmImports import *
class LiveTradingFeaturesAlgorithm(QCAlgorithm):
### Initialize the Algorithm and Prepare Required Data
def initialize(self):
self.set_start_date(2013, 10, 7)
self.set_end_date(2013, 10, 11)
self.set_cash(25000)
##Equity Data for US... |
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 a custom filter function when creating an ETF constituents universe for SPY | ```python
from AlgorithmImports import *
class ETFConstituentUniverseFilterFunctionRegressionAlgorithm(QCAlgorithm):
def initialize(self):
self.set_start_date(2020, 12, 1)
self.set_end_date(2021, 1, 31)
self.set_cash(100000)
self.filtered = False
self.securities_changed =... |
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 where WarmUpIndicator method is used to warm up indicators | ```python
from AlgorithmImports import *
class SmaCrossUniverseSelectionAlgorithm(QCAlgorithm):
'''Provides an example where WarmUpIndicator method is used to warm up indicators
after their security is added and before (Universe Selection scenario)'''
_count = 10
_tolerance = 0.01
_target_percen... |
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 security data filter | ```python
from AlgorithmImports import *
class CustomSecurityDataFilterRegressionAlgorithm(QCAlgorithm):
def initialize(self):
self.set_cash(2500000)
self.set_start_date(2013,10,7)
self.set_end_date(2013,10,7)
security = self.add_security(SecurityType.EQUITY, "SPY")
secur... |
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 demonstration imports indian NSE index "NIFTY" as a tradable security in addition to the USDINR currency pair. We move into the
NSE market when the economy is performing well. | ```python
from AlgorithmImports import *
class CustomDataNIFTYAlgorithm(QCAlgorithm):
def initialize(self):
self.set_start_date(2008, 1, 8)
self.set_end_date(2014, 7, 25)
self.set_cash(100000)
# Define the symbol and "type" of our generic data:
rupee = self.add_data(Doll... |
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 show casing ad asserting security to symbol implicit conversion | ```python
from AlgorithmImports import *
class SecurityToSymbolRegressionAlgorithm(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,10, 7)
... |
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework. | Generate a LEAN AlphaModel that can be described like this
: Alpha Streams: Benchmark Alpha: Pick stocks according to Joel Greenblatt's Magic Formula | ```python
from AlgorithmImports import *
from Selection.FundamentalUniverseSelectionModel import FundamentalUniverseSelectionModel
from math import ceil
from itertools import chain
class GreenblattMagicFormulaAlpha(QCAlgorithm):
''' Alpha Streams: Benchmark Alpha: Pick stocks according to Joel Greenblatt's Magi... |
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework. | Generate a LEAN AlphaModel that can be described like this
: The motivating idea for this Alpha Model is that a large price gap (here we use true outliers -- | ```python
from AlgorithmImports import *
class PriceGapMeanReversionAlpha(QCAlgorithm):
'''The motivating idea for this Alpha Model is that a large price gap (here we use true outliers --
price gaps that whose absolutely values are greater than 3 * Volatility) is due to rebound
back to an appropriate pri... |
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework. | Generate a LEAN AlphaModel that can be described like this
: Alpha Benchmark Strategy capitalizing on ETF rebalancing causing momentum during trending markets. | ```python
from AlgorithmImports import *
class RebalancingLeveragedETFAlpha(QCAlgorithm):
''' Alpha Streams: Benchmark Alpha: Leveraged ETF Rebalancing
Strategy by Prof. Shum, reposted by Ernie Chan.
Source: http://epchan.blogspot.com/2012/10/a-leveraged-etfs-strategy.html'''
def initialize(... |
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework. | Generate a LEAN AlphaModel that can be described like this
: Contingent Claim Analysis is put forth by Robert Merton, recepient of the Noble Prize in Economics in 1997 for his work in contributing to | ```python
from AlgorithmImports import *
import scipy.stats as sp
from Risk.NullRiskManagementModel import NullRiskManagementModel
from Portfolio.EqualWeightingPortfolioConstructionModel import EqualWeightingPortfolioConstructionModel
from Execution.ImmediateExecutionModel import ImmediateExecutionModel
class Conti... |
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework. | Generate a LEAN AlphaModel that can be described like this
: Alpha Streams: Benchmark Alpha: Identify "pumped" penny stocks and predict that the price of a "pumped" penny stock reverts to mean | ```python
from AlgorithmImports import *
from Selection.FundamentalUniverseSelectionModel import FundamentalUniverseSelectionModel
class SykesShortMicroCapAlpha(QCAlgorithm):
''' Alpha Streams: Benchmark Alpha: Identify "pumped" penny stocks and predict that the price of a "pumped" penny stock reverts to mean
... |
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework. | Generate a LEAN ExecutionModel that can be described like this
: Execution model that submits orders while the current market prices is at least the configured number of standard | ```python
from AlgorithmImports import *
class StandardDeviationExecutionModel(ExecutionModel):
'''Execution model that submits orders while the current market prices is at least the configured number of standard
deviations away from the mean in the favorable direction (below/above for buy/sell respectively... |
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework. | Generate a LEAN ExecutionModel that can be described like this
: Execution model that submits orders while the current market price is more favorable that the current volume weighted average price. | ```python
from AlgorithmImports import *
class VolumeWeightedAveragePriceExecutionModel(ExecutionModel):
'''Execution model that submits orders while the current market price is more favorable that the current volume weighted average price.'''
def __init__(self, asynchronous=True):
'''Initializes a ... |
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework. | Generate a LEAN ExecutionModel that can be described like this
: Execution model that submits orders while the current spread is tight. | ```python
from AlgorithmImports import *
class SpreadExecutionModel(ExecutionModel):
'''Execution model that submits orders while the current spread is tight.
Note this execution model will not work using Resolution.DAILY since Exchange.exchange_open will be false, suggested resolution is Minute
'''
... |
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework. | Generate a LEAN AlphaModel that can be described like this
: This alpha model is designed to accept every possible pair combination | ```python
from AlgorithmImports import *
from enum import Enum
class BasePairsTradingAlphaModel(AlphaModel):
'''This alpha model is designed to accept every possible pair combination
from securities selected by the universe selection model
This model generates alternating long ratio/short ratio insights ... |
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework. | Generate a LEAN AlphaModel that can be described like this
: Defines a custom alpha model that uses MACD crossovers. The MACD signal line | ```python
from AlgorithmImports import *
class MacdAlphaModel(AlphaModel):
'''Defines a custom alpha model that uses MACD crossovers. The MACD signal line
is used to generate up/down insights if it's stronger than the bounce threshold.
If the MACD signal is within the bounce threshold then a flat price i... |
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework. | Generate a LEAN AlphaModel that can be described like this
: Uses Wilder's RSI to create insights. | ```python
from AlgorithmImports import *
from QuantConnect.Logging import *
from enum import Enum
class RsiAlphaModel(AlphaModel):
'''Uses Wilder's RSI to create insights.
Using default settings, a cross over below 30 or above 70 will trigger a new insight.'''
def __init__(self,
period ... |
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework. | Generate a LEAN AlphaModel that can be described like this
: This alpha model is designed to rank every pair combination by its pearson correlation | ```python
from AlgorithmImports import *
from Alphas.BasePairsTradingAlphaModel import BasePairsTradingAlphaModel
from scipy.stats import pearsonr
class PearsonCorrelationPairsTradingAlphaModel(BasePairsTradingAlphaModel):
''' This alpha model is designed to rank every pair combination by its pearson correlation... |
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework. | Generate a LEAN AlphaModel that can be described like this
: Uses Historical returns to create insights. | ```python
from AlgorithmImports import *
class HistoricalReturnsAlphaModel(AlphaModel):
'''Uses Historical returns to create insights.'''
def __init__(self, *args, **kwargs):
'''Initializes a new default instance of the HistoricalReturnsAlphaModel class.
Args:
lookback(int): Hist... |
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework. | Generate a LEAN AlphaModel that can be described like this
: Alpha model that uses an EMA cross to create insights | ```python
from AlgorithmImports import *
class EmaCrossAlphaModel(AlphaModel):
'''Alpha model that uses an EMA cross to create insights'''
def __init__(self,
fast_period = 12,
slow_period = 26,
resolution = Resolution.DAILY):
'''Initializes a new in... |
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework. | Generate a LEAN AlphaModel that can be described like this
: Provides an implementation of IAlphaModel that always returns the same insight for each security | ```python
from AlgorithmImports import *
class ConstantAlphaModel(AlphaModel):
''' Provides an implementation of IAlphaModel that always returns the same insight for each security'''
def __init__(self, type, direction, period, magnitude = None, confidence = None, weight = None):
'''Initializes a new... |
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework. | Generate a LEAN RiskManagementModel that can be described like this
: Provides an implementation of IRiskManagementModel that limits the unrealized profit per holding to the specified percentage | ```python
from AlgorithmImports import *
class MaximumUnrealizedProfitPercentPerSecurity(RiskManagementModel):
'''Provides an implementation of IRiskManagementModel that limits the unrealized profit per holding to the specified percentage'''
def __init__(self, maximum_unrealized_profit_percent = 0.05):
... |
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework. | Generate a LEAN RiskManagementModel that can be described like this
: Provides an implementation of IRiskManagementModel that limits the drawdown per holding to the specified percentage | ```python
from AlgorithmImports import *
class MaximumDrawdownPercentPerSecurity(RiskManagementModel):
'''Provides an implementation of IRiskManagementModel that limits the drawdown per holding to the specified percentage'''
def __init__(self, maximum_drawdown_percent = 0.05):
'''Initializes a new i... |
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework. | Generate a LEAN RiskManagementModel that can be described like this
: Provides an implementation of IRiskManagementModel that that limits the sector exposure to the specified percentage | ```python
from AlgorithmImports import *
from itertools import groupby
class MaximumSectorExposureRiskManagementModel(RiskManagementModel):
'''Provides an implementation of IRiskManagementModel that that limits the sector exposure to the specified percentage'''
def __init__(self, maximum_sector_exposure = 0... |
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework. | Generate a LEAN RiskManagementModel that can be described like this
: Provides an implementation of IRiskManagementModel that limits the maximum possible loss | ```python
from AlgorithmImports import *
class TrailingStopRiskManagementModel(RiskManagementModel):
'''Provides an implementation of IRiskManagementModel that limits the maximum possible loss
measured from the highest unrealized profit'''
def __init__(self, maximum_drawdown_percent = 0.05):
'''I... |
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework. | Generate a LEAN RiskManagementModel that can be described like this
: Provides an implementation of IRiskManagementModel that limits the drawdown of the portfolio to the specified percentage. | ```python
from AlgorithmImports import *
class MaximumDrawdownPercentPortfolio(RiskManagementModel):
'''Provides an implementation of IRiskManagementModel that limits the drawdown of the portfolio to the specified percentage.'''
def __init__(self, maximum_drawdown_percent = 0.05, is_trailing = False):
... |
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework. | Generate a LEAN UniverseSelectionModel that can be described like this
: Provides a base class for defining equity coarse/fine fundamental selection models | ```python
from AlgorithmImports import *
class FundamentalUniverseSelectionModel:
'''Provides a base class for defining equity coarse/fine fundamental selection models'''
def __init__(self,
filterFineData = None,
universeSettings = None):
'''Initializes a new in... |
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework. | Generate a LEAN UniverseSelectionModel that can be described like this
: Provides an implementation of IUniverseSelectionMode that subscribes to option chains | ```python
from AlgorithmImports import *
from Selection.UniverseSelectionModel import UniverseSelectionModel
class OptionUniverseSelectionModel(UniverseSelectionModel):
'''Provides an implementation of IUniverseSelectionMode that subscribes to option chains'''
def __init__(self,
refreshInter... |
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework. | Generate a LEAN UniverseSelectionModel that can be described like this
: Universe selection model that selects the constituents of an ETF. | ```python
from AlgorithmImports import *
from Selection.UniverseSelectionModel import UniverseSelectionModel
class ETFConstituentsUniverseSelectionModel(UniverseSelectionModel):
'''Universe selection model that selects the constituents of an ETF.'''
def __init__(self,
etf_symbol,
... |
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework. | Generate a LEAN UniverseSelectionModel that can be described like this
: Defines the QC500 universe as a universe selection model for framework algorithm | ```python
from AlgorithmImports import *
from Selection.FundamentalUniverseSelectionModel import FundamentalUniverseSelectionModel
from itertools import groupby
from math import ceil
class QC500UniverseSelectionModel(FundamentalUniverseSelectionModel):
'''Defines the QC500 universe as a universe selection model ... |
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework. | Generate a LEAN UniverseSelectionModel that can be described like this
: Provides an implementation of IUniverseSelectionMode that subscribes to future chains | ```python
from AlgorithmImports import *
from Selection.UniverseSelectionModel import UniverseSelectionModel
class FutureUniverseSelectionModel(UniverseSelectionModel):
'''Provides an implementation of IUniverseSelectionMode that subscribes to future chains'''
def __init__(self,
refreshInte... |
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework. | Generate a LEAN UniverseSelectionModel that can be described like this
: Provides an implementation of FundamentalUniverseSelectionModel that subscribes to | ```python
from AlgorithmImports import *
from Selection.FundamentalUniverseSelectionModel import FundamentalUniverseSelectionModel
class EmaCrossUniverseSelectionModel(FundamentalUniverseSelectionModel):
'''Provides an implementation of FundamentalUniverseSelectionModel that subscribes to
symbols with the la... |
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework. | Generate a LEAN PortfolioConstructionModel that can be described like this
: Provides an implementation of Mean-Variance portfolio optimization based on modern portfolio theory.
The default model uses the MinimumVariancePortfolioOptimizer that accepts a 63-row matrix of 1-day returns. | ```python
from AlgorithmImports import *
from Portfolio.MinimumVariancePortfolioOptimizer import MinimumVariancePortfolioOptimizer
class MeanVarianceOptimizationPortfolioConstructionModel(PortfolioConstructionModel):
def __init__(self,
rebalance = Resolution.DAILY,
portfolio_bia... |
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework. | Generate a LEAN PortfolioConstructionModel that can be described like this
: Provides an implementation of Black-Litterman portfolio optimization. The model adjusts equilibrium market
returns by incorporating views from multiple alpha models and therefore to get the optimal risky portfolio
reflecting those views. If in... | ```python
from AlgorithmImports import *
from Portfolio.MaximumSharpeRatioPortfolioOptimizer import MaximumSharpeRatioPortfolioOptimizer
from itertools import groupby
from numpy import dot, transpose
from numpy.linalg import inv
class BlackLittermanOptimizationPortfolioConstructionModel(PortfolioConstructionModel):
... |
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework. | Generate a LEAN PortfolioConstructionModel that can be described like this
: Provides an implementation of IPortfolioConstructionModel that gives equal weighting to all securities. | ```python
from AlgorithmImports import *
class EqualWeightingPortfolioConstructionModel(PortfolioConstructionModel):
'''Provides an implementation of IPortfolioConstructionModel that gives equal weighting to all securities.
The target percent holdings of each security is 1/N where N is the number of securiti... |
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework. | Generate a LEAN PortfolioConstructionModel that can be described like this
: Provides an implementation of IPortfolioConstructionModel that allocates percent of account | ```python
from AlgorithmImports import *
from EqualWeightingPortfolioConstructionModel import EqualWeightingPortfolioConstructionModel
class AccumulativeInsightPortfolioConstructionModel(EqualWeightingPortfolioConstructionModel):
'''Provides an implementation of IPortfolioConstructionModel that allocates percent... |
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework. | Generate a LEAN PortfolioConstructionModel that can be described like this
: Provides an implementation of IPortfolioConstructionModel that generates percent targets based on the | ```python
from AlgorithmImports import *
from EqualWeightingPortfolioConstructionModel import EqualWeightingPortfolioConstructionModel
class InsightWeightingPortfolioConstructionModel(EqualWeightingPortfolioConstructionModel):
'''Provides an implementation of IPortfolioConstructionModel that generates percent ta... |
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework. | Generate a LEAN PortfolioConstructionModel that can be described like this
: Provides an implementation of IPortfolioConstructionModel that | ```python
from AlgorithmImports import *
from EqualWeightingPortfolioConstructionModel import EqualWeightingPortfolioConstructionModel
class SectorWeightingPortfolioConstructionModel(EqualWeightingPortfolioConstructionModel):
'''Provides an implementation of IPortfolioConstructionModel that
generates percent ... |
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework. | Generate a LEAN PortfolioConstructionModel that can be described like this
: Implementation of On-Line Moving Average Reversion (OLMAR) | ```python
from AlgorithmImports import *
class MeanReversionPortfolioConstructionModel(PortfolioConstructionModel):
def __init__(self,
rebalance = Resolution.Daily,
portfolioBias = PortfolioBias.LongShort,
reversion_threshold = 1,
window_si... |
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework. | Generate a LEAN PortfolioConstructionModel that can be described like this
: Risk Parity Portfolio Construction Model | ```python
from AlgorithmImports import *
from Portfolio.RiskParityPortfolioOptimizer import RiskParityPortfolioOptimizer
class RiskParityPortfolioConstructionModel(PortfolioConstructionModel):
def __init__(self,
rebalance = Resolution.DAILY,
portfolio_bias = PortfolioBias.LONG_S... |
You are a quantive developer and need to generate code for use in QuantConnect's LEAN algorithm framework. | Generate a LEAN PortfolioConstructionModel that can be described like this
: Provides an implementation of IPortfolioConstructionModel that generates percent targets based on the | ```python
from AlgorithmImports import *
from InsightWeightingPortfolioConstructionModel import InsightWeightingPortfolioConstructionModel
class ConfidenceWeightedPortfolioConstructionModel(InsightWeightingPortfolioConstructionModel):
'''Provides an implementation of IPortfolioConstructionModel that generates pe... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.