SlideShare uma empresa Scribd logo
1 de 21
Baixar para ler offline
Pairs Trading in Python
Introduction and application of classical pairs trading
www.quantconnect.com
Jared Broad
CEO and Founder
Outline
▪ Introduction to QuantConnect
▪ General Idea of Pairs Trading
▪ Implementing the Model
▪ Testing and Researching
▪ Weaknesses of Pairs Trading
▪ Summary
February-2018 QuantConnect – Pairs Trading with Python Page 2
What is QuantConnect?
We empower investors with powerful
investment tools and connect the brightest
minds from around the world with capital they need.
February-2018 QuantConnect – Pairs Trading with Python Page 3
What is QuantConnect?
QuantConnect is a community of 50,000 Engineers, Data Scientists, Programmers
From 6,100 Cities and 173 Countries
February-2018 QuantConnect – Pairs Trading with Python Page 4
Building Thousands of Algorithms Every Day
February-2018 QuantConnect – Pairs Trading with Python Page 5
We’ve built a web algorithm lab where thousands of
people test their ideas on financial data we provide; for free.
LEAN ALGO
TECHNOLOGY
FINANCIAL
DATA
POWER
COMPUTING
How do we do it?
EQUITIES
OPTIONS
FUTURES
FOREX
CRYPTO
February-2018 QuantConnect – Pairs Trading with Python Page 6
Pairs Trading – Market Neutral Trading Strategy
Pairs trading is a type of statistical arbitrage
Basic Idea:
1) Select two stocks which move similarly.
2) Find where the price diverges.
3) Sell the high priced stock and buy the low priced stock.
February-2018 QuantConnect – Pairs Trading with Python Page 7
February-2018 QuantConnect – Pairs Trading with Python Page 8
The Price Ratio
To standardize the prices – we make a
Price Ratio. This allows us to compare
Stock A and Stock B over time.
Price Ratio = Stock A / Stock B
If the Ratio changes significantly,
it’s a signal to trade.
We can measure this change with
standard deviation.
0
2
4
6
8
10
12
14
Jan-08 Feb-08 Mar-08 Apr-08 May-08 Jun-08 Jul-08 Aug-08
Price Series of Stock A and B Stock A Stock B
Price(B) = 2 * Price(A) + 1
0
2
4
6
8
10
12
14
16
Jan-08 Feb-08 Mar-08 Apr-08 May-08 Jun-08 Jul-08 Aug-08
Price Divergence Stock A Stock B
Example Price Divergence
February-2018 QuantConnect – Pairs Trading with Python Page 9
Basic Idea of Pairs Trading
Buy CVX
Sell XOM
Buy XOM
Sell CVX
Buy CVX
Sell XOM
Buy XOM
Sell CVX
Ratio Upper Threshold
Ratio Lower Threshold
When assets cross divergence threshold; trigger trade.
February-2018 QuantConnect – Pairs Trading with Python Page 10
StandardDeviations
Can we apply this idea to trading strategy?
To apply this concept;
❖ We model price with the log of stock price. This follows Brownian Motion N(0, ∆𝑡).
❖ This way the difference of the asset prices are cointegrated.
i.e. log(pricex) – log(pricey) is “One-Order Cointegrated”.
Stationary & Mean Reversion
February-2018 QuantConnect – Pairs Trading with Python Page 10
Step 1: Generate the spread of two log price series
𝑆𝑝𝑟𝑒𝑎𝑑 𝑡 = log(𝑌𝑡) − (𝛼 + 𝛽log(𝑋𝑡))
Step 2: Set the range of spread series [lower, upper]
If 𝑆𝑝𝑟𝑒𝑎𝑑 𝑡 > 𝑢𝑝𝑝𝑒𝑟 𝑡ℎ𝑟𝑒𝑠ℎ𝑜𝑙𝑑 Buy 𝑋𝑡, Sell 𝑌𝑡
If 𝑆𝑝𝑟𝑒𝑎𝑑 𝑡 < 𝑙𝑜𝑤𝑒𝑟 𝑡ℎ𝑟𝑒𝑠ℎ𝑜𝑙𝑑 Buy 𝑌𝑡, Sell 𝑋𝑡
Exploratory Research
❖ Find two likely cointegrated stocks: e.g. XOM, CVX
❖ Estimate spreads between each stock.
❖ Check for stationarity.
QuantBook Research
February-2018 QuantConnect – Pairs Trading with Python Page 12
Pairs Trading Weaknesses
❖ Double the fees.
❖ Capitalize on small price movements.
❖ Risk correlation will break down (e.g. CEO
change, new technology)
❖ Execution risk (slippage).
February-2018 QuantConnect – Pairs Trading with Python Page 13
LEAN Implementation
Backtest
❖ Create our Trading Signal.
❖ Run Backtest in QuantConnect.
February-2018 QuantConnect – Pairs Trading with Python Page 14
Summary
❖ We use cointegration to detect a long term relationship of two stocks.
❖ Changes in that relationship might signal a chance to profit by pairs trading.
Next Steps – Defining Trading Rules, Setting Thresholds
Total Trades Drawdown Net Profit Sharpe Ratio
270 12.9% 34% 0.555
February-2018 QuantConnect – Pairs Trading with Python Page 15
www.quantconnect.com
Thank you.
Appendix
Cointegration and Stationary
• Cointegration is a statistical property of a time
series(like the stock price series).
• Cointegration specifies a co-movement relationship of
price – the long term relationship.
• The mean and the variance of the
series do not vary over time
Cointegration Stationary
• If two series {𝑋𝑡} and {𝑌𝑡} are not stationary
• But their linear combination 𝑌𝑡 = 𝛽𝑋𝑡 − 𝛼 is a stationary process
{𝑿 𝒕} and {𝒀 𝒕} are cointegrated
How to test if two series are cointegrated?
Augmented Dickey-Fuller test
February-2018 QuantConnect – Pairs Trading with Python Page 18
Our Research Environment
February-2018 QuantConnect – Pairs Trading With Python Page 19
Coding the Idea, The Algorithm Lab
February-2018 QuantConnect – Pairs Trading With Python Page 20
Going Live, Deploying to Live Trading
February-2018 QuantConnect – Pairs Trading with Python Page 21

