From c7ffcc68271fac4885a237442597a773af0ea677 Mon Sep 17 00:00:00 2001 From: Jasen Mackie Date: Sat, 27 Apr 2019 20:39:06 +0000 Subject: [PATCH] First draft for adding multivariate support to mcsim() See #91 --- R/mcsim.R | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/R/mcsim.R b/R/mcsim.R index 3f7691fd..5a73b8fa 100644 --- a/R/mcsim.R +++ b/R/mcsim.R @@ -156,8 +156,12 @@ mcsim <- function( Portfolio = NULL } ) # trim out training period defined by 'gap' argument - dailyPL <- dailyPL[gap:nrow(dailyPL), ncol(dailyPL)] - + if(use == 'cash') { # then we need to account for the possibility that the series is multivariate + dailyPL <- dailyPL[gap:nrow(dailyPL), ] + } else { # get dailyPL column from dailyEqPL or dailyTxnPL depending on whether use='equity' or 'txns' + dailyPL <- dailyPL[gap:nrow(dailyPL), ncol(dailyPL)] + } + ##################### confidence interval formulae ########################### CI_lower <- function(samplemean, merr) { #out <- original - bias - merr #based on boot package implementation in norm.ci @@ -192,11 +196,9 @@ mcsim <- function( Portfolio = NULL fnames <- function(x, indices) { Mean <- mean(x) Median <- median(x) - sd <- StdDev(xts(x, index(dailyPL))) # need to use xts for StdDev to work + sd <- sd(x) + # sd <- StdDev(xts(x, index(dailyPL))) # need to use xts for StdDev to work maxdd <- -max(cummax(cumsum(x))-cumsum(x)) - # sharpedata <- xts(ROC(cumsum(x + initEq)),index(dailyPL)) - # sharpedata[is.na(sharpedata)] <- 0 - # sharpe <- SharpeRatio(sharpedata, FUN = "StdDev") sharpe <- Mean/sd # this is a rough version of sharpe using 'cash' mean & stddev as opposed to 'returns' fnames <- c(Mean, Median, sd, maxdd, sharpe) #fnames <- c(Mean)