我试图通过在资产参与约束下优化最小方差的投资组合来找到一组套期保值比率。最后,我想优化其他风险度量的资产权重,例如最小CVaR,VaR或最大回报/风险。
我的投资组合包括9个系列。 1种国内资产和4种国际资产,对冲0%货币:
"D_Asset1","F_Asset2","F_Asset3","F_Asset4","F_Asset5"
我还有100%货币对冲的系列:
"H_F_Asset2","H_F_Asset3","H_F_Asset4","H_F_Asset5"
投资组合资产权重的总和应该等于1且只有长期(即没有杠杆/卖空),国内资产的权重将为60%。另一个资产将具有组约束,以便对冲和未对冲资产的总和等于固定目标权重(即我的基准中的权重)。组约束定义为:
("F_Asset2"+"H_F_Asset2") = 0.2 & ("F_Asset2"+"H_F_Asset2") >= 0
("F_Asset3"+"H_F_Asset3") = 0.1 & ("F_Asset3"+"H_F_Asset3") >= 0
("F_Asset4"+"H_F_Asset4") = 0.05 & ("F_Asset4"+"H_F_Asset4") >= 0
("F_Asset5"+"H_F_Asset5") = 0.05 & ("F_Asset5"+"H_F_Asset5") >= 0
因此,我应该能够通过权重优化得出每个资产的套期保值比率,方法是查看每个未对冲/对冲组中优化权重的比例。我试着按如下方式编写代码:
opt_data <- as.timeSeries(Asset_returns[,c"D_Asset1","F_Asset2","F_Asset3","F_Asset4","F_Asset5","H_F_Asset2","H_F_Asset3","H_F_Asset4","H_F_Asset5")])
spec <- portfolioSpec()
setSolver(spec) <- "solveRquadprog"
cons <- c("eqsumW['D_Asset1']=0.6","eqsumW[c('F_Asset2','H_F_Asset2')]=0.2","eqsumW[c('F_Asset3','H_F_Asset3')]=0.1","eqsumW[c('F_Asset4','H_F_Asset4')]=0.05","eqsumW[c('F_Asset5','H_F_Asset5')]=0.05")
portfolioConstraints(list(mu=apply(opt_data,2,function(x) mean(x)),sigma=cov(opt_data)), spec,cons)
minriskPortfolio(list(mu=apply(opt_data,2,function(x) mean(x)),sigma=cov(opt_data),spec,constraints = cons)
这似乎不起作用,因为我的资产总和最终被分配给被套期资产4(0.3809)和5(0.6191),只有另一组资产的固定权重不被尊重...所以我显然做错了什么。下面是运行我的脚本时获得的打印数据以下数据样本。
Title:
MV Minimum Risk Portfolio
Estimator: covEstimator
Solver: solveRquadprog
Optimize: minRisk
Constraints: LongOnly
Portfolio Weights:
D_Asset1 F_Asset2 F_Asset3 F_Asset4 F_Asset5 H_F_Asset2 H_F_Asset3
0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
H_F_Asset4 H_F_Asset5
0.3809 0.6191
Covariance Risk Budgets:
D_Asset1 F_Asset2 F_Asset3 F_Asset4 F_Asset5 H_F_Asset2 H_F_Asset3
0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
H_F_Asset4 H_F_Asset5
0.3809 0.6191
Target Return and Risk:
[1] -0.0052
Description:
Thu Oct 27 13:53:36 2016 by user: 43951663
我的系列如下:
GMT
D_Asset1 F_Asset2 F_Asset3 F_Asset4 F_Asset5 H_F_Asset2 H_F_Asset3 H_F_Asset4 H_F_Asset5
2002-07-05 0.0060728958 -0.013756357 -0.011423593 0.0134417810 -0.0003016946 -0.0009105038 -0.0018985396 0.014808963 -0.003882658
2002-07-12 -0.0897779000 -0.085188382 -0.089815019 -0.0138095353 -0.0762572363 -0.0685047064 -0.0832575916 -0.022109799 -0.047944944
2002-07-19 -0.0943660524 -0.046920616 -0.030421831 -0.0382901308 -0.0624865993 -0.0794080445 -0.0524289818 -0.031577514 -0.041396426
2002-07-26 0.0133063390 -0.057651106 -0.020437497 -0.0728233620 -0.0456981099 0.0064529146 -0.0396719802 -0.054443226 -0.024872592
2002-08-02 0.0112493491 0.009167815 0.016499805 0.0103302726 0.0252948946 0.0143938534 0.0118099642 0.014237543 0.026552984
2002-08-09 0.0802254120 0.067077593 0.057022734 0.0469759343 0.0558895137 0.0513020851 0.0548215098 0.029355000 0.019311812
2002-08-16 0.0121210802 0.004739185 0.002730157 -0.0071254354 -0.0147625074 0.0220800644 -0.0005414763 -0.017939892 -0.013482516
2002-08-23 0.0254279436 0.028461524 0.013045475 0.0007546919 0.0223311149 0.0133616906 0.0279480422 0.005884930 0.008278473
2002-08-30 -0.0478436889 -0.049203575 -0.039813657 -0.0356601715 -0.0256056009 -0.0276201640 -0.0386866322 -0.025089402 -0.004296057
2002-09-06 -0.0320257540 -0.038044390 -0.028008660 -0.0577045132 -0.0281928317 -0.0252990267 -0.0312053440 -0.049959243 -0.021289249
2002-09-13 -0.0005754118 -0.031013743 -0.024805745 -0.0045048220 -0.0035485481 -0.0055489175 -0.0259398560 0.017170857 0.004670684
2002-09-20 -0.0544596063 -0.049806038 -0.037835532 0.0040695629 -0.0467206777 -0.0523013152 -0.0589901499 0.020442551 -0.049443302
2002-09-27 -0.0264640157 0.003081610 0.011115685 0.0119000112 -0.0229705875 -0.0220045767 0.0091850943 0.009544600 -0.014769134
2002-10-04 -0.0350683237 -0.044400596 -0.026363396 -0.0591064104 -0.0404089273 -0.0317751096 -0.0394601664 -0.049204737 -0.028352867
2002-10-11 0.0455968470 0.047623114 0.034835901 -0.0516194024 0.0202454036 0.0435196284 0.0364044803 -0.047211423 0.013827130
2002-10-18 0.0682138514 0.050215807 0.044584318 0.0531850741 0.0789798029 0.0584691831 0.0566157920 0.055481410 0.060939407
2002-10-25 0.0112759198 -0.016565486 -0.019723747 -0.0234843100 0.0107604217 0.0149227748 -0.0177273307 -0.028938189 0.010213889
2002-11-01 -0.0040060015 0.012830724 -0.013284706 0.0043773949 -0.0193135586 0.0053397013 0.0007975884 -0.003459391 -0.015845981
2002-11-08 -0.0235192733 -0.004405182 0.008119140 -0.0033849145 -0.0101840271 -0.0059125661 -0.0036278513 -0.004716045 0.011824785
2002-11-15 0.0227169708 0.027997661 0.013501476 -0.0219131086 0.0096590849 0.0160309555 0.0242988333 -0.022932122 0.014512210
2002-11-22 0.0237869242 0.018522337 0.020965808 0.0062667869 0.0233331986 0.0242851881 0.0316120790 0.026096681 0.019139845
我很乐意使用另一个优化器,只要它在R中并且允许我处理其他风险度量,例如CVaR,VaR等......任何关于如何解决这个问题的想法都会对我和本论坛上的其他人。
答案 0 :(得分:0)
您的代码中存在拼写错误。请查看以下内容?
opt_data <- as.timeSeries(Asset_returns[,c("D_Asset1","F_Asset2","F_Asset3","F_Asset4","F_Asset5","H_F_Asset2","H_F_Asset3","H_F_Asset4","H_F_Asset5")])
Whit上限:
cons <- c("eqsumW['D_Asset1']=0.6","maxsumW[c('F_Asset2','H_F_Asset2')]=0.2","maxsumW[c('F_Asset3','H_F_Asset3')]=0.1","maxsumW[c('F_Asset4','H_F_Asset4')]=0.05","maxsumW[c('F_Asset5','H_F_Asset5')]=0.05")
我得到了:
minriskPortfolio(list(mu=apply(opt_data,2,function(x) mean(x)),sigma=cov(opt_data)),spec,constraints = cons)
Title:
MV Minimum Risk Portfolio
Estimator: covEstimator
Solver: solveRquadprog
Optimize: minRisk
Constraints:
Portfolio Weights:
D_Asset1 F_Asset2 F_Asset3 F_Asset4 F_Asset5 H_F_Asset2 H_F_Asset3
0.6000 0.0308 0.1000 0.0000 0.0000 0.1692 0.0000
H_F_Asset4 H_F_Asset5
0.0500 0.0500
Covariance Risk Budgets:
D_Asset1 F_Asset2 F_Asset3 F_Asset4 F_Asset5 H_F_Asset2 H_F_Asset3
0.6932 0.0283 0.0762 0.0000 0.0000 0.1557 0.0000
H_F_Asset4 H_F_Asset5
0.0172 0.0294
Target Return and Risk:
[1] -0.0043