Mais conteúdo relacionado

Mais procurados

What we learned from running a quant crypto hedge fund
What we learned from running a quant crypto hedge fundWhat we learned from running a quant crypto hedge fund
What we learned from running a quant crypto hedge fundYingdan (Mora) Liang
 
"Fundamental Forecasts: Methods and Timing" by Vinesh Jha, CEO of ExtractAlpha
"Fundamental Forecasts: Methods and Timing" by Vinesh Jha, CEO of ExtractAlpha"Fundamental Forecasts: Methods and Timing" by Vinesh Jha, CEO of ExtractAlpha
"Fundamental Forecasts: Methods and Timing" by Vinesh Jha, CEO of ExtractAlphaQuantopian
 
Intra-Day De Mark Plus Order Flow Indicator by Dr. Christopher Ting, SMU
  Intra-Day De Mark Plus Order Flow Indicator by Dr. Christopher Ting, SMU  Intra-Day De Mark Plus Order Flow Indicator by Dr. Christopher Ting, SMU
Intra-Day De Mark Plus Order Flow Indicator by Dr. Christopher Ting, SMUQuantopian
 
"Enhancing Statistical Significance of Backtests" by Dr. Ernest Chan, Managin...
"Enhancing Statistical Significance of Backtests" by Dr. Ernest Chan, Managin..."Enhancing Statistical Significance of Backtests" by Dr. Ernest Chan, Managin...
"Enhancing Statistical Significance of Backtests" by Dr. Ernest Chan, Managin...Quantopian
 
"Quantitative Trading as a Mathematical Science" by Dr. Haksun Li, Founder an...
"Quantitative Trading as a Mathematical Science" by Dr. Haksun Li, Founder an..."Quantitative Trading as a Mathematical Science" by Dr. Haksun Li, Founder an...
"Quantitative Trading as a Mathematical Science" by Dr. Haksun Li, Founder an...Quantopian
 
Pairs Trading: Optimizing via Mixed Copula versus Distance Method for S&P 5...
	 Pairs Trading: Optimizing via Mixed Copula versus Distance Method for S&P 5...	 Pairs Trading: Optimizing via Mixed Copula versus Distance Method for S&P 5...
