www.quantinsti.com
CONFIDENTIAL. NOT TO BE SHARED OUTSIDE WITHOUT WRITTEN CONSENT.
Building & Managing Strategies
Using Quantra Blueshift Platform
www.quantinsti.com
CONFIDENTIAL. NOT TO BE SHARED OUTSIDE WITHOUT WRITTEN CONSENT.
What is Blueshift
Heading Font: Calibri (Headings)
Size: 36
Color: White
Systematic Trading Strategies – For Everyone!
IP protection
Financial datasets
On the cloud Back-testing
Strategy research
Learning and community
www.quantinsti.com
CONFIDENTIAL. NOT TO BE SHARED OUTSIDE WITHOUT WRITTEN CONSENT.
Outline of Today’s Session
1. A few words about systematic strategies
2. A very short primer on python
3. Introduction to Blueshift
4. Creating a re-usable template
5. Some Technical notes on Technical Indicators
6. A simple technical indicator based strategy on Blueshift
7. Managing a portfolio strategies
8. Ensemble portfolios
9. Trading without ‘regrets’ – A no-regret approach
10. Concluding remarks
What is it NOT
1. Trade recommendation
2. The ‘best’ strategies that ‘always’ work
3. Precautions to be taken in back-testing (may be another session!)
www.quantinsti.com
CONFIDENTIAL. NOT TO BE SHARED OUTSIDE WITHOUT WRITTEN CONSENT.
Systematic Strategies
A Systematic Approach
“Successful investing is anticipating the anticipations
of others.”
John Maynard Keynes (Economist)
www.quantinsti.com
CONFIDENTIAL. NOT TO BE SHARED OUTSIDE WITHOUT WRITTEN CONSENT.
The Strategy Spectrum
www.quantinsti.com
CONFIDENTIAL. NOT TO BE SHARED OUTSIDE WITHOUT WRITTEN CONSENT.
Systematic Strategy Design Cycle
Universe
Selection
Signal
Generation
Target
Portfolio
Rebalance
Improve
Can be static or dynamic
with filtering
Can be independent
of/ Dependent on
the rest
Based on signals +
positions rules
Execution rules/
strategies go here
Research and
refinement process
www.quantinsti.com
CONFIDENTIAL. NOT TO BE SHARED OUTSIDE WITHOUT WRITTEN CONSENT.
Systematic Strategy Development
 Inputs: Input to the strategies can come in many flavours1 like
 Price/ returns and it’s transformation. Most of the common technical indicators are transformation of price returns2
 Positioning information – volumes and open interest data and participant-wise positioning data if available
 Fundamental information –macro-economic information, company fundamentals
 Non-market information: Example twitter sentiments, analysts ratings etc.
 Trading Rules/ Logic: Can be either based on trader’s hypothesis or inferred (learned) from
data
 Form hypothesis (e.g. moving average cross-over signals change in trends) and test – traditional approach
 Feed data to infer rules (the subject matter of machine learning and artificial intelligence)
 Back-testing and Forward-testing: A crucial step and often over-looked step.
 A good platform to guard against biases : data-mining bias, survivorship bias, market-impact modeling, look-ahead bias
 Should be flexible, event-driven (to avoid look-ahead bias) and with built-in analytics
 Portfolio Creation/ Optimization: Never go all-in with a single strategy
 Two strategies better than one – if they are uncorrelated (in terms of signals and/ or performance)
 Various methods exists – ensemble, traditional portfolio theory, dynamic portfolio allocation etc.
