fPortfolio:运行 LPM 优化时出错
fPortfolio: Error when running LPM optimization
当我 运行 a mean
LPM optimization
我得到以下错误:
Error in match.fun(spec@model$param$tau) :
'spec@model$param$tau' is not a function, character or symbol
我已经将估算器设置为 lpmEstimator
并输入 LPM
。有人知道我该如何解决这个问题吗?
正如您在 getAnywhere("lpmEstimator")
中看到的那样,有必要为 fAssets::assetsLPM
指定用于获取估计值的参数。
这在这里有效:
lppData <- 100*LPP2005.RET[,1:6]
spec <- portfolioSpec()
spec@model$type="LPM"
#getAnywhere("lpmEstimator")
#lpmEstimator(lppData)
#fAssets::assetsLPM(lppData,apply(lppData,2,mean),a=2)
getEstimator(spec) #to retrieve the current setting
setEstimator(spec)="lpmEstimator"
spec@model$param$tau= colMeans #the target return.
spec@model$param$a=2
#optimize, without shortselling
frontier3 <- portfolioFrontier(lppData, spec = spec,constraints="LongOnly");
getWeights(frontier3)
frontierPoints(frontier3)
# > frontierPoints(frontier3)
# targetRisk targetReturn
# 1 0.12609343 0.0000406634
# 2 0.11470167 0.0017901986
# 3 0.10794259 0.0035397338
# 4 0.10303948 0.0052892689
# 5 0.10060581 0.0070388041
# 9 0.10151888 0.0140369448
# 10 0.10475357 0.0157864800
# 11 0.10911567 0.0175360152
# 18 0.16347904 0.0297827615
# 19 0.17379682 0.0315322967
# 20 0.18448599 0.0332818318
# 21 0.19548564 0.0350313670
# 22 0.20674621 0.0367809022
# 29 0.29024846 0.0490276485
# 30 0.30260866 0.0507771836
# 31 0.31503911 0.0525267188
# 32 0.32753181 0.0542762540
# 49 0.55299710 0.0840183521
# 50 0.56844009 0.0857678860
# attr(,"control")
# targetRisk targetReturn auto
# "Cov" "mean" "TRUE"
编辑
如果您想要自己的 tau
,您将需要一个将其分配给每个资产的函数(因此取决于您的数据)。在这种情况下,一种方法是:
mtau=function(x)rep(0.04,ncol(x))
spec@model$param$tau=mtau #the target return.
当我 运行 a mean
LPM optimization
我得到以下错误:
Error in match.fun(spec@model$param$tau) : 'spec@model$param$tau' is not a function, character or symbol
我已经将估算器设置为 lpmEstimator
并输入 LPM
。有人知道我该如何解决这个问题吗?
正如您在 getAnywhere("lpmEstimator")
中看到的那样,有必要为 fAssets::assetsLPM
指定用于获取估计值的参数。
这在这里有效:
lppData <- 100*LPP2005.RET[,1:6]
spec <- portfolioSpec()
spec@model$type="LPM"
#getAnywhere("lpmEstimator")
#lpmEstimator(lppData)
#fAssets::assetsLPM(lppData,apply(lppData,2,mean),a=2)
getEstimator(spec) #to retrieve the current setting
setEstimator(spec)="lpmEstimator"
spec@model$param$tau= colMeans #the target return.
spec@model$param$a=2
#optimize, without shortselling
frontier3 <- portfolioFrontier(lppData, spec = spec,constraints="LongOnly");
getWeights(frontier3)
frontierPoints(frontier3)
# > frontierPoints(frontier3)
# targetRisk targetReturn
# 1 0.12609343 0.0000406634
# 2 0.11470167 0.0017901986
# 3 0.10794259 0.0035397338
# 4 0.10303948 0.0052892689
# 5 0.10060581 0.0070388041
# 9 0.10151888 0.0140369448
# 10 0.10475357 0.0157864800
# 11 0.10911567 0.0175360152
# 18 0.16347904 0.0297827615
# 19 0.17379682 0.0315322967
# 20 0.18448599 0.0332818318
# 21 0.19548564 0.0350313670
# 22 0.20674621 0.0367809022
# 29 0.29024846 0.0490276485
# 30 0.30260866 0.0507771836
# 31 0.31503911 0.0525267188
# 32 0.32753181 0.0542762540
# 49 0.55299710 0.0840183521
# 50 0.56844009 0.0857678860
# attr(,"control")
# targetRisk targetReturn auto
# "Cov" "mean" "TRUE"
编辑
如果您想要自己的 tau
,您将需要一个将其分配给每个资产的函数(因此取决于您的数据)。在这种情况下,一种方法是:
mtau=function(x)rep(0.04,ncol(x))
spec@model$param$tau=mtau #the target return.