Pairs Trading: Optimizing via Mixed Copula versus Distance Method for S&P 5...Fernando A. B. Sabino da Silva
 
Volatility Trading - Hedge Fund Strategies
Volatility Trading - Hedge Fund StrategiesVolatility Trading - Hedge Fund Strategies
Volatility Trading - Hedge Fund StrategiesHedge Fund South Africa
 
"Quant Trading for a Living – Lessons from a Life in the Trenches" by Andreas...
"Quant Trading for a Living – Lessons from a Life in the Trenches" by Andreas..."Quant Trading for a Living – Lessons from a Life in the Trenches" by Andreas...
"Quant Trading for a Living – Lessons from a Life in the Trenches" by Andreas...Quantopian
 
Classification of quantitative trading strategies webinar ppt
Classification of quantitative trading strategies webinar pptClassification of quantitative trading strategies webinar ppt
Classification of quantitative trading strategies webinar pptQuantInsti
 
"Don't Lose Your Shirt Trading Mean-Reversion" by Edith Mandel, Principal at ...
"Don't Lose Your Shirt Trading Mean-Reversion" by Edith Mandel, Principal at ..."Don't Lose Your Shirt Trading Mean-Reversion" by Edith Mandel, Principal at ...
"Don't Lose Your Shirt Trading Mean-Reversion" by Edith Mandel, Principal at ...Quantopian
 
Mean Reversion Trading System: Practical Methods for Swing Trading
Mean Reversion Trading System: Practical Methods for Swing TradingMean Reversion Trading System: Practical Methods for Swing Trading
Mean Reversion Trading System: Practical Methods for Swing Tradingsiyunoyip
 
Pairs Trading
Pairs TradingPairs Trading
Pairs Tradingnattyvirk
 
Dual Momentum Investing by Gary Antonacci QuantCon 2016
Dual Momentum Investing by Gary Antonacci QuantCon 2016Dual Momentum Investing by Gary Antonacci QuantCon 2016
Dual Momentum Investing by Gary Antonacci QuantCon 2016Quantopian
 
Peculiarities of Volatilities by Ernest Chan at QuantCon 2016
Peculiarities of Volatilities by Ernest Chan at QuantCon 2016Peculiarities of Volatilities by Ernest Chan at QuantCon 2016
Peculiarities of Volatilities by Ernest Chan at QuantCon 2016Quantopian
 
Statistics - The Missing Link Between Technical Analysis and Algorithmic Trad...
Statistics - The Missing Link Between Technical Analysis and Algorithmic Trad...Statistics - The Missing Link Between Technical Analysis and Algorithmic Trad...
Statistics - The Missing Link Between Technical Analysis and Algorithmic Trad...Quantopian
 
Market Timing, Big Data, and Machine Learning by Xiao Qiao at QuantCon 2016
Market Timing, Big Data, and Machine Learning by Xiao Qiao at QuantCon 2016Market Timing, Big Data, and Machine Learning by Xiao Qiao at QuantCon 2016
Market Timing, Big Data, and Machine Learning by Xiao Qiao at QuantCon 2016Quantopian
 
"Deep Q-Learning for Trading" by Dr. Tucker Balch, Professor of Interactive C...
"Deep Q-Learning for Trading" by Dr. Tucker Balch, Professor of Interactive C..."Deep Q-Learning for Trading" by Dr. Tucker Balch, Professor of Interactive C...
"Deep Q-Learning for Trading" by Dr. Tucker Balch, Professor of Interactive C...Quantopian
 

Mais procurados (20)

What we learned from running a quant crypto hedge fund
What we learned from running a quant crypto hedge fundWhat we learned from running a quant crypto hedge fund
What we learned from running a quant crypto hedge fund
 
"Fundamental Forecasts: Methods and Timing" by Vinesh Jha, CEO of ExtractAlpha
"Fundamental Forecasts: Methods and Timing" by Vinesh Jha, CEO of ExtractAlpha"Fundamental Forecasts: Methods and Timing" by Vinesh Jha, CEO of ExtractAlpha
"Fundamental Forecasts: Methods and Timing" by Vinesh Jha, CEO of ExtractAlpha
 
