首页 > > 详细

辅导留学生 Diversification Ratio 、讲解数据结构、data structure编程讲解

Use the 11 stock return series from HW2 to find the weight vector using the following smart beta
schemes. Use an upper bound weight of 50% for each stock

1. Maximum Diversification Ratio (MDR)

2. Global Minimum Variance (GMV)

3. Maximum Sharpe Ratio (MSR)

You will need to import ‘minimize’ from scipy.optimize. To help you understand how to use an optimizer,
a sample code for the objective function and the optimization for Equal Risk Contribution (ERC) is
provided for you (you need to understand and change the code).
def risk_parity_function(weights, cov):
temp = np.dot(cov,weights) / np.dot(np.dot(weights, cov),weights)**(1/2)
MC = weights[:] * temp[:]
return (sum(((np.dot(np.dot(weights,cov),weights))**(1/2) / len(weights) -MC)**2))

def risk_parity(data, long = 1):
cov = data.cov()
n = cov.shape[0]
weights = np.ones(n) /n
cons = ({'type': 'eq', 'fun': lambda x: 1 - sum(x)})
bnds = [(0,1) for i in weights]
if long == 1:
res = minimize(risk_parity_function, x0 = weights, args = (cov), method = 'SLSQP', constraints = cons,
bounds = bnds, tol = 1e-30)
else:
res = minimize(risk_parity_function, x0 = weights, args = (cov), method = 'SLSQP', constraints = cons,
tol = 1e-30)
return res.x

联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!