SlideShare a Scribd company logo
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
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
The Quant Finance PyData Stack
• Source: [Jake VanderPlas: State of the Tools]
– (https://www.youtube.com/watch?v=5GlNDD7qbP4)#PyData #PyDataNYC 3
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
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
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
Tearsheets analysis package
Visualizations
• Daily returns of a stock, or trading strategy
• Positions
• Transactions
• Periods of market stress
• Bayesian risk analyses
#PyData #PyDataNYC 7
Tearsheet Components
#PyData #PyDataNYC 8
#PyData #PyDataNYC 9
#PyData #PyDataNYC 10
#PyData #PyDataNYC 11
#PyData #PyDataNYC 12
Long/Short Exposure over Time
#PyData #PyDataNYC 13
Sector Exposure over Time
#PyData #PyDataNYC 14
Slippage and Transaction Cost Sensitivity
#PyData #PyDataNYC 15
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
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
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
Modeling Trading Strategy Uncertainty with Bayesian Analysis
#PyData #PyDataNYC 19
Bayesian analysis – real world example
#PyData #PyDataNYC 20
paper
trading
Bayesian analysis – real world example
#PyData #PyDataNYC 21
!
Bayesian analysis – real world example
#PyData #PyDataNYC 22
June2015
Nov2015
Backtest – “in-sample”
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
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
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

More Related Content

PPTX
Modeling the Stock Market: Common pitfalls and how to avoid them!
PPTX
Pairs Trading from NYC Algorithmic Trading Meetup November '13
PPTX
DIY Quant Strategies on Quantopian
PDF
Algorithmic trading and Machine Learning by Michael Kearns, Professor of Comp...
PDF
10 Ways Backtests Lie by Tucker Balch
PDF
Turkey or trader? by Jeremiah Lowin, Director of Risk Management at Kokino LLC
PDF
Beware of Low Frequency Data by Ernie Chan, Managing Member, QTS Capital Mana...
PPTX
Stauth common pitfalls_stock_market_modeling_pqtc_fall2018
Modeling the Stock Market: Common pitfalls and how to avoid them!
Pairs Trading from NYC Algorithmic Trading Meetup November '13
DIY Quant Strategies on Quantopian
Algorithmic trading and Machine Learning by Michael Kearns, Professor of Comp...
10 Ways Backtests Lie by Tucker Balch
Turkey or trader? by Jeremiah Lowin, Director of Risk Management at Kokino LLC
Beware of Low Frequency Data by Ernie Chan, Managing Member, QTS Capital Mana...
Stauth common pitfalls_stock_market_modeling_pqtc_fall2018

What's hot (20)

PPTX
The QuantCon Keynote: "Counter Trend Trading – Threat or Complement to Trend ...
PPTX
"A Framework for Developing Trading Models Based on Machine Learning" by Kris...
PDF
Should You Build Your Own Backtester? by Michael Halls-Moore at QuantCon 2016
PPTX
Quantopian is Launching a Crowd-sourced Hedge Fund
PDF
Case Studies in Creating Quant Models from Large Scale Unstructured Text by S...
PDF
A Guided Tour of Machine Learning for Traders by Tucker Balch at QuantCon 2016
PDF
"A Framework-Based Approach to Building Quantitative Trading Systems" by Dr. ...
PPTX
Tearsheet feedback webinar 10.10.18
PDF
"Quantum Hierarchical Risk Parity - A Quantum-Inspired Approach to Portfolio ...
PDF
"Trading Strategies That Are Designed Not Fitted" by Robert Carver, Independe...
PDF
"Quantitative Trading as a Mathematical Science" by Dr. Haksun Li, Founder an...
PPTX
Algorithmic Trading Latest Trends & Developments Lecture By Dr. Lipa Roitman
PDF
Futures Trading Strategies on SGX - India chapter in AFACT in Singapore
PPTX
"Enhancing Statistical Significance of Backtests" by Dr. Ernest Chan, Managin...
PDF
Using Domain Expertise to Improve Text Analysis, Evan Schnidman, Founder and ...
PDF
Risk Management: Maximising Long-Term Growth Presentation
PPTX
"Quant Trading for a Living – Lessons from a Life in the Trenches" by Andreas...
PPTX
"How to Run a Quantitative Trading Business in China with Python" by Xiaoyou ...
PDF
QuantConnect - Options Backtesting
PPTX
Algorithmic Finance Meetup: Starmine Short Interest Talk
The QuantCon Keynote: "Counter Trend Trading – Threat or Complement to Trend ...
"A Framework for Developing Trading Models Based on Machine Learning" by Kris...
Should You Build Your Own Backtester? by Michael Halls-Moore at QuantCon 2016
Quantopian is Launching a Crowd-sourced Hedge Fund
Case Studies in Creating Quant Models from Large Scale Unstructured Text by S...
A Guided Tour of Machine Learning for Traders by Tucker Balch at QuantCon 2016
"A Framework-Based Approach to Building Quantitative Trading Systems" by Dr. ...
Tearsheet feedback webinar 10.10.18
"Quantum Hierarchical Risk Parity - A Quantum-Inspired Approach to Portfolio ...
"Trading Strategies That Are Designed Not Fitted" by Robert Carver, Independe...
"Quantitative Trading as a Mathematical Science" by Dr. Haksun Li, Founder an...
Algorithmic Trading Latest Trends & Developments Lecture By Dr. Lipa Roitman
Futures Trading Strategies on SGX - India chapter in AFACT in Singapore
"Enhancing Statistical Significance of Backtests" by Dr. Ernest Chan, Managin...
Using Domain Expertise to Improve Text Analysis, Evan Schnidman, Founder and ...
Risk Management: Maximising Long-Term Growth Presentation
"Quant Trading for a Living – Lessons from a Life in the Trenches" by Andreas...
"How to Run a Quantitative Trading Business in China with Python" by Xiaoyou ...
QuantConnect - Options Backtesting
Algorithmic Finance Meetup: Starmine Short Interest Talk
Ad

Viewers also liked (13)

PDF
Building a Quantitative Trading Strategy To Beat the S&P500
PPTX
Mean Reversion
PPTX
An introduction to reinforcement learning (rl)
PDF
Introduction to Reinforcement Learning
PDF
Trade Like a Chimp: Unleash Your Inner Primate by Andreas Clenow at QuantCon ...
PDF
Statistics - The Missing Link Between Technical Analysis and Algorithmic Trad...
PPTX
Reinforcement Learning : A Beginners Tutorial
PDF
Dual Momentum Investing by Gary Antonacci QuantCon 2016
PPTX
How to design quant trading strategies using “R”?
PPT
Reinforcement learning
PPTX
Presentation on supervised learning
PPTX
Introduction to Machine Learning
PPTX
Introduction to Machine Learning
Building a Quantitative Trading Strategy To Beat the S&P500
Mean Reversion
An introduction to reinforcement learning (rl)
Introduction to Reinforcement Learning
Trade Like a Chimp: Unleash Your Inner Primate by Andreas Clenow at QuantCon ...
Statistics - The Missing Link Between Technical Analysis and Algorithmic Trad...
Reinforcement Learning : A Beginners Tutorial
Dual Momentum Investing by Gary Antonacci QuantCon 2016
How to design quant trading strategies using “R”?
Reinforcement learning
Presentation on supervised learning
Introduction to Machine Learning
Introduction to Machine Learning
Ad

Similar to PyData NYC 2015 (20)

PDF
Bayesian Portfolio Allocation
PDF
Computational Investing: Presentation to SC Python Meetup
PDF
Python. Finance. Excel. - The Thalesians
PDF
ALGORITHMIC OPTIONS TRADING PYTHON
PPTX
Python ml
PDF
Backtesting And Live Trading With Interactive Brokers Using Python With Dr. H...
PPTX
Basic of python for data analysis
PPTX
Machine learning in finance using python
PDF
Econometrics for python, how to deal with data
PDF
Python in the Financial Industry The universal tool for end-to-end developme...
PDF
Get Started with Quantiacs
PDF
Building interactive apps in Jupyter Notebooks
PDF
Get Started with Quantiacs
PPTX
Certified Python Business Analyst
PDF
PYTHON LIVE TRADING: MASTERING THE ART OF REAL-TIME FINANCIAL MARKET ANALYSIS
PDF
The Rise of Python in Finance,Automating Trading Strategies: _.pdf
PDF
The Rise of Python in Finance ,Harnessing Data with Python.pdf
PPTX
Data Science With Python | Python For Data Science | Python Data Science Cour...
PDF
Deep Quant Finance brochure.pdf for mba student
PDF
Python Advanced Predictive Analytics Kumar Ashish
Bayesian Portfolio Allocation
Computational Investing: Presentation to SC Python Meetup
Python. Finance. Excel. - The Thalesians
ALGORITHMIC OPTIONS TRADING PYTHON
Python ml
Backtesting And Live Trading With Interactive Brokers Using Python With Dr. H...
Basic of python for data analysis
Machine learning in finance using python
Econometrics for python, how to deal with data
Python in the Financial Industry The universal tool for end-to-end developme...
Get Started with Quantiacs
Building interactive apps in Jupyter Notebooks
Get Started with Quantiacs
Certified Python Business Analyst
PYTHON LIVE TRADING: MASTERING THE ART OF REAL-TIME FINANCIAL MARKET ANALYSIS
The Rise of Python in Finance,Automating Trading Strategies: _.pdf
The Rise of Python in Finance ,Harnessing Data with Python.pdf
Data Science With Python | Python For Data Science | Python Data Science Cour...
Deep Quant Finance brochure.pdf for mba student
Python Advanced Predictive Analytics Kumar Ashish

Recently uploaded (20)

PDF
AutoCAD Professional Crack 2025 With License Key
PDF
Complete Guide to Website Development in Malaysia for SMEs
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
Cost to Outsource Software Development in 2025
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
How AI/LLM recommend to you ? GDG meetup 16 Aug by Fariman Guliev
PPTX
assetexplorer- product-overview - presentation
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Tally Prime Crack Download New Version 5.1 [2025] (License Key Free
PPTX
AMADEUS TRAVEL AGENT SOFTWARE | AMADEUS TICKETING SYSTEM
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
CapCut Video Editor 6.8.1 Crack for PC Latest Download (Fully Activated) 2025
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
Digital Systems & Binary Numbers (comprehensive )
PPTX
Weekly report ppt - harsh dattuprasad patel.pptx
PDF
Salesforce Agentforce AI Implementation.pdf
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
AutoCAD Professional Crack 2025 With License Key
Complete Guide to Website Development in Malaysia for SMEs
Odoo Companies in India – Driving Business Transformation.pdf
Cost to Outsource Software Development in 2025
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
How AI/LLM recommend to you ? GDG meetup 16 Aug by Fariman Guliev
assetexplorer- product-overview - presentation
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Tally Prime Crack Download New Version 5.1 [2025] (License Key Free
AMADEUS TRAVEL AGENT SOFTWARE | AMADEUS TICKETING SYSTEM
Reimagine Home Health with the Power of Agentic AI​
Navsoft: AI-Powered Business Solutions & Custom Software Development
Design an Analysis of Algorithms II-SECS-1021-03
CapCut Video Editor 6.8.1 Crack for PC Latest Download (Fully Activated) 2025
Operating system designcfffgfgggggggvggggggggg
Digital Systems & Binary Numbers (comprehensive )
Weekly report ppt - harsh dattuprasad patel.pptx
Salesforce Agentforce AI Implementation.pdf
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency

PyData NYC 2015

  • 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. 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. The Quant Finance PyData Stack • Source: [Jake VanderPlas: State of the Tools] – (https://www.youtube.com/watch?v=5GlNDD7qbP4)#PyData #PyDataNYC 3
  • 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. 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. 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. Tearsheets analysis package Visualizations • Daily returns of a stock, or trading strategy • Positions • Transactions • Periods of market stress • Bayesian risk analyses #PyData #PyDataNYC 7
  • 13. Long/Short Exposure over Time #PyData #PyDataNYC 13
  • 14. Sector Exposure over Time #PyData #PyDataNYC 14
  • 15. Slippage and Transaction Cost Sensitivity #PyData #PyDataNYC 15
  • 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. 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. 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. Modeling Trading Strategy Uncertainty with Bayesian Analysis #PyData #PyDataNYC 19
  • 20. Bayesian analysis – real world example #PyData #PyDataNYC 20 paper trading
  • 21. Bayesian analysis – real world example #PyData #PyDataNYC 21 !
  • 22. Bayesian analysis – real world example #PyData #PyDataNYC 22 June2015 Nov2015 Backtest – “in-sample”
  • 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. 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. 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