Portfolio analysis tools

Introduction to Portfolio Analysis in Python

Charlotte Werger

Data Scientist

Professional portfolio analysis tools

Screenshot of professional portfolio management tool

Introduction to Portfolio Analysis in Python

Back-testing your strategy

  • Back-testing: run your strategy on historic data and see how it would have performed
  • Strategy works on historic data: not guaranteed to work well on future data -> changes in markets

Portfolio back-test results plotted against an index

Introduction to Portfolio Analysis in Python

Quantopian's pyfolio tool

$ $

Quantopian logo

$ $ Pyfolio logo

1 Github: https://github.com/quantopian/pyfolio
Introduction to Portfolio Analysis in Python

Performance and risk analysis in Pyfolio

# Install the package
!pip install pyfolio
# Import the package
import pyfolio as pf
# Read the data as a pandas series
returns=pd.Series(pd.read_csv('pf_returns.csv')
returns.index=pd.to_datetime(returns.index)
# Create a tear sheet on returns
pf.create_returns_tear_sheet(returns)
# If you have backtest and live data 
pf.create_returns_tear_sheet(returns, live_start_date='2018-03-01')
Introduction to Portfolio Analysis in Python

Pyfolio's tear sheet

Returns table in Pyfolio tear sheet output

Rolling Sharpe ratio in Pyfolio tear sheet output

Drawdown chart in Pyfolio tear sheet output

Introduction to Portfolio Analysis in Python

Holdings and exposures in Pyfolio

# define our sector mappings
sect_map = {'COST': 'Consumer Goods',
            'INTC': 'Technology', 
            'CERN': 'Healthcare', 
            'GPS': 'Technology',
            'MMM': 'Construction', 
            'DELL': 'Technology', 
            'AMD': 'Technology'}
pf.create_position_tear_sheet(returns, positions, 
                             sector_mappings=sect_map)
Introduction to Portfolio Analysis in Python

Exposure tear sheet results

$$

Top 10 position in Pyfolio tear sheet output

$ $

Sector allocation in Pyfolio tear sheet output

Introduction to Portfolio Analysis in Python

Let's practice!

Introduction to Portfolio Analysis in Python

Preparing Video For Download...