Strategy Development
From basic research to prototype
Content
• Feature analysis
• Strategy design
• Implementation on QC
• Use the link below to access the research and backtest codes
• https://www.quantconnect.cloud/backtest/
159393e7bb6d540ad5c964bf0e9d2820/?theme=chrome
Feature Analysis
• Research with raw data
• Sampling Features
• Labeling methods
• Example
• Studying quantitative properties of option contracts
Sampling Features
• In module 4, we extracted raw data from different sources
• We then transform them into a continuous, homogeneous, and
structured dataset
• Theoretically, an algo can use the dataset directly, such as machine
learning algos
• But there are practical issues:
• Algos may not scale well when the size of dataset is large
• There could be still too many underlying noises
Sampling Features
• To make algos more efficient, we need ways of sampling bars to
produce something simpler, such as a feature matrix
• Sampling for reduction
• E.g., daily data is the downsampling of minute data, it is useful because it can
reduce the computational load of the algo
Sampling Features
• Event-Based Sampling
• Capturing certain events that may improve the prediction
• Technical Indicators
• MACD
• SMA
• Point and Figure
• RSI
• Earnings Announcement Dates
•…
Labeling Methods
• Two types of algo of machine learning
• Unsupervised learning algos can learn the patterns from the features directly
• Supervised learning algos require an array of labels of the features data
• Example
• In WOO ratings system, we use 1,2,3,… for each indicator and give a GO if we
have 1 for each indicator
• In SMA crossover algo, we use 1, 0, -1 for the events of SMAs.
• In AFML Chapter 3, the triple-barrier labeling method labels each event when
one of the barriers is touched. (000, 100, 010,…)
Example: Options Feature Analysis
• We ask: How often did OTM options expire worthless?
• If it happens often, we may use option selling strategy like an
insurance company
• Using SPY monthly options, the result is in the next page
SPY OTM Options Expired Worthless
• 2024, Put: 93.93% (1223/1302 contracts), Call: 85.44% (904/1058)
• 2023, Put: 96.68% (1165/1205), Call: 89.56% (1158/1293)
• 2022, Put: 85.61% (726/848), Call: 93% (797/857)
• 2021, Put: 97.98% (632/645), Call: 92.14% (563/611)
• 2020, Put: 92.25% (679/736), Call: 85.39% (608/712).
• 2019, Put: 96.81% (699/722), Call: 84.63% (424/501).
• 2018, Put: 92.13% (644/699), Call: 89.87% (603/671).
• 2017, Put: 97.82% (629/643), Call: 71.22% (458/643).
• 2016, Put: 96.70% (675/698), Call: 88.81% (516/581).
• 2015, Put: 91.79% (682/743), Call: 92.67% (595/642).
How to Explain This?
• In 2016-2024, except in 2022, the market has been up most of the
time
• When market went down, the recovery was in general quite fast
• The volatility of market index is relatively small due to QE and investor
optimism
Options Feature Analysis
• Using indicator labels
• We ask: Which MACD group of [1, 2, 3, 4, 5, 6] works better when
predicting the worthless expiration of OTM put contracts?”
• The result 2017-2020, SPY Puts
• MACD label is 1, 95.3%, 721/15346 ITM contracts.
• MACD label is 2, 93.7%, 649/10295 ITM.
• MACD label is 3, 92.2%, 118/1510 ITM.
• MACD label is 4, 87.7%, 528/4281 ITM.
• MACD label is 5, 92.5%, 228/3054 ITM.
• MACD label is 6, 98.9%, 12/1102 ITM.
How to Explain This?
• MACD is one of the simplest and effective momentum indicators
• In 2017-2020, the market has been up most of the time
• Bearish labels are less frequent
• When market went down, the recovery was in general quite fast
• This implies that bearish labels (such as 2, 3) did not lead to bearish
outcomes unless they are very bearish (such as 4).
• Meanwhile, the bullish label such as 1 does not perform significantly
better
• The recovery label 6 worked best because of fast recovery
Strategy Design
• At this stage we want to transform informative features into
actual investment by
• Making sense of all the observations and formulating a general
theory that explains them
• Coding the full algo as the prototype using QC
Algo Ideas
• Sell monthly SPY puts with the ATM strike
• Use 90% of the capital
• Sell puts whenever our portfolio is all cash
• If our options get assigned, we sell the stocks next day
• Use MACD labels for better timing
• See “main.py” and “labels.py”
Modules of the Algo
• Initialization
• Start date and end date
• Initial capital
• The symbols for data request
• Options filtering rule (days to expiration, tiers of strikes)
• The fraction of capital to use
• Indicator definition
• Dataframe and variables to store information (contract symbol,
number of shares, label of indicator) on the run
Modules of the Algo
• OnData: Evaluation and action on data slice (OnData)
• Is the indicator generated? If not, wait for the next data slice.
• Do we have shares assigned? If so, sell it right away
• Do we have any options position? If so, wait for the next data slice
• Compute the MACD label
• Compute the number of contracts to sell
• Select the contract (PUT, ATM with strike just below SPY’s market price)
• Trade the contract by market order when the label is in the prefixed set, also
log the label.
• OnOrderEvent: Log the transactions
Contract Selection
• How is a contract selected?
• We request Options Data Using data.OptionChains instead of
OptionsChainProvider
• It returns a list of options contracts for each date
• We then sort the contracts and select the proper one
QuantConnect Screencopy
Results
• In Sample (12/01/2015-12/01/2020)
• Any MACD : Sharpe = 0.435
• MACD in [1]: Sharpe = 0.881
• MACD in [1,6]: Sharpe = 1.099
• Out of Sample (12/01/2020-12/01/2023)
• Any MACD: Sharpe = 0.028
• MACD in [1]: Sharpe = -0.232
• MACD in [1,6]: Sharpe = -0.048
Questions for You
• What data do you want to use?
• What feature analysis results do you get?
• What strategy do you want to design?
• What In-Sample and Out-of-Sample periods do you want to use?
• What tweaks you can do on top of the existing algo, possibly available
on the Internet?