我有6个证券的买入和卖出信号的时间序列。我试图解决投资组合权重,这将使信号强度最大化,目标波动率为15%。
投资组合具有以下限制。长度低于175%,短于75%,持仓量必须在无杠杆投资组合的100%至-100%之间。
我能够找到最大化信号强度的求解器,但我无法弄清楚如何使用资产回报流的协方差矩阵来添加目标波动率约束。下面是设置,信号是买卖信号对象的框架。 df
是返回流的数据框。
library(quadprog)
library(PerformanceAnalytics)
library(quantmod)
library(PortfolioAnalytics)
signals <- structure(list( SPY = c(0, -0.5, -0.5, -0.5, -0.5, -1, -1),
FXY = c(0.5, 0.5, 0.5, 0.5, 0.5, 1, 1),
FXE = c(-1, -1, -1, -1, -1, -1, -1 ),
GLD = c(-0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5),
JJC = c(-1, -1, -1, -1, -1, -1, -1),
TLT = c(0.5, 0.5, 0.5, 1, 1, 1, 1)
),
.Names = c("SPY", "FXY", "FXE", "GLD", "JJC", "TLT"),
row.names = c("2016-01-08", "2016-01-11", "2016-01-12", "2016-01-13", "2016-01-14", "2016-01-15", "2016-01-19"),
class = "data.frame"
)
#list of ETF symbols representing (snp, jpy, euro, gold, copper, long treasury)
symbollist <- c("SPY", "FXY", "FXE", "GLD", "JJC", "TLT")
#call symbols dating back from 2010
getSymbols(symbollist, from="2015-01-01")
#bind column function
badj <- function(x){
merge(
dailyReturn(x)
)
}
tickers <- list(SPY, FXY, FXE, GLD, JJC, TLT)
sigma <- cov(df)
df <- as.data.frame(lapply(tickers, badj))
colnames(df) <- symbollist
sigma <- cov(df)
以下是我目前在优化方面的成就
#create portfolio object
port <- portfolio.spec( assets = symbollist )
#add constraints
port <- add.constraint( portfolio = port,
type = "box",
min = c(-1),
max = c(1)
)
port <- add.constraint( portfolio = port,
type = "weight_sum",
min_sum = -.75,
max_sum = 1.75
)
#add objective
port <- add.objective( portfolio = port,
type = "return",
name = "mean"
)
#optimize
max_port <- optimize.portfolio( signals[nrow(signals),]
portfolio = port,
optimize_method = "ROI",
trace = TRUE
)
print(max_port)
我怀疑这是一个相对简单的解决方案,只是找出正确的优化器或机制使用但我真的卡住了,感谢您提供的任何指导!