fportfolio为GMV优化返回零投资组合权重,if(STATUS!= 0){:参数对于相切投资组合的长度为零时出错

时间:2017-07-19 07:12:57

标签: r optimization portfolio

我正在尝试为工作进行投资组合优化。目前正在学习如何在fportfolio包中做到这一点。我跟随这本书:使用R / Rmetrics进行投资组合优化。

以下是全局最小方差优化的代码:

def PostVotes():
    print("PostVotes: Posting the votes onto the forum...")

    driver.find_element_by_xpath("""//*[@id="cke_contents_vB_Editor_QR_editor"]/textarea""").send_keys("Beep Boop, I'm a bot. Vote count was requested.\n")
    driver.find_element_by_xpath("""//*[@id="cke_contents_vB_Editor_QR_editor"]/textarea""").send_keys("\n[b][SIZE=4]Lynch Votes:[/SIZE][/b]\n")
    for user in lynchref:
        if "PLAYERLIST" not in user and user != "":
            driver.find_element_by_xpath("""//*[@id="cke_contents_vB_Editor_QR_editor"]/textarea""").send_keys("[b]",user,"[/b]", " - ", ['{}, '.format(elem) for elem in lynchref[user]], "\n")

    driver.find_element_by_xpath("""//*[@id="cke_contents_vB_Editor_QR_editor"]/textarea""").send_keys("\n[b][SIZE=4]Not Voting:[/SIZE][/b]\n")
    for player in lynchref:
        if player not in lynches and "PLAYERLIST" not in player and player != "":
            driver.find_element_by_xpath("""//*[@id="cke_contents_vB_Editor_QR_editor"]/textarea""").send_keys(player,"\n")

    driver.find_element_by_xpath("""//*[@id="qr_submit"]""").click()

本书的输出如下:

lppData <- 100 * LPP2005.RET[, 1:6]
globminSpec <- portfolioSpec()
globminPortfolio <- minvariancePortfolio(data = lppData,spec = globminSpec,constraints = "LongOnly")
print(globminPortfolio) 

但是,我的输出是:

Title:
MV Minimum Variance Portfolio
Estimator:  covEstimator
Solver:     solveRquadprog
Optimize:   minRisk
Constraints: LongOnly
Portfolio Weights:
SBI SPI SII LMI MPI ALT
0.3554 0.0000 0.0891 0.4894 0.0025 0.0636
Covariance Risk Budgets:
SBI SPI SII LMI MPI ALT
0.3553 0.0000 0.0891 0.4893 0.0025 0.0637
Target Return and Risks:
mean mu Cov Sigma CVaR VaR
0.0105 0.0105 0.0986 0.0986 0.2020 0.1558
Description:
Mon May 4 13:44:58 2009 by user: Rmetrics

对于相切投资组合,本书的代码是:

Title:
 MV Minimum Variance Portfolio 
 Estimator:         covEstimator 
 Solver:            solveRquadprog 
 Optimize:          minRisk 
 Constraints:       LongOnly 


  Portfolio Weights:
SBI SPI SII LMI MPI ALT 
  0   0   0   0   0   0 

Covariance Risk Budgets:
SBI SPI SII LMI MPI ALT 


Target Returns and Risks:
mean  Cov CVaR  VaR 
   0    0    0    0 

Description:
 Wed Jul 19 14:06:22 2017 by user: tmpj81 

它产生了这个错误:

 tgSpec <- portfolioSpec()
    setRiskFreeRate(tgSpec) <- 0
    tgPortfolio <- tangencyPortfolio(  data = lppData,  spec = tgSpec,  
    constraints = "LongOnly")
    print(tgPortfolio)

我正在完全遵循说明书,并且我使用包中提供的数据和我自己的数据产生了这些错误。

有谁知道我怎么处理这个?我还注意到,在本书的GMV输出中,有平均值,mu,cov,sigma,cvar,var,而在我的中只有mean,cov,cvar,var。

0 个答案:

没有答案