fPortfolio:运行LPM优化时出错
当我运行fPortfolio:运行LPM优化时出错,r,optimization,portfolio,R,Optimization,Portfolio,当我运行meanLPM优化时,我得到以下错误: match.fun中的错误(spec@model$param$tau): 'spec@model$param$tau'不是函数、字符或符号 我已经将估计器设置为lpmEstimator,并键入LPM。有人知道我如何解决这个问题吗?正如您在getAnywhere(“lpmEstimator”)中所看到的,有必要为用于获取估计值的fAssets::assetsLPM指定参数 这在这里起作用: lppData <- 100*LPP2005.RE
mean
LPM优化时,我得到以下错误:
match.fun中的错误(spec@model$param$tau):
'spec@model$param$tau'不是函数、字符或符号
我已经将估计器设置为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"
谢谢你的回答。什么是colMeans?它包含什么?我知道tau是什么,它是投资者在LPM优化中想要的最小可接受回报率。我想将其设置为4%,或0.04。我该怎么做?如果我设置spec@model$param$tau请参见?colMeans。它计算
数据的平均值。frame,在本例中,将其用作
tau。对于您自己的
tau`请参见编辑。很抱歉再次打扰您,但它仍然不起作用。我有一个对象X,有11列,第一列日期,2:11是股票。47排。当然,我使用as.timeSeries(X)。你如何定义tau呢?如果我定义tau来模拟这个对象的大小,我会得到以下错误:eval中的错误(调用,parent.frame()):dims[product 470]与对象的长度不匹配[22090]
在传递data.frame(x[,2:11])时忽略date
列
mtau=function(x)rep(0.04,ncol(x))
spec@model$param$tau=mtau #the target return.