我正在尝试根据特定风险级别优化投资组合。使用fPortfolio
似乎很简单,但我得到的结果没有意义。我花了好几个小时试图解决这个问题而没有任何运气。
基本案例(即非约束)
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()
当我尝试将风险等级设置为0.09时,我会得到相同的答案。
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()
“规范”表示会针对新的风险级别,但结果不会改变。如果我将风险设置为0.09或0.12或任何其他值,则无关紧要。
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
我做错了什么?如何使用R中的fPortfolio
设置风险等级?
答案 0 :(得分:1)
从fPortfolio的帮助文件中可以看出,如果设置风险目标,则可能需要使用maxreturnPortfolio。您可能还需要setOptimize(spec)&lt; - 'maxReturn'。
从R中的帮助文件复制: “最高回报投资组合:
函数maxreturnPortfolio返回具有固定目标风险的最大回报的投资组合。“
答案 1 :(得分:1)
当您将maxreturnPortfolio()与允许卖空交易结合使用时,优化程序将成功定位您通过setTargetRisk提供的风险级别并相应地调整权重。此外,您不希望将LPP2005.RET缩放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
您现在可以获得0.09目标风险级别的解决方案:
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()
答案 2 :(得分:1)
我推荐阅读这本书,作者是:fPortfolio book