Intra-Day De Mark Plus Order Flow Indicator by Dr. Christopher Ting, SMU
  Intra-Day De Mark Plus Order Flow Indicator by Dr. Christopher Ting, SMU  Intra-Day De Mark Plus Order Flow Indicator by Dr. Christopher Ting, SMU
Intra-Day De Mark Plus Order Flow Indicator by Dr. Christopher Ting, SMU
 
"Enhancing Statistical Significance of Backtests" by Dr. Ernest Chan, Managin...
"Enhancing Statistical Significance of Backtests" by Dr. Ernest Chan, Managin..."Enhancing Statistical Significance of Backtests" by Dr. Ernest Chan, Managin...
"Enhancing Statistical Significance of Backtests" by Dr. Ernest Chan, Managin...
 
"Quantitative Trading as a Mathematical Science" by Dr. Haksun Li, Founder an...
"Quantitative Trading as a Mathematical Science" by Dr. Haksun Li, Founder an..."Quantitative Trading as a Mathematical Science" by Dr. Haksun Li, Founder an...
"Quantitative Trading as a Mathematical Science" by Dr. Haksun Li, Founder an...
 
QuantConnect - Options Backtesting
QuantConnect - Options BacktestingQuantConnect - Options Backtesting
QuantConnect - Options Backtesting
 
Pairs Trading: Optimizing via Mixed Copula versus Distance Method for S&P 5...
	 Pairs Trading: Optimizing via Mixed Copula versus Distance Method for S&P 5...	 Pairs Trading: Optimizing via Mixed Copula versus Distance Method for S&P 5...
Pairs Trading: Optimizing via Mixed Copula versus Distance Method for S&P 5...
 
Volatility Trading - Hedge Fund Strategies
Volatility Trading - Hedge Fund StrategiesVolatility Trading - Hedge Fund Strategies
Volatility Trading - Hedge Fund Strategies
 
"Quant Trading for a Living – Lessons from a Life in the Trenches" by Andreas...
"Quant Trading for a Living – Lessons from a Life in the Trenches" by Andreas..."Quant Trading for a Living – Lessons from a Life in the Trenches" by Andreas...
"Quant Trading for a Living – Lessons from a Life in the Trenches" by Andreas...
 
Classification of quantitative trading strategies webinar ppt
Classification of quantitative trading strategies webinar pptClassification of quantitative trading strategies webinar ppt
Classification of quantitative trading strategies webinar ppt
 
"Don't Lose Your Shirt Trading Mean-Reversion" by Edith Mandel, Principal at ...
"Don't Lose Your Shirt Trading Mean-Reversion" by Edith Mandel, Principal at ..."Don't Lose Your Shirt Trading Mean-Reversion" by Edith Mandel, Principal at ...
"Don't Lose Your Shirt Trading Mean-Reversion" by Edith Mandel, Principal at ...
 
Mean Reversion Trading System: Practical Methods for Swing Trading
Mean Reversion Trading System: Practical Methods for Swing TradingMean Reversion Trading System: Practical Methods for Swing Trading
Mean Reversion Trading System: Practical Methods for Swing Trading
 
Statistical arbitrage
Statistical arbitrageStatistical arbitrage
Statistical arbitrage
 
Pairs Trading
Pairs TradingPairs Trading
Pairs Trading
 
Dual Momentum Investing by Gary Antonacci QuantCon 2016
Dual Momentum Investing by Gary Antonacci QuantCon 2016Dual Momentum Investing by Gary Antonacci QuantCon 2016
Dual Momentum Investing by Gary Antonacci QuantCon 2016
 
Peculiarities of Volatilities by Ernest Chan at QuantCon 2016
Peculiarities of Volatilities by Ernest Chan at QuantCon 2016Peculiarities of Volatilities by Ernest Chan at QuantCon 2016
Peculiarities of Volatilities by Ernest Chan at QuantCon 2016
 
The Technical Analysis Guidebook
The Technical Analysis GuidebookThe Technical Analysis Guidebook
The Technical Analysis Guidebook
 
Statistics - The Missing Link Between Technical Analysis and Algorithmic Trad...
Statistics - The Missing Link Between Technical Analysis and Algorithmic Trad...Statistics - The Missing Link Between Technical Analysis and Algorithmic Trad...
Statistics - The Missing Link Between Technical Analysis and Algorithmic Trad...
 
