Introduction to Portfolio Analysis in Python
Charlotte Werger
Data Scientist
$$
$$
$$
$$
$$
from pypfopt import expected_returns
# Exponentially weighted moving average
mu_ema = expected_returns.ema_historical_return(df,
span=252, frequency=252)
print(mu_ema)
symbol
XOM 0.103030
BBY 0.394629
PFE 0.186058
from pypfopt import risk_models
# Exponentially weighted covariance
Sigma_ew = risk_models.exp_cov(df, span=180, frequency=252)
$ $
$ $
Sigma_semi = risk_models.semicovariance(df,
benchmark=0, frequency=252)
print(Sigma_semi)
XOM BBY MA PFE
XOM 0.018939 0.008505 0.006568 0.004058
BBY 0.008505 0.016797 0.009133 0.004404
MA 0.006568 0.009133 0.018711 0.005373
PFE 0.004058 0.004404 0.005373 0.008349
Introduction to Portfolio Analysis in Python