python3投资组合资产权重

问题描述

我想创建一个数据框,显示资产A和资产B的权重,总和加1。 索引可以命名为权重,列为资产A和资产B。

资产A从0开始,以0.01为增量;最终变成1。

相反,资产B从1开始并将值减少0.01,最终变为0。

E.g.
        ['A','B']
weights   0    1
weights  0.01  0.99
weights  0.02  0.98
weights  0.03  0.97
weights  ...   ...
weights   1      0

在这里,我想通过将所有可能的投资组合收益除以其各自的投资组合标准差(忽略无风险利率)来找到夏普比率最高的位置。我当时在考虑实现for循环或数据帧,但是我不确定从哪里开始。请帮忙!

输入

#sample data values

assets = ['A','B']
mean = [0.25,0.11]
std = [0.05,0.14]
covariance = 0.007
weights = [0.5,0.5]

portfolio_return = weights[0] * mean[0] + weights[1] * mean[1]
print('the portfolio return is: ',portfolio_return,'\n')

portfolio_var = (weights[0]**2 * std[0]**2) + (weights[1]**2 * std[1]**2) + 2*(weights[0]*weights[1]*std[0]*std[1]*covariance)
print('the portfolio variance is: ')
print(portfolio_var,'\n')  

print('the portfolio standard deviation is: ')
portfolio_std = np.sqrt(portfolio_var)
print(portfolio_std,'\n')

输出

the portfolio return is:  0.18 

the portfolio variance is: 
0.005549500000000001 

the portfolio standard deviation is: 
0.07449496627289659 

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...