Python 投资组合分析入门
Charlotte Werger
Data Scientist
$$
$$


最大夏普投资组合:EF 上的最高夏普比率
from pypfopt.efficient_frontier import EfficientFrontier
# 使用 mu 和 S 计算有效前沿
ef = EfficientFrontier(mu, Sigma)
raw_weights = ef.max_sharpe()
# 获取可读权重
cleaned_weights = ef.clean_weights()
{'GOOG': 0.01269,'AAPL': 0.09202,'FB': 0.19856,
'BABA': 0.09642,'AMZN': 0.07158,'GE': 0.02456,...}
# 获取绩效指标
ef.portfolio_performance(verbose=True)
预期年化收益:33.0%
年化波动率:21.7%
夏普比率:1.43
最小波动率投资组合:EF 上的最低风险水平
# 使用 mu 和 S 计算有效前沿
ef = EfficientFrontier(mu, Sigma)
raw_weights = ef.min_volatility()
# 获取可读权重和绩效指标
cleaned_weights = ef.clean_weights()
{'GOOG': 0.05664, 'AAPL': 0.087, 'FB': 0.1591,
'BABA': 0.09784, 'AMZN': 0.06986, 'GE': 0.0123,...}
ef.portfolio_performance(verbose=True)
预期年化收益:17.4%
年化波动率:13.2%
夏普比率:1.28


Python 投资组合分析入门