Python and Finance DATACAMP Chapter 1
Python and Finance DATACAMP Chapter 1
Portfolio Analysis!
I N T R O D U C T I O N TO P O R T F O L I O A N A LY S I S I N P Y T H O N
Charlotte Werger
Data Scientist
Hi! My name is Charlotte
Fund: a pool of investments that is managed by a professional fund manager. Individual investors
buy "units" of the fund and the manager invests the money
Index: A smaller sample of the market that is representative of the whole, e.g. S&P500, Nasdaq,
Russell 2000, MSCI World Index
Charlotte Werger
Data Scientist
What are portfolio weights?
Weight is the percentage composition of a particular asset in a portfolio
Weights and diversi cation (few large investments versus many small investments)
Weights determine your investment strategy, and can be set to optimize risk and expected return
Vt −Vt−1
Returnt = Vt−1
Warning for confusion: average return, cumulative return, active return, and annualized return
returns.head(2)
AAPL AMZN TSLA
date
2018-03-25 NaN NaN NaN
2018-03-26 -0.013772 0.030838 0.075705
0.05752375881537723
Charlotte Werger
Data Scientist
Risk of a portfolio
Investing is risky: individual assets will go up or down
Returns spread around the mean is measured by the variance σ 2 and is a common measure of
volatility
N
2
∑ (X −μ)
σ2 = i=1
N
The correlation between asset 1 and 2 is denoted by ρ1,2 , and tells us to which extend assets
move together
The portfolio variance takes into account the individual assets' variances (σ12 , σ22 , etc), the
weights of the assets in the portfolio (w1 , w2 ), as well as their correlation to each other
The standard deviation (σ ) is equal to the square root of variance (σ 2 ), both are a measure of
volatility
This can be re-written in matrix notation, which you can use more easily in code:
In words, what we need to calculate in python is: Portfolio variance = Weights transposed x
(Covariance matrix x Weights)
AAPL FB GE GM WMT
AAPL 0.053569 0.026822 0.013466 0.018119 0.010798
FB 0.026822 0.062351 0.015298 0.017250 0.008765
GE 0.013466 0.015298 0.045987 0.021315 0.009513
GM 0.018119 0.017250 0.021315 0.058651 0.011894
WMT 0.010798 0.008765 0.009513 0.011894 0.041520
0.022742232726360567
2.3%