This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################################################# | |
############################ GMV Settings ####################################### | |
################################################################################# | |
gmv.lookback=120 | |
gmv.maxWeight=0.3 | |
gmv.longOnly=FALSE | |
gmv.estimator="CovClassic" | |
################################################################################# | |
############################ GMV BACKTEST SPDR ################################## | |
################################################################################# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################################################# | |
############################ GMV Settings ####################################### | |
################################################################################# | |
gmv.lookback=120 | |
gmv.maxWeight=0.3 | |
gmv.longOnly=FALSE | |
gmv.estimator="CovClassic" | |
################################################################################# | |
############################ GMV BACKTEST SPDR ################################## | |
################################################################################# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source("config/config.R") | |
SPDR <- readRDS(file="data/SPDR.rds") | |
SPDR.returns <- na.omit((SPDR / lag(SPDR, k= 1) - 1) * 100) | |
########################################################################### | |
############# Plot the underlying SPDR assets ############################# | |
########################################################################### | |
nrAssets <- ncol(SPDR) | |
par(mfrow=c(rep(ceiling(sqrt(nrAssets)),2))) | |
res <- sapply(1:nrAssets, function(x) plot(time(SPDR[,x]), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################################################################ | |
### Perform Global Minimum Variance backtest ##### | |
############################################################################ | |
GMVPortfolioBacktest <- function(returns=NULL, assets=NULL, | |
lookback=120, | |
longOnly=FALSE, | |
covariance.f="CovClassic", | |
max.weight=1, | |
nrCores=detectCores(), | |
plot=TRUE, strategyName="Strategy") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
solve.QP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## gmv optimization | |
## Function uses return timeseries xts-object as input | |
GMVOptimization <- function(returns, covariance.f="CovClassic", longOnly=FALSE, max.weight=1) | |
{ | |
estimation <- do.call(covariance.f, | |
list(x=coredata(returns))) | |
covariance.matrix <- rrcov::getCov(estimation) | |
# The quadratic solver below implements the dual method of Goldfarb and Idnani (1982, 1983) | |
# for solving quadratic programming problems of the form min(-d^T b + 1/2 b^T D b) |