Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting target risk in R package fPortfolio

I am trying to optimize a portfolio according to a specific level of risk. It seems straightforward to use fPortfolio, but the results I am getting do not make sense. I have spent hours trying to figure this out without any luck.

Base Case (i.e., not constraints)

defaultSpec <- portfolioSpec()
lppAssets <- 100*LPP2005.RET[, c("SBI", "SPI", "LMI", "MPI")]
lppData <- portfolioData(data = lppAssets, spec = defaultSpec)
port <- efficientPortfolio(lppData, defaultSpec, constraints = "LongOnly")
port@portfolio

# $weights
#         SBI         SPI         LMI         MPI 
# 0.396009510 0.002142136 0.547715368 0.054132986 

# $covRiskBudgets
#         SBI         SPI         LMI         MPI 
# 0.396009510 0.002142136 0.547715368 0.054132986 

# $targetReturn
#        mean          mu 
# 0.006422759 0.006422759 

# $targetRisk
#       Cov     Sigma      CVaR       VaR 
# 0.1038206 0.1038206 0.2186926 0.1684104 

# $targetAlpha
# [1] 0.05

# $status
# [1] 0


# Slot "messages":
# list()

When I try to set risk level to 0.09, I get the same answer.

defaultSpec <- portfolioSpec()
setTargetRisk(defaultSpec) <- 0.09 # **this doesn't seem to work**
lppAssets <- 100*LPP2005.RET[, c("SBI", "SPI", "LMI", "MPI")]
lppData <- portfolioData(data = lppAssets, spec = defaultSpec)
port <- efficientPortfolio(lppData, defaultSpec, constraints = "LongOnly")
port@portfolio

# An object of class "fPFOLIOVAL"
# Slot "portfolio":
# $weights
#         SBI         SPI         LMI         MPI 
# 0.396009510 0.002142136 0.547715368 0.054132986 

# $covRiskBudgets
#         SBI         SPI         LMI         MPI 
# 0.396009510 0.002142136 0.547715368 0.054132986 

# $targetReturn
#        mean          mu 
# 0.006422759 0.006422759 

# $targetRisk
#       Cov     Sigma      CVaR       VaR 
# 0.1038206 0.1038206 0.2186926 0.1684104 

# $targetAlpha
# [1] 0.05

# $status
# [1] 0


# Slot "messages":
# list()

The "spec" says that a new level of risk is targeted, but the results do not change. It does not matter if I set risk at 0.09 or 0.12 or any other value.

defaultSpec

# Model List:   
#  Type:                      MV
#  Optimize:                  maxReturn
#  Estimator:                 covEstimator
#  Params:                    alpha = 0.05 a = 1

# Portfolio List:   
#  Portfolio Weights:         NA
#  Target Return:             NA
#  Target Risk:               0.09
#  Risk-Free Rate:            0
#  Number of Frontier Points: 50
#  Status:                    NA

# Optim List:   
#  Solver:                    solveRquadprog
#  Objective:                 portfolioObjective portfolioReturn portfolioRisk
#  Options:                   meq = 2
#  Trace:                     FALSE

What am I doing wrong? How do I set the level of risk using fPortfolio in R?

like image 293
jns Avatar asked Sep 18 '25 15:09

jns


2 Answers

From the help file for fPortfolio, it appears that if you set the risk target, you might need to use maxreturnPortfolio. You might also need to setOptimize(spec) <- 'maxReturn'.

Copied from the help file in R: "Maximum Return Portfolio:

The function maxreturnPortfolio returns the portfolio with the maximal return for a fixed target risk."

like image 65
user3734010 Avatar answered Sep 20 '25 06:09

user3734010


When you use maxreturnPortfolio() in conjunction with permitting Short sales, the optimizer will successfully target the risk level you provide via setTargetRisk and adjust weights accordingly. Also, you don't want to scale the LPP2005.RET by 100.

library(fPortfolio)
defaultSpec <- portfolioSpec()
setTargetRisk(defaultSpec) <- 0.09
setSolver(defaultSpec)= "solveRshortExact" 
lppAssets <- LPP2005.RET[, c("SBI", "SPI", "LMI", "MPI")]
lppData <- portfolioData(data = lppAssets, spec = defaultSpec)
port <- maxreturnPortfolio(lppData, defaultSpec, constraints = "Short")
port@portfolio

You now get a solution with the 0.09 target risk level:

An object of class "fPFOLIOVAL"
Slot "portfolio":
$weights
         SBI          SPI          LMI          MPI 
-43.38872554  10.24063734  34.16040358  -0.01231538 

$covRiskBudgets
          SBI           SPI           LMI           MPI 
 0.2599262930  0.7653635547 -0.0246663061 -0.0006235416 

$targetReturn
      mean         mu 
0.01048478 0.01048478 

$targetRisk
      Cov     Sigma      CVaR       VaR 
0.0900000 0.0900000 0.2048887 0.1397806 

$targetAlpha
[1] 0.05

$status
[1] 0


Slot "messages":
list()
like image 28
Thor Avatar answered Sep 20 '25 07:09

Thor