Skip to content

Instantly share code, notes, and snippets.

View VermeirJellen's full-sized avatar

Jellen Vermeir VermeirJellen

View GitHub Profile
#################################################################################
############################ GMV Settings #######################################
#################################################################################
gmv.lookback=120
gmv.maxWeight=0.3
gmv.longOnly=FALSE
gmv.estimator="CovClassic"
#################################################################################
############################ GMV BACKTEST SPDR ##################################
#################################################################################
#################################################################################
############################ GMV Settings #######################################
#################################################################################
gmv.lookback=120
gmv.maxWeight=0.3
gmv.longOnly=FALSE
gmv.estimator="CovClassic"
#################################################################################
############################ GMV BACKTEST SPDR ##################################
#################################################################################
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]),
############################################################################
### 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")
solve.QP
## 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)