Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

PyData NYC 2015

2,874 views

Published on

Portfolio and Risk Analytics in Python with pyfolio - On open source library compatible with Zipline and Quantopian.

Published in: Software
  • Be the first to comment

PyData NYC 2015

  1. 1. Portfolio and Risk Analytics in Python with pyfolio PyData NYC 2015 Jessica Stauth VP Quant Strategy Justin Lent, Thomas Weicki PhD, Andrew Campbell #PyData #PyDataNYC 1
  2. 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. #PyData #PyDataNYC 2
  3. 3. The Quant Finance PyData Stack • Source: [Jake VanderPlas: State of the Tools] – (https://www.youtube.com/watch?v=5GlNDD7qbP4)#PyData #PyDataNYC 3
  4. 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 #PyData #PyDataNYC 4
  5. 5. pyfolio • State-of-the-art portfolio and risk analytics http://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 #PyData #PyDataNYC 5
  6. 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 #PyData #PyDataNYC 6
  7. 7. Tearsheets analysis package Visualizations • Daily returns of a stock, or trading strategy • Positions • Transactions • Periods of market stress • Bayesian risk analyses #PyData #PyDataNYC 7
  8. 8. Tearsheet Components #PyData #PyDataNYC 8
  9. 9. #PyData #PyDataNYC 9
  10. 10. #PyData #PyDataNYC 10
  11. 11. #PyData #PyDataNYC 11
  12. 12. #PyData #PyDataNYC 12
  13. 13. Long/Short Exposure over Time #PyData #PyDataNYC 13
  14. 14. Sector Exposure over Time #PyData #PyDataNYC 14
  15. 15. Slippage and Transaction Cost Sensitivity #PyData #PyDataNYC 15
  16. 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 #PyData #PyDataNYC 16
  17. 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. #PyData #PyDataNYC 17
  18. 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. #PyData #PyDataNYC 18
  19. 19. Modeling Trading Strategy Uncertainty with Bayesian Analysis #PyData #PyDataNYC 19
  20. 20. Bayesian analysis – real world example #PyData #PyDataNYC 20 paper trading
  21. 21. Bayesian analysis – real world example #PyData #PyDataNYC 21 !
  22. 22. Bayesian analysis – real world example #PyData #PyDataNYC 22 June2015 Nov2015 Backtest – “in-sample”
  23. 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 #PyData #PyDataNYC 23
  24. 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%2 0wanted • Bugs: https://github.com/quantopian/pyfolio/issues #PyData #PyDataNYC 24
  25. 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 jstauth@quantopian.com @jstauth www.quantopian.com/fund Thank you. Questions? #PyData #PyDataNYC 25

×