Python and Finance DATACAMP Chapter 2
Python and Finance DATACAMP Chapter 2
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
Comparing returns
1. Annual Return: Total return earned over a period
of one calendar year
N in years:
rate = (1 + Return)1/N − 1
N in months:
rate = (1 + Return)12/N − 1
Convert any time length to an annual rate:
date
2015-01-06 105.05
Name: AAPL, dtype: float64
apple_price.tail(1)
date
2018-03-29 99.75
Name: AAPL, dtype: float64
print (total_return)
0.5397420653068692
0.14602501482708763
date
2017-12-27 170.60
2017-12-28 171.08
2017-12-29 169.23
Name: AAPL, dtype: float64
print (annualized_return)
0.1567672968419047
Charlotte Werger
Data Scientist
Choose a portfolio
Portfolio 1 Portfolio 2
Where: Rp is the portfolio return, Rf is the risk free rate and σp is the portfolio standard deviation
0.2286248397870068
0.6419569149994251
Portfolio 1 Portfolio 2
Charlotte Werger
Data Scientist
In a perfect world returns are distributed normally
1 Source: “An Introduction to Omega, Con Keating and William Shadwick, The Finance Development Center, 2002
Rule of thumb:
1 Source: https://brownmath.com/stat/shape.htm
1 Source: Pimco
A distribution with kurtosis <3 is called platykurtic. Tails are shorter and thinner, and central peak
is lower and broader.
A distribution with kurtosis >3 is called leptokurtic: Tails are longer and fatter, and central peak is
higher and sharper (fat tailed)
1 Source: https://brownmath.com/stat/shape.htm
date
2015-01-02 NaN
2015-01-05 -0.028172
2015-01-06 0.000094
Name: AAPL, dtype: float64
apple_returns.hist()
mean : 0.0006855391415724799
vol : 0.014459504468360529
skew : -0.012440851735057878
kurt : 3.197244607586669
Charlotte Werger
Data Scientist
Looking at downside risk
A good risk measure should focus on potential losses i.e. downside risk
0.07887683763760528