1. Ideally sources should be disparate, uncorrelated and relevant.
2. For further technical details see here.
www.quantinsti.com
CONFIDENTIAL. NOT TO BE SHARED OUTSIDE WITHOUT WRITTEN CONSENT.
Developing Strategies
Introduction to the Blueshift Platform
“Unfortunately for the case of sanity, that (momentum
investing) seems to be true.”
Cliff Asness (AQR Capital)
www.quantinsti.com
CONFIDENTIAL. NOT TO BE SHARED OUTSIDE WITHOUT WRITTEN CONSENT.
A Very Short Primer on Python
1. Signing up and Platform Tour
2. Creating Strategy from template
3. Let’s run and see
Python Primer in 40 lines of code
1. Print statement
2. Variables types
3. Dictionaries
4. Lists and loop
5. Defining functions
6. Defining Classes
Accessing Data on Blueshift
1. Re-run the example
2. Printing info at the end of backtest – analyze()
3. Accessing the data object
www.quantinsti.com
CONFIDENTIAL. NOT TO BE SHARED OUTSIDE WITHOUT WRITTEN CONSENT.
Work-Flow on Blueshift
initialize()
handle_data()
before_trading_start()
Called once at the start of the algorithm
Place to set up algorithm parameters and initialize them
Arguments: context – a dictionary object to store all user parameters
and variables and available to all other functions
Called once at the start of the trading session (i.e. once a day)
Place to set up daily pre-open stuff
Arguments: context – as above, and data – a object with current
date-time, can be queried for current or historical data on symbols
Called once at every bar (every minute)
Place to set up logic on how to respond to market data
Arguments: context – as above, and data – as above
schedule_function()
date_rules()
time_rules()
Other Useful
API Functions
order_percent_target()
get_open_orders()
cancel_order()
set_commission()
set_slippage()
set_account_currency()
Schedule any user-
defined functions
at a given time and
frequency
Functions to place,
and cancel orders
Functions to set
trading and other
parameters
www.quantinsti.com
CONFIDENTIAL. NOT TO BE SHARED OUTSIDE WITHOUT WRITTEN CONSENT.
Blueshift Environment
Data contains everything needed to feed data: current(), history(), as well
as current_dt
Context contains everything else: Portfolio (context.portfolio), account
(context.account), calendar (trading_calendar)
See here for more details
Context
trading_calendar
tz(), open_time()
etc.
account leverage, etc.
portfolio positions
asset, amount
etc.
www.quantinsti.com
CONFIDENTIAL. NOT TO BE SHARED OUTSIDE WITHOUT WRITTEN CONSENT.
Getting Started with Development
Creating Our Own Template
1. Why? Makes things easy and fast – take care of boiler plates
2. Modify the initialize function:
1. Add necessary imports
2. Keeping all parameters at one place – in a dictionary
3. Add trading universe list
4. keep track of rebalance weights
5. Set trading costs and commissions structure
6. Add Agent object
3. Defining our agent object class
1. It fetches prices, compute the signal and keep track of PnL
4. Let’s add some technical indicators
5. Implementing a signal – the expert advisor
6. Add the run strategy function and the rebalance function
7. Update handle_data
8. Let’s run the strategy
www.quantinsti.com
CONFIDENTIAL. NOT TO BE SHARED OUTSIDE WITHOUT WRITTEN CONSENT.
Technical Indicators
Using Technical Indicators in Strategies
“A rising market and a long position is a sure sign of
investment genius”
John Kenneth Galbraith (Economist)
www.quantinsti.com
CONFIDENTIAL. NOT TO BE SHARED OUTSIDE WITHOUT WRITTEN CONSENT.
Getting Technical with Indicators
Most technical indicators share some common traits
𝐼 = 𝑓 𝑂, 𝐻, 𝐿, 𝐶, 𝑉 ~ 𝑓(𝑟𝑒𝑡𝑢𝑟𝑛𝑠, 𝑣𝑜𝑙𝑢𝑚𝑒𝑠)
1. Technical indicators can be expressed as weighted function of returns
2. They tend to move in a range (not always statistically ‘stationary’
3. Major categories are:
1. linear function of returns (e.g. MA, MACD, CCI)
2. Function of sign of returns (e.g. RSI, Chande oscillator)
3. Function of returns in time space (Aroon oscillator)
4. They are usually correlated: first component of correlation indicates
momentum/ mean-reversion
5. They differ in their time-series characteristics (the frequency response)
6. They can benefit from the ‘self fulfilling prophecy’
7. They can suffer from ‘predatory’ algorithm, especially in high-frequency
8. Guaranteed to work in a strong momentum/ mean-reversion (needs
tuning). But NOT guaranteed to signal so!
www.quantinsti.com
CONFIDENTIAL. NOT TO BE SHARED OUTSIDE WITHOUT WRITTEN CONSENT.
A Simple Strategy
Buy (sell): if close near lower (upper) bands
Buy (sell): if close away from extremes and positive (negative) momentum
Chart from Trading View
www.quantinsti.com
CONFIDENTIAL. NOT TO BE SHARED OUTSIDE WITHOUT WRITTEN CONSENT.
Performance of Strategies
www.quantinsti.com
CONFIDENTIAL. NOT TO BE SHARED OUTSIDE WITHOUT WRITTEN CONSENT.
Managing Strategy Portfolio
Ensemble, Change-points, No-regrets
“Past performance is the best predictor of success”
Jim Simons (Renaissance Technologies)
www.quantinsti.com
CONFIDENTIAL. NOT TO BE SHARED OUTSIDE WITHOUT WRITTEN CONSENT.
Managing Strategy Portfolio
Ensemble/ Committee: Allocation based on voting. We can
average the signal, use a weighted average (ensemble
strategy), or we can define a voting scheme (majority, all-or-
nothing etc.)
Regime-Switching: Different strategies exploit different market
conditions. This method tries to identify change in market
regime and select model(s) best suited [Not demo-ed]
Dynamic/ No-regrets: Adaptive weighing of strategy portfolio
based on past performance. No-regret is a special case trying
to minimize regrets with the benefits of hind-sight. Kelly
portfolios can also be clubbed under this
Factor-based: Analyze the returns of each individual
strategies and cast them in to identifiable risk factor
components. Then build portfolio based on desired exposures
to each factors and/ or isolate alpha [Not demo-ed]
www.quantinsti.com
CONFIDENTIAL. NOT TO BE SHARED OUTSIDE WITHOUT WRITTEN CONSENT.
Committee of Experts
Why Ensemble Works?
𝐸 𝑦 − 𝑓 𝑥 2 = 𝐸 𝑓 𝑥 − 𝑓(𝑥) 2 + 𝐸 𝑓 𝑥 2 − 𝐸 𝑓 𝑥 2 + 𝜎2
Primarily works through reducing variance and improving forecast!
1. Adding the agent class – takes in a list of advisors
1. Computes the weighted signals from panel of advisors
2. Update weights periodically
3. Keep track of the performance of each advisors
2. Scheduling the weights and performance updaters
3. Modify the strategy function
4. Run and see
Total Error Bias/ Accuracy Variance/ Stability
www.quantinsti.com
CONFIDENTIAL. NOT TO BE SHARED OUTSIDE WITHOUT WRITTEN CONSENT.
Trading Without Regrets
How to play slot-machines? How about many of them simultaneously?
No-Regret Learning: An allocation scheme ‘similar’ to the best portfolio.
A large learning rate is exploitive and a small learning rate is explorative.
Smells of both mean-reversion (short-term) and trending (long-term)
1. Implementing the logic (we already have performance history)
2. Run and see
3. Switching to Kelly Portfolio
www.quantinsti.com
CONFIDENTIAL. NOT TO BE SHARED OUTSIDE WITHOUT WRITTEN CONSENT.
Performance of Strategies
www.quantinsti.com
CONFIDENTIAL. NOT TO BE SHARED OUTSIDE WITHOUT WRITTEN CONSENT.
Strategy Development - Recommendations
Always save all your strategy variables in the `context` environment
- helps tracking variables and re-starts
Use schedule_function if your algo does not need to respond to every bars
- will run faster
Good practice to check account leverage to make sure the algo is running as
intended
Do not over-fit – build a hypothesis and test. Data-mining (p-hacking)
generates good performance in the past and bad going forward
Check the stats in the backtest results. A strategy with low Sharpe,
concentrated wins (low stability), large downside risks (negative skew),
and large drawdowns and high beta is not a good candidate
www.quantinsti.com
CONFIDENTIAL. NOT TO BE SHARED OUTSIDE WITHOUT WRITTEN CONSENT.
List of Demo Strategies
1. Strategy Template
2. Ensemble portfolio
3. Kelly portfolio
4. No-regret portfolio
All under /portfolio
Also don’t forget to check out the examples under /equities and /forex
Find them at: https://github.com/QuantInsti/blueshift-demo-strategies
www.quantinsti.com
CONFIDENTIAL. NOT TO BE SHARED OUTSIDE WITHOUT WRITTEN CONSENT.
THANK YOU!
For further queries reach out to blueshift-support@quantinsti.com

Develop And Backtest Your Trading Strategy - Demo - Presentation

  • 1.
    www.quantinsti.com CONFIDENTIAL. NOT TOBE SHARED OUTSIDE WITHOUT WRITTEN CONSENT. Building & Managing Strategies Using Quantra Blueshift Platform
  • 2.
    www.quantinsti.com CONFIDENTIAL. NOT TOBE SHARED OUTSIDE WITHOUT WRITTEN CONSENT. What is Blueshift Heading Font: Calibri (Headings) Size: 36 Color: White Systematic Trading Strategies – For Everyone! IP protection Financial datasets On the cloud Back-testing Strategy research Learning and community
  • 3.
    www.quantinsti.com CONFIDENTIAL. NOT TOBE SHARED OUTSIDE WITHOUT WRITTEN CONSENT. Outline of Today’s Session 1. A few words about systematic strategies 2. A very short primer on python 3. Introduction to Blueshift 4. Creating a re-usable template 5. Some Technical notes on Technical Indicators 6. A simple technical indicator based strategy on Blueshift 7. Managing a portfolio strategies 8. Ensemble portfolios 9. Trading without ‘regrets’ – A no-regret approach 10. Concluding remarks What is it NOT 1. Trade recommendation 2. The ‘best’ strategies that ‘always’ work 3. Precautions to be taken in back-testing (may be another session!)
  • 4.
    www.quantinsti.com CONFIDENTIAL. NOT TOBE SHARED OUTSIDE WITHOUT WRITTEN CONSENT. Systematic Strategies A Systematic Approach “Successful investing is anticipating the anticipations of others.” John Maynard Keynes (Economist)
  • 5.
    www.quantinsti.com CONFIDENTIAL. NOT TOBE SHARED OUTSIDE WITHOUT WRITTEN CONSENT. The Strategy Spectrum
  • 6.
    www.quantinsti.com CONFIDENTIAL. NOT TOBE SHARED OUTSIDE WITHOUT WRITTEN CONSENT. Systematic Strategy Design Cycle Universe Selection Signal Generation Target Portfolio Rebalance Improve Can be static or dynamic with filtering Can be independent of/ Dependent on the rest Based on signals + positions rules Execution rules/ strategies go here Research and refinement process
  • 7.
    www.quantinsti.com CONFIDENTIAL. NOT TOBE SHARED OUTSIDE WITHOUT WRITTEN CONSENT. Systematic Strategy Development  Inputs: Input to the strategies can come in many flavours1 like  Price/ returns and it’s transformation. Most of the common technical indicators are transformation of price returns2  Positioning information – volumes and open interest data and participant-wise positioning data if available  Fundamental information –macro-economic information, company fundamentals  Non-market information: Example twitter sentiments, analysts ratings etc.  Trading Rules/ Logic: Can be either based on trader’s hypothesis or inferred (learned) from data  Form hypothesis (e.g. moving average cross-over signals change in trends) and test – traditional approach  Feed data to infer rules (the subject matter of machine learning and artificial intelligence)  Back-testing and Forward-testing: A crucial step and often over-looked step.  A good platform to guard against biases : data-mining bias, survivorship bias, market-impact modeling, look-ahead bias  Should be flexible, event-driven (to avoid look-ahead bias) and with built-in analytics  Portfolio Creation/ Optimization: Never go all-in with a single strategy  Two strategies better than one – if they are uncorrelated (in terms of signals and/ or performance)  Various methods exists – ensemble, traditional portfolio theory, dynamic portfolio allocation etc. 1. Ideally sources should be disparate, uncorrelated and relevant. 2. For further technical details see here.
  • 8.
    www.quantinsti.com CONFIDENTIAL. NOT TOBE SHARED OUTSIDE WITHOUT WRITTEN CONSENT. Developing Strategies Introduction to the Blueshift Platform “Unfortunately for the case of sanity, that (momentum investing) seems to be true.” Cliff Asness (AQR Capital)
  • 9.
    www.quantinsti.com CONFIDENTIAL. NOT TOBE SHARED OUTSIDE WITHOUT WRITTEN CONSENT. A Very Short Primer on Python 1. Signing up and Platform Tour 2. Creating Strategy from template 3. Let’s run and see Python Primer in 40 lines of code 1. Print statement 2. Variables types 3. Dictionaries 4. Lists and loop 5. Defining functions 6. Defining Classes Accessing Data on Blueshift 1. Re-run the example 2. Printing info at the end of backtest – analyze() 3. Accessing the data object
  • 10.
    www.quantinsti.com CONFIDENTIAL. NOT TOBE SHARED OUTSIDE WITHOUT WRITTEN CONSENT. Work-Flow on Blueshift initialize() handle_data() before_trading_start() Called once at the start of the algorithm Place to set up algorithm parameters and initialize them Arguments: context – a dictionary object to store all user parameters and variables and available to all other functions Called once at the start of the trading session (i.e. once a day) Place to set up daily pre-open stuff Arguments: context – as above, and data – a object with current date-time, can be queried for current or historical data on symbols Called once at every bar (every minute) Place to set up logic on how to respond to market data Arguments: context – as above, and data – as above schedule_function() date_rules() time_rules() Other Useful API Functions order_percent_target() get_open_orders() cancel_order() set_commission() set_slippage() set_account_currency() Schedule any user- defined functions at a given time and frequency Functions to place, and cancel orders Functions to set trading and other parameters
  • 11.
    www.quantinsti.com CONFIDENTIAL. NOT TOBE SHARED OUTSIDE WITHOUT WRITTEN CONSENT. Blueshift Environment Data contains everything needed to feed data: current(), history(), as well as current_dt Context contains everything else: Portfolio (context.portfolio), account (context.account), calendar (trading_calendar) See here for more details Context trading_calendar tz(), open_time() etc. account leverage, etc. portfolio positions asset, amount etc.
  • 12.
    www.quantinsti.com CONFIDENTIAL. NOT TOBE SHARED OUTSIDE WITHOUT WRITTEN CONSENT. Getting Started with Development Creating Our Own Template 1. Why? Makes things easy and fast – take care of boiler plates 2. Modify the initialize function: 1. Add necessary imports 2. Keeping all parameters at one place – in a dictionary 3. Add trading universe list 4. keep track of rebalance weights 5. Set trading costs and commissions structure 6. Add Agent object 3. Defining our agent object class 1. It fetches prices, compute the signal and keep track of PnL 4. Let’s add some technical indicators 5. Implementing a signal – the expert advisor 6. Add the run strategy function and the rebalance function 7. Update handle_data 8. Let’s run the strategy
  • 13.
    www.quantinsti.com CONFIDENTIAL. NOT TOBE SHARED OUTSIDE WITHOUT WRITTEN CONSENT. Technical Indicators Using Technical Indicators in Strategies “A rising market and a long position is a sure sign of investment genius” John Kenneth Galbraith (Economist)
  • 14.
    www.quantinsti.com CONFIDENTIAL. NOT TOBE SHARED OUTSIDE WITHOUT WRITTEN CONSENT. Getting Technical with Indicators Most technical indicators share some common traits 𝐼 = 𝑓 𝑂, 𝐻, 𝐿, 𝐶, 𝑉 ~ 𝑓(𝑟𝑒𝑡𝑢𝑟𝑛𝑠, 𝑣𝑜𝑙𝑢𝑚𝑒𝑠) 1. Technical indicators can be expressed as weighted function of returns 2. They tend to move in a range (not always statistically ‘stationary’ 3. Major categories are: 1. linear function of returns (e.g. MA, MACD, CCI) 2. Function of sign of returns (e.g. RSI, Chande oscillator) 3. Function of returns in time space (Aroon oscillator) 4. They are usually correlated: first component of correlation indicates momentum/ mean-reversion 5. They differ in their time-series characteristics (the frequency response) 6. They can benefit from the ‘self fulfilling prophecy’ 7. They can suffer from ‘predatory’ algorithm, especially in high-frequency 8. Guaranteed to work in a strong momentum/ mean-reversion (needs tuning). But NOT guaranteed to signal so!
  • 15.
    www.quantinsti.com CONFIDENTIAL. NOT TOBE SHARED OUTSIDE WITHOUT WRITTEN CONSENT. A Simple Strategy Buy (sell): if close near lower (upper) bands Buy (sell): if close away from extremes and positive (negative) momentum Chart from Trading View
  • 16.
    www.quantinsti.com CONFIDENTIAL. NOT TOBE SHARED OUTSIDE WITHOUT WRITTEN CONSENT. Performance of Strategies
  • 17.
    www.quantinsti.com CONFIDENTIAL. NOT TOBE SHARED OUTSIDE WITHOUT WRITTEN CONSENT. Managing Strategy Portfolio Ensemble, Change-points, No-regrets “Past performance is the best predictor of success” Jim Simons (Renaissance Technologies)
  • 18.
    www.quantinsti.com CONFIDENTIAL. NOT TOBE SHARED OUTSIDE WITHOUT WRITTEN CONSENT. Managing Strategy Portfolio Ensemble/ Committee: Allocation based on voting. We can average the signal, use a weighted average (ensemble strategy), or we can define a voting scheme (majority, all-or- nothing etc.) Regime-Switching: Different strategies exploit different market conditions. This method tries to identify change in market regime and select model(s) best suited [Not demo-ed] Dynamic/ No-regrets: Adaptive weighing of strategy portfolio based on past performance. No-regret is a special case trying to minimize regrets with the benefits of hind-sight. Kelly portfolios can also be clubbed under this Factor-based: Analyze the returns of each individual strategies and cast them in to identifiable risk factor components. Then build portfolio based on desired exposures to each factors and/ or isolate alpha [Not demo-ed]
  • 19.
    www.quantinsti.com CONFIDENTIAL. NOT TOBE SHARED OUTSIDE WITHOUT WRITTEN CONSENT. Committee of Experts Why Ensemble Works? 𝐸 𝑦 − 𝑓 𝑥 2 = 𝐸 𝑓 𝑥 − 𝑓(𝑥) 2 + 𝐸 𝑓 𝑥 2 − 𝐸 𝑓 𝑥 2 + 𝜎2 Primarily works through reducing variance and improving forecast! 1. Adding the agent class – takes in a list of advisors 1. Computes the weighted signals from panel of advisors 2. Update weights periodically 3. Keep track of the performance of each advisors 2. Scheduling the weights and performance updaters 3. Modify the strategy function 4. Run and see Total Error Bias/ Accuracy Variance/ Stability
  • 20.
    www.quantinsti.com CONFIDENTIAL. NOT TOBE SHARED OUTSIDE WITHOUT WRITTEN CONSENT. Trading Without Regrets How to play slot-machines? How about many of them simultaneously? No-Regret Learning: An allocation scheme ‘similar’ to the best portfolio. A large learning rate is exploitive and a small learning rate is explorative. Smells of both mean-reversion (short-term) and trending (long-term) 1. Implementing the logic (we already have performance history) 2. Run and see 3. Switching to Kelly Portfolio
  • 21.
    www.quantinsti.com CONFIDENTIAL. NOT TOBE SHARED OUTSIDE WITHOUT WRITTEN CONSENT. Performance of Strategies
  • 22.
    www.quantinsti.com CONFIDENTIAL. NOT TOBE SHARED OUTSIDE WITHOUT WRITTEN CONSENT. Strategy Development - Recommendations Always save all your strategy variables in the `context` environment - helps tracking variables and re-starts Use schedule_function if your algo does not need to respond to every bars - will run faster Good practice to check account leverage to make sure the algo is running as intended Do not over-fit – build a hypothesis and test. Data-mining (p-hacking) generates good performance in the past and bad going forward Check the stats in the backtest results. A strategy with low Sharpe, concentrated wins (low stability), large downside risks (negative skew), and large drawdowns and high beta is not a good candidate
  • 23.
    www.quantinsti.com CONFIDENTIAL. NOT TOBE SHARED OUTSIDE WITHOUT WRITTEN CONSENT. List of Demo Strategies 1. Strategy Template 2. Ensemble portfolio 3. Kelly portfolio 4. No-regret portfolio All under /portfolio Also don’t forget to check out the examples under /equities and /forex Find them at: https://github.com/QuantInsti/blueshift-demo-strategies
  • 24.
    www.quantinsti.com CONFIDENTIAL. NOT TOBE SHARED OUTSIDE WITHOUT WRITTEN CONSENT. THANK YOU! For further queries reach out to blueshift-support@quantinsti.com