python3投资组合资产权重

时间:2020-08-10 19:22:17

标签: python-3.x dataframe for-loop finance portfolio

我想创建一个数据框,显示资产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 

0 个答案:

没有答案