Machine Learning for Trading--1-7 Sharpe Ratio and Other Portfolio Statistics

  • 计算每日Portfolio的资产价值–Get the Daily Total Value of the Portfolio
  • 累积回报率,日均回报率,日回报率方差
  • 夏普比例–Sharpe Ratio

计算每日Portfolio的资产价值–Get the Daily Total Value of the Portfolio

  • Step 1: 生成一个包含price和dates的DataFrame
  • Step 2: Price 以第一行为基准进行归一化处理,得到Normalized Price
    • normed = prices/prices[0]
  • Step 3: 乘以配置比例
    • alloced = normed * allocs
  • Step 4: 计算每日价格 position value
    • pos_vals = alloced * start_val
  • Step 5: 计算每日Portfolio的资产价值
    • port_val = pos_vals.sum(axis=1)

累积回报率,日均回报率,日回报率方差

  • Cumulative Return Rates: cum_ret = (port_val[-1]/port_val[0] - 1)
  • Average Daily Return Rates: avg_daily_ret = daily_rets.mean()
  • Standard Deviation of Daily Return: std_daily_ret = daily_rets.std()

夏普比例–Sharpe Ratio

  • Sharpe Ratio (SR) – 它反映了单位风险基金净值增长率超过无风险收益率的程度
  • SR = E[Ra - Rb]/Sigma_a – E:期望值, Ra:投资回报率, Rb:无风险投资的回报率, Sigma_a:额外投资收益回报率方差
  • 对于基于日、周、月的采样数据,计算annual sharpe ratio需要乘以一个修正值
    • Daily: sqrt(256)
    • Weekly: sqrt(52)
    • Monthly: sqrt(12)
  • SR = sqrt(k) * mean(daily_rets - daily_rf) / std(daily_rets)
您的支持将鼓励我继续创作