Using Pyfolio for Portfolio Analytics and Bayesian Backtest Review
Summary
This tutorial presents pyfolio as a Python toolkit for evaluating trading strategies through return, position, transaction, stress-period, and Bayesian analyses. Its central output is a set of tear sheets combining tables and plots, with lower-level plotting and time-series statistics also available for custom analysis. The examples show how to obtain stock returns, calculate a Sharpe ratio, and connect Zipline backtest results to pyfolio.
A worked example uses the OLMAR online portfolio moving-average reversion method on a basket of equities, projects portfolio weights onto a fully invested, nonnegative simplex, and rebalances according to those weights. It then extracts returns, positions, and trades for a combined report, including slippage and an out-of-sample start date. The tutorial also describes Bayesian comparison of in-sample and forward-test returns using a Student t distribution to account for uncertainty. It provides workflow examples rather than empirical conclusions; the historical data source, software versions, and dated APIs limit direct reuse, and no strategy performance results are stated.
Key ideas
- Pyfolio organizes portfolio evaluation into reports covering returns, holdings, transactions, stress periods, and Bayesian analysis.
- Zipline backtest outputs can be converted into return, position, and transaction series for analysis.
- The OLMAR example adjusts asset weights using relative moving-average deviations and projects them onto a long-only fully invested portfolio.
- The Bayesian example compares in-sample and out-of-sample returns while modeling uncertainty with a Student t distribution.
- The tutorial demonstrates analysis workflows but does not establish that the example strategy is profitable.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.