Portfolio returns

Introduction to Portfolio Analysis in Python

Charlotte Werger

Data Scientist

What are portfolio weights?

  • Weight is the percentage composition of a particular asset in a portfolio
  • All weights together have to sum up to 100%
  • Weights and diversification (few large investments versus many small investments)

Optimal portfolio weights for crypto portfolio

Introduction to Portfolio Analysis in Python

Calculating portfolio weights

$$

  • Calculate by dividing the value of a security by total value of the portfolio
  • Equal weighted portfolio, or market cap weighted portfolio
  • Weights determine your investment strategy, and can be set to optimize risk and expected return

Portfolio weights calculation

Introduction to Portfolio Analysis in Python

Portfolio returns

  • Changes in value over time

  • $ Return_t = \frac{V_t - V_{t-1}}{V_{t-1}} $

Returns of portfolio and S&P500 index

Introduction to Portfolio Analysis in Python

Portfolio returns

$$

  • $ Return_t = \frac{V_t - V_{t-1}}{V_{t-1}} $
  • Historic average returns often used to calculate expected return
  • Warning for confusion: average return, cumulative return, active return, and annualized return
Introduction to Portfolio Analysis in Python

Calculating returns from pricing data

df.head(2)
              AAPL     AMZN      TSLA    
date                    
2018-03-25    13.88    114.74    92.48    
2018-03-26    13.35    109.95    89.79
# Calculate returns over each day
returns = df.pct_change()
returns.head(2)
              AAPL          AMZN        TSLA    
date                
2018-03-25    NaN            NaN        NaN    
2018-03-26    -0.013772    0.030838    0.075705
Introduction to Portfolio Analysis in Python

Calculating returns from pricing data

weights = np.array([0, 0.50, 0.25])
# Calculate average return for each stock
meanDailyReturns = returns.mean()
# Calculate portfolio return 
portReturn = np.sum(meanDailyReturns*weights)
print (portReturn)
0.05752375881537723

Introduction to Portfolio Analysis in Python

Calculating cumulative returns

# Calculate daily portfolio returns
returns['Portfolio']= returns.dot(weights)
# Let's see what it looks like
returns.head(3)

                AAPL        AMZN        TSLA        Portfolio
date                    
2018-03-23    -0.020974    -0.026739    -0.029068   -0.025880
2018-03-26    -0.013772    0.030838     0.075705    0.030902
Introduction to Portfolio Analysis in Python

Calculating cumulative returns

# Compound the percentage returns over time 
daily_cum_ret=(1+returns).cumprod()
# Plot your cumulative return 
daily_cum_ret.Portfolio.plot()

Introduction to Portfolio Analysis in Python

Cumulative return plot

Portfolio cumulative returns graph

Introduction to Portfolio Analysis in Python

Let's practice!

Introduction to Portfolio Analysis in Python

Preparing Video For Download...