pydata nyc 2015
TRANSCRIPT
![Page 1: PyData NYC 2015](https://reader036.vdocuments.mx/reader036/viewer/2022062522/588325dc1a28abe2758b62ab/html5/thumbnails/1.jpg)
Portfolio and Risk Analytics in Python with pyfolio
PyData NYC 2015
Jessica StauthVP Quant Strategy
Justin Lent, Thomas Weicki PhD, Andrew Campbell
#PyData #PyDataNYC 1
![Page 2: PyData NYC 2015](https://reader036.vdocuments.mx/reader036/viewer/2022062522/588325dc1a28abe2758b62ab/html5/thumbnails/2.jpg)
#PyData #PyDataNYC 2
Why use Python for Quant Finance?
• Python is a general purpose language
• No hodge-podge of perl, bash, matlab, R, excel fortran.
• Very easy to learn.
![Page 3: PyData NYC 2015](https://reader036.vdocuments.mx/reader036/viewer/2022062522/588325dc1a28abe2758b62ab/html5/thumbnails/3.jpg)
3
The Quant Finance PyData Stack
• Source: [Jake VanderPlas: State of the Tools]– (https://www.youtube.com/watch?v=5GlNDD7qbP4)
#PyData #PyDataNYC
![Page 4: PyData NYC 2015](https://reader036.vdocuments.mx/reader036/viewer/2022062522/588325dc1a28abe2758b62ab/html5/thumbnails/4.jpg)
#PyData #PyDataNYC 4
Python in Quantitative Finance
• When Quantopian started in 2011, we needed a backtester
– Open-sourced Zipline in 2012
• When we started to build a crowd-source hedge fund, we needed a better way to evaluate algorithms
– Open-sourced pyfolio in 2015
![Page 5: PyData NYC 2015](https://reader036.vdocuments.mx/reader036/viewer/2022062522/588325dc1a28abe2758b62ab/html5/thumbnails/5.jpg)
#PyData #PyDataNYC 5
pyfolio
• State-of-the-art portfolio and risk analyticshttp://quantopian.github.io/pyfolio/
• Open source and free: Apache v2 license
• Can be used:– stand alone– with Zipline– on Quantopian in a hosted Research Environment– with PyThalesians
![Page 6: PyData NYC 2015](https://reader036.vdocuments.mx/reader036/viewer/2022062522/588325dc1a28abe2758b62ab/html5/thumbnails/6.jpg)
#PyData #PyDataNYC 6
Using pyfolio stand-alone
• Installation
• Use Anaconda to get a Python system with the full PyData ecosystem. Then:
• pip install pyfolio
• Import it in your project
![Page 7: PyData NYC 2015](https://reader036.vdocuments.mx/reader036/viewer/2022062522/588325dc1a28abe2758b62ab/html5/thumbnails/7.jpg)
#PyData #PyDataNYC 7
Tearsheets analysis packageVisualizations
• Daily returns of a stock, or trading strategy• Positions• Transactions• Periods of market stress• Bayesian risk analyses
![Page 8: PyData NYC 2015](https://reader036.vdocuments.mx/reader036/viewer/2022062522/588325dc1a28abe2758b62ab/html5/thumbnails/8.jpg)
#PyData #PyDataNYC 8
Tearsheet Components
![Page 9: PyData NYC 2015](https://reader036.vdocuments.mx/reader036/viewer/2022062522/588325dc1a28abe2758b62ab/html5/thumbnails/9.jpg)
#PyData #PyDataNYC 9
![Page 10: PyData NYC 2015](https://reader036.vdocuments.mx/reader036/viewer/2022062522/588325dc1a28abe2758b62ab/html5/thumbnails/10.jpg)
#PyData #PyDataNYC 10
![Page 11: PyData NYC 2015](https://reader036.vdocuments.mx/reader036/viewer/2022062522/588325dc1a28abe2758b62ab/html5/thumbnails/11.jpg)
#PyData #PyDataNYC 11
![Page 12: PyData NYC 2015](https://reader036.vdocuments.mx/reader036/viewer/2022062522/588325dc1a28abe2758b62ab/html5/thumbnails/12.jpg)
#PyData #PyDataNYC 12
![Page 13: PyData NYC 2015](https://reader036.vdocuments.mx/reader036/viewer/2022062522/588325dc1a28abe2758b62ab/html5/thumbnails/13.jpg)
#PyData #PyDataNYC 13
Long/Short Exposure over Time
![Page 14: PyData NYC 2015](https://reader036.vdocuments.mx/reader036/viewer/2022062522/588325dc1a28abe2758b62ab/html5/thumbnails/14.jpg)
#PyData #PyDataNYC 14
Sector Exposure over Time
![Page 15: PyData NYC 2015](https://reader036.vdocuments.mx/reader036/viewer/2022062522/588325dc1a28abe2758b62ab/html5/thumbnails/15.jpg)
#PyData #PyDataNYC 15
Slippage and Transaction Cost Sensitivity
![Page 16: PyData NYC 2015](https://reader036.vdocuments.mx/reader036/viewer/2022062522/588325dc1a28abe2758b62ab/html5/thumbnails/16.jpg)
#PyData #PyDataNYC 16
Zipline + pyfolio, locally or via quantopian.com
• Zipline: open-source backtester by Quantopian
• Powers quantopian.com– 12 years of stock market data for US Equities (minute-bar
prices, corporate fundamentals, sentiment, events, etc.)– Various models for transaction costs and slippage.– Web based IDE for creating and deploying trading algorithms
• Hosted ipython notebook research server– Ad-hoc data analysis. We provide market data.– Pull in strategy backtest results from the Web IDE and use pyfolio
![Page 17: PyData NYC 2015](https://reader036.vdocuments.mx/reader036/viewer/2022062522/588325dc1a28abe2758b62ab/html5/thumbnails/17.jpg)
#PyData #PyDataNYC 17
Bayesian analysis in pyfolio
• Sneak-peek into ongoing research.
• Can a backtest (in-sample data) be used to predict the future results (out of sample data)?
• Sophisticated statistical modeling takes uncertainty into account.
• Uses T-distribution to model returns (instead of normal).– Addresses ‘fat-tail’ nature of financial returns
• Relies on PyMC3.– Python module for Bayesian statistical modeling and model fitting which
focuses on advanced Markov chain Monte Carlo fitting algorithms.
![Page 18: PyData NYC 2015](https://reader036.vdocuments.mx/reader036/viewer/2022062522/588325dc1a28abe2758b62ab/html5/thumbnails/18.jpg)
#PyData #PyDataNYC 18
Modeling Trading Strategy Uncertainty with Bayesian Analysis
How do I know my trading strategy is “working” after I’ve put real $ into it?
How many Out-of-Sample trading days must be observed for me to be certain?
Calculate: P(mean > 0)(Probability of out-of-sample means > 0%)
Re-compute model as new data is sampled.
![Page 19: PyData NYC 2015](https://reader036.vdocuments.mx/reader036/viewer/2022062522/588325dc1a28abe2758b62ab/html5/thumbnails/19.jpg)
#PyData #PyDataNYC 19
Modeling Trading Strategy Uncertainty with Bayesian Analysis
![Page 20: PyData NYC 2015](https://reader036.vdocuments.mx/reader036/viewer/2022062522/588325dc1a28abe2758b62ab/html5/thumbnails/20.jpg)
#PyData #PyDataNYC 20
Bayesian analysis – real world example
paper trading
![Page 21: PyData NYC 2015](https://reader036.vdocuments.mx/reader036/viewer/2022062522/588325dc1a28abe2758b62ab/html5/thumbnails/21.jpg)
#PyData #PyDataNYC 21
Bayesian analysis – real world example
!
![Page 22: PyData NYC 2015](https://reader036.vdocuments.mx/reader036/viewer/2022062522/588325dc1a28abe2758b62ab/html5/thumbnails/22.jpg)
#PyData #PyDataNYC 22
Bayesian analysis – real world example
June 2015
Nov 2015Backtest – “in-sample”
![Page 23: PyData NYC 2015](https://reader036.vdocuments.mx/reader036/viewer/2022062522/588325dc1a28abe2758b62ab/html5/thumbnails/23.jpg)
#PyData #PyDataNYC 23
More Info on Bayesian Analysis
Accompanying blog post: http://blog.quantopian.com/bayesian-cone/
Bayesian Methods for Hackers: http://camdavidsonpilon.github.io/Probabilistic-Programming-and-Bayesian-Methods-for-Hackers/
PyMC3: http://pymc-devs.github.io/pymc3
![Page 24: PyData NYC 2015](https://reader036.vdocuments.mx/reader036/viewer/2022062522/588325dc1a28abe2758b62ab/html5/thumbnails/24.jpg)
#PyData #PyDataNYC 24
Summary
• Pyfolio bundles various useful analyses and includes advanced statistical modeling.
• “Using pyfolio” webinar tutorial: https://www.youtube.com/watch?v=-VmZAlBWUko
• Still young -- please contribute: https://github.com/quantopian/pyfolio/labels/help%20wanted
• Bugs: https://github.com/quantopian/pyfolio/issues
![Page 25: PyData NYC 2015](https://reader036.vdocuments.mx/reader036/viewer/2022062522/588325dc1a28abe2758b62ab/html5/thumbnails/25.jpg)
#PyData #PyDataNYC 25
Up next right here: Andrew Campbell - Bootstrapping Applications and Dashboards with IPython Widgets
Tomorrow 4:25pm Room A: Scott Sandersen – Developing an Expression Language for Quantitative
Financial Modeling
[email protected]@jstauth
www.quantopian.com/fund
Thank you.Questions?