Introduction to Portfolio Analysis in Python
Charlotte Werger
Data Scientist
$ $
$ $
# 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')
# 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