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

$$
$$

# 定义无风险利率与目标回报为 0
rfr = 0
target_return = 0
# 由价格计算日收益率
apple_returns=pd.DataFrame(apple_price.pct_change())
# 仅选择负收益
negative_returns = apple_returns.loc[apple_returns['AAPL'] < target]
# 计算期望收益与下行收益的标准差
expected_return = apple_returns['AAPL'].mean()
down_stdev = negative_returns.std()
# 计算索提诺比率
sortino_ratio = (expected_return - rfr)/down_stdev
print(sortino_ratio)
0.07887683763760528

# 使用 rolling().max() 计算回报的最大值 roll_max = apple_price.rolling(min_periods=1,window=250).max()# 从滚动最大值计算日回撤 daily_drawdown = apple_price/roll_max - 1.0# 计算最大日回撤 max_daily_drawdown = daily_drawdown.rolling(min_periods=1,window=250).min()# 绘制结果 daily_drawdown.plot() max_daily_drawdown.plot() plt.show()

Python 投资组合分析入门