Market Timing, Big Data, and Machine Learning by Xiao Qiao at QuantCon 2016
Market Timing, Big Data, and Machine Learning by Xiao Qiao at QuantCon 2016Market Timing, Big Data, and Machine Learning by Xiao Qiao at QuantCon 2016
Market Timing, Big Data, and Machine Learning by Xiao Qiao at QuantCon 2016
 
"Deep Q-Learning for Trading" by Dr. Tucker Balch, Professor of Interactive C...
"Deep Q-Learning for Trading" by Dr. Tucker Balch, Professor of Interactive C..."Deep Q-Learning for Trading" by Dr. Tucker Balch, Professor of Interactive C...
"Deep Q-Learning for Trading" by Dr. Tucker Balch, Professor of Interactive C...
 

Semelhante a QuantConnect - Introduction to Pairs Trading

QuantConnect ETF Momentum Asset Allocation
QuantConnect ETF Momentum Asset AllocationQuantConnect ETF Momentum Asset Allocation
QuantConnect ETF Momentum Asset AllocationQuantConnect
 
Melbourne Datathon Challenge 2019 (Buy Low Sell High)
Melbourne Datathon Challenge 2019 (Buy Low Sell High)Melbourne Datathon Challenge 2019 (Buy Low Sell High)
Melbourne Datathon Challenge 2019 (Buy Low Sell High)Vishva Abeyrathne
 
Roadblocks for Institutional Adoption of Crypto - Andrew Rollins Shift Money ...
Roadblocks for Institutional Adoption of Crypto - Andrew Rollins Shift Money ...Roadblocks for Institutional Adoption of Crypto - Andrew Rollins Shift Money ...
Roadblocks for Institutional Adoption of Crypto - Andrew Rollins Shift Money ...Andrew Rollins
 
Financial Data Mining and Algo Trading presented at the SAS Data Mining Confe...
Financial Data Mining and Algo Trading presented at the SAS Data Mining Confe...Financial Data Mining and Algo Trading presented at the SAS Data Mining Confe...
Financial Data Mining and Algo Trading presented at the SAS Data Mining Confe...Robert Golan
 
RSDeltabookforthecloud
RSDeltabookforthecloudRSDeltabookforthecloud
RSDeltabookforthecloudBrian Crone
 
Symmedian Technologies NEW 4SYTE.NET Supply Chain Data Virtualization Tool
Symmedian Technologies NEW 4SYTE.NET Supply Chain Data Virtualization ToolSymmedian Technologies NEW 4SYTE.NET Supply Chain Data Virtualization Tool
Symmedian Technologies NEW 4SYTE.NET Supply Chain Data Virtualization ToolBob Hutson
 
Robo advisory-online-fow dw-asia-gs_khooalgo2008
Robo advisory-online-fow dw-asia-gs_khooalgo2008Robo advisory-online-fow dw-asia-gs_khooalgo2008
Robo advisory-online-fow dw-asia-gs_khooalgo2008Guan Khoo
 
Qraft company deck_202003_rf
Qraft company deck_202003_rfQraft company deck_202003_rf
Qraft company deck_202003_rf형식 김
 
Crowdsource Earnings Predictions and the Quantopian Research Platform
Crowdsource Earnings Predictions and the Quantopian Research PlatformCrowdsource Earnings Predictions and the Quantopian Research Platform
Crowdsource Earnings Predictions and the Quantopian Research PlatformQuantopian
 
Unique Value of Digital Assets Part IV Interpolative Value with Appendix
Unique Value of Digital Assets Part IV Interpolative Value with AppendixUnique Value of Digital Assets Part IV Interpolative Value with Appendix
Unique Value of Digital Assets Part IV Interpolative Value with AppendixBrij Consulting, LLC
 
Quantopian: Crowd-sourced Systematic Alpha
Quantopian: Crowd-sourced Systematic AlphaQuantopian: Crowd-sourced Systematic Alpha
Quantopian: Crowd-sourced Systematic AlphaQuantopian
 
Uwe Wystup (MathFinance) on FX Derivatives Innovation
Uwe Wystup (MathFinance) on FX Derivatives InnovationUwe Wystup (MathFinance) on FX Derivatives Innovation
Uwe Wystup (MathFinance) on FX Derivatives InnovationMathFinance AG
 
