OvermanZarathustra
OvermanZarathustra

Reputation: 99

fPortfolio: Error when running LPM optimization

When I run a mean LPM optimization I get the following error:

Error in match.fun(spec@model$param$tau) : 'spec@model$param$tau' is not a function, character or symbol

I have already set the estimator to lpmEstimator and type to LPM. Anyone know how I can fix this?

Upvotes: 1

Views: 140

Answers (1)

Robert
Robert

Reputation: 5152

As you can see in getAnywhere("lpmEstimator") it is necessary to specify parameters for fAssets::assetsLPM that is used to get the estimations.

This works here:

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" 

EDIT

If you want your own tau you will need a function that assign it to each asset (so depends on your data). In this case one way would be doing:

mtau=function(x)rep(0.04,ncol(x))
spec@model$param$tau=mtau #the target return.

Upvotes: 1

Related Questions