ClearTH Test Automation Framework: Case Study in IRS & CDS Swaps Lifecycle Mo...
ClearTH Test Automation Framework: Case Study in IRS & CDS Swaps Lifecycle Mo...ClearTH Test Automation Framework: Case Study in IRS & CDS Swaps Lifecycle Mo...
ClearTH Test Automation Framework: Case Study in IRS & CDS Swaps Lifecycle Mo...Iosif Itkin
 
What is Value Stream Management and why do you need it?
What is Value Stream Management and why do you need it?What is Value Stream Management and why do you need it?
What is Value Stream Management and why do you need it?Tasktop
 
Quantlogic Product Presentation
Quantlogic Product PresentationQuantlogic Product Presentation
Quantlogic Product Presentationnscarr
 
The Informative Guide_ White Label Crypto Exchange.pptx
The Informative Guide_ White Label Crypto Exchange.pptxThe Informative Guide_ White Label Crypto Exchange.pptx
The Informative Guide_ White Label Crypto Exchange.pptxMoonTechnolabsPvtLtd
 
Internet Software and Services - Transactions Summary
Internet Software and Services - Transactions SummaryInternet Software and Services - Transactions Summary
Internet Software and Services - Transactions SummaryAlps Venture Partners
 

Semelhante a QuantConnect - Introduction to Pairs Trading (20)

QuantConnect ETF Momentum Asset Allocation
QuantConnect ETF Momentum Asset AllocationQuantConnect ETF Momentum Asset Allocation
QuantConnect ETF Momentum Asset Allocation
 
Melbourne Datathon Challenge 2019 (Buy Low Sell High)
Melbourne Datathon Challenge 2019 (Buy Low Sell High)Melbourne Datathon Challenge 2019 (Buy Low Sell High)
Melbourne Datathon Challenge 2019 (Buy Low Sell High)
 
Roadblocks for Institutional Adoption of Crypto - Andrew Rollins Shift Money ...
Roadblocks for Institutional Adoption of Crypto - Andrew Rollins Shift Money ...Roadblocks for Institutional Adoption of Crypto - Andrew Rollins Shift Money ...
Roadblocks for Institutional Adoption of Crypto - Andrew Rollins Shift Money ...
 
AlgoBit - One Pager
AlgoBit - One PagerAlgoBit - One Pager
AlgoBit - One Pager
 
Financial Data Mining and Algo Trading presented at the SAS Data Mining Confe...
Financial Data Mining and Algo Trading presented at the SAS Data Mining Confe...Financial Data Mining and Algo Trading presented at the SAS Data Mining Confe...
Financial Data Mining and Algo Trading presented at the SAS Data Mining Confe...
 
RSDeltabookforthecloud
RSDeltabookforthecloudRSDeltabookforthecloud
RSDeltabookforthecloud
 
Symmedian Technologies NEW 4SYTE.NET Supply Chain Data Virtualization Tool
Symmedian Technologies NEW 4SYTE.NET Supply Chain Data Virtualization ToolSymmedian Technologies NEW 4SYTE.NET Supply Chain Data Virtualization Tool
Symmedian Technologies NEW 4SYTE.NET Supply Chain Data Virtualization Tool
 
Robo advisory-online-fow dw-asia-gs_khooalgo2008
Robo advisory-online-fow dw-asia-gs_khooalgo2008Robo advisory-online-fow dw-asia-gs_khooalgo2008
Robo advisory-online-fow dw-asia-gs_khooalgo2008
 
Qraft company deck_202003_rf
Qraft company deck_202003_rfQraft company deck_202003_rf
Qraft company deck_202003_rf
 
Crowdsource Earnings Predictions and the Quantopian Research Platform
Crowdsource Earnings Predictions and the Quantopian Research PlatformCrowdsource Earnings Predictions and the Quantopian Research Platform
Crowdsource Earnings Predictions and the Quantopian Research Platform
 
Unique Value of Digital Assets Part IV Interpolative Value with Appendix
Unique Value of Digital Assets Part IV Interpolative Value with AppendixUnique Value of Digital Assets Part IV Interpolative Value with Appendix
Unique Value of Digital Assets Part IV Interpolative Value with Appendix
 
Adaptix_2013
Adaptix_2013Adaptix_2013
Adaptix_2013
 
Quantopian: Crowd-sourced Systematic Alpha
Quantopian: Crowd-sourced Systematic AlphaQuantopian: Crowd-sourced Systematic Alpha
Quantopian: Crowd-sourced Systematic Alpha
 
Uwe Wystup (MathFinance) on FX Derivatives Innovation
Uwe Wystup (MathFinance) on FX Derivatives InnovationUwe Wystup (MathFinance) on FX Derivatives Innovation
Uwe Wystup (MathFinance) on FX Derivatives Innovation
 
ClearTH Test Automation Framework: Case Study in IRS & CDS Swaps Lifecycle Mo...
ClearTH Test Automation Framework: Case Study in IRS & CDS Swaps Lifecycle Mo...ClearTH Test Automation Framework: Case Study in IRS & CDS Swaps Lifecycle Mo...
ClearTH Test Automation Framework: Case Study in IRS & CDS Swaps Lifecycle Mo...
 
What is Value Stream Management and why do you need it?
What is Value Stream Management and why do you need it?What is Value Stream Management and why do you need it?
What is Value Stream Management and why do you need it?
 
Quantlogic Product Presentation
Quantlogic Product PresentationQuantlogic Product Presentation
Quantlogic Product Presentation
 
資産運用とビッグデータ解析_2
資産運用とビッグデータ解析_2資産運用とビッグデータ解析_2
資産運用とビッグデータ解析_2
 
The Informative Guide_ White Label Crypto Exchange.pptx
The Informative Guide_ White Label Crypto Exchange.pptxThe Informative Guide_ White Label Crypto Exchange.pptx
The Informative Guide_ White Label Crypto Exchange.pptx
 
Internet Software and Services - Transactions Summary
Internet Software and Services - Transactions SummaryInternet Software and Services - Transactions Summary
Internet Software and Services - Transactions Summary
 

Último

BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxfenichawla
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdfSuman Jyoti
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...roncy bisnoi
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...SUHANI PANDEY
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfJiananWang21
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdfankushspencer015
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college projectTonystark477637
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01KreezheaRecto
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLPVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLManishPatel169454
 

Último (20)

BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLPVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
 

QuantConnect - Introduction to Pairs Trading

  • 1. Pairs Trading in Python Introduction and application of classical pairs trading www.quantconnect.com Jared Broad CEO and Founder
  • 2. Outline ▪ Introduction to QuantConnect ▪ General Idea of Pairs Trading ▪ Implementing the Model ▪ Testing and Researching ▪ Weaknesses of Pairs Trading ▪ Summary February-2018 QuantConnect – Pairs Trading with Python Page 2
  • 3. What is QuantConnect? We empower investors with powerful investment tools and connect the brightest minds from around the world with capital they need. February-2018 QuantConnect – Pairs Trading with Python Page 3
  • 4. What is QuantConnect? QuantConnect is a community of 50,000 Engineers, Data Scientists, Programmers From 6,100 Cities and 173 Countries February-2018 QuantConnect – Pairs Trading with Python Page 4
  • 5. Building Thousands of Algorithms Every Day February-2018 QuantConnect – Pairs Trading with Python Page 5
  • 6. We’ve built a web algorithm lab where thousands of people test their ideas on financial data we provide; for free. LEAN ALGO TECHNOLOGY FINANCIAL DATA POWER COMPUTING How do we do it? EQUITIES OPTIONS FUTURES FOREX CRYPTO February-2018 QuantConnect – Pairs Trading with Python Page 6
  • 7. Pairs Trading – Market Neutral Trading Strategy Pairs trading is a type of statistical arbitrage Basic Idea: 1) Select two stocks which move similarly. 2) Find where the price diverges. 3) Sell the high priced stock and buy the low priced stock. February-2018 QuantConnect – Pairs Trading with Python Page 7
  • 8. February-2018 QuantConnect – Pairs Trading with Python Page 8 The Price Ratio To standardize the prices – we make a Price Ratio. This allows us to compare Stock A and Stock B over time. Price Ratio = Stock A / Stock B If the Ratio changes significantly, it’s a signal to trade. We can measure this change with standard deviation.
  • 9. 0 2 4 6 8 10 12 14 Jan-08 Feb-08 Mar-08 Apr-08 May-08 Jun-08 Jul-08 Aug-08 Price Series of Stock A and B Stock A Stock B Price(B) = 2 * Price(A) + 1 0 2 4 6 8 10 12 14 16 Jan-08 Feb-08 Mar-08 Apr-08 May-08 Jun-08 Jul-08 Aug-08 Price Divergence Stock A Stock B Example Price Divergence February-2018 QuantConnect – Pairs Trading with Python Page 9
  • 10. Basic Idea of Pairs Trading Buy CVX Sell XOM Buy XOM Sell CVX Buy CVX Sell XOM Buy XOM Sell CVX Ratio Upper Threshold Ratio Lower Threshold When assets cross divergence threshold; trigger trade. February-2018 QuantConnect – Pairs Trading with Python Page 10 StandardDeviations
  • 11. Can we apply this idea to trading strategy? To apply this concept; ❖ We model price with the log of stock price. This follows Brownian Motion N(0, ∆𝑡). ❖ This way the difference of the asset prices are cointegrated. i.e. log(pricex) – log(pricey) is “One-Order Cointegrated”. Stationary & Mean Reversion February-2018 QuantConnect – Pairs Trading with Python Page 10 Step 1: Generate the spread of two log price series 𝑆𝑝𝑟𝑒𝑎𝑑 𝑡 = log(𝑌𝑡) − (𝛼 + 𝛽log(𝑋𝑡)) Step 2: Set the range of spread series [lower, upper] If 𝑆𝑝𝑟𝑒𝑎𝑑 𝑡 > 𝑢𝑝𝑝𝑒𝑟 𝑡ℎ𝑟𝑒𝑠ℎ𝑜𝑙𝑑 Buy 𝑋𝑡, Sell 𝑌𝑡 If 𝑆𝑝𝑟𝑒𝑎𝑑 𝑡 < 𝑙𝑜𝑤𝑒𝑟 𝑡ℎ𝑟𝑒𝑠ℎ𝑜𝑙𝑑 Buy 𝑌𝑡, Sell 𝑋𝑡
  • 12. Exploratory Research ❖ Find two likely cointegrated stocks: e.g. XOM, CVX ❖ Estimate spreads between each stock. ❖ Check for stationarity. QuantBook Research February-2018 QuantConnect – Pairs Trading with Python Page 12
  • 13. Pairs Trading Weaknesses ❖ Double the fees. ❖ Capitalize on small price movements. ❖ Risk correlation will break down (e.g. CEO change, new technology) ❖ Execution risk (slippage). February-2018 QuantConnect – Pairs Trading with Python Page 13
  • 14. LEAN Implementation Backtest ❖ Create our Trading Signal. ❖ Run Backtest in QuantConnect. February-2018 QuantConnect – Pairs Trading with Python Page 14
  • 15. Summary ❖ We use cointegration to detect a long term relationship of two stocks. ❖ Changes in that relationship might signal a chance to profit by pairs trading. Next Steps – Defining Trading Rules, Setting Thresholds Total Trades Drawdown Net Profit Sharpe Ratio 270 12.9% 34% 0.555 February-2018 QuantConnect – Pairs Trading with Python Page 15
  • 18. Cointegration and Stationary • Cointegration is a statistical property of a time series(like the stock price series). • Cointegration specifies a co-movement relationship of price – the long term relationship. • The mean and the variance of the series do not vary over time Cointegration Stationary • If two series {𝑋𝑡} and {𝑌𝑡} are not stationary • But their linear combination 𝑌𝑡 = 𝛽𝑋𝑡 − 𝛼 is a stationary process {𝑿 𝒕} and {𝒀 𝒕} are cointegrated How to test if two series are cointegrated? Augmented Dickey-Fuller test February-2018 QuantConnect – Pairs Trading with Python Page 18
  • 19. Our Research Environment February-2018 QuantConnect – Pairs Trading With Python Page 19
  • 20. Coding the Idea, The Algorithm Lab February-2018 QuantConnect – Pairs Trading With Python Page 20
  • 21. Going Live, Deploying to Live Trading February-2018 QuantConnect – Pairs Trading with Python Page 21