Skip to content

Commit

Permalink
update backtest.plot based on xts on R 4.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
xinran1228 committed Jul 10, 2024
1 parent 9400e46 commit c1ea1ae
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions R/backtest.plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,11 @@ backtest.plot <- function(R, log_return = FALSE, plotType='both', colorSet=NULL,
bg=rgb(t(col2rgb("white")), alpha = 200, maxColorValue = 255))

## ylim panel
ylim1 <- c(p$Env$ylim[[2]][1], p$Env$ylim[[2]][2])
ylim2 <- c(p$Env$ylim[[4]][1], p$Env$ylim[[4]][2])
# ylim1 <- c(p$Env$ylim[[2]][1], p$Env$ylim[[2]][2])
# ylim2 <- c(p$Env$ylim[[4]][1], p$Env$ylim[[4]][2])
ylim1 <- p$Env$panels[[1]]$ylim
ylim2 <- p$Env$panels[[2]]$ylim

xy1 <- as.xts(matrix(rep(ylim1, length(x)),ncol=length(ylim1), byrow=TRUE),
order.by=as.Date(x))
xy2 <- as.xts(matrix(rep(ylim2, length(x)),ncol=length(ylim2), byrow=TRUE),
Expand All @@ -102,7 +105,9 @@ backtest.plot <- function(R, log_return = FALSE, plotType='both', colorSet=NULL,
bg=rgb(t(col2rgb("white")), alpha = 200, maxColorValue = 255))

## ylim panel
ylim1 <- c(p$Env$ylim[[2]][1], p$Env$ylim[[2]][2])
# ylim1 <- c(p$Env$ylim[[2]][1], p$Env$ylim[[2]][2])
ylim1 <- p$Env$panels[[1]]$ylim

xy1 <- as.xts(matrix(rep(ylim1, length(x)),ncol=length(ylim1), byrow=TRUE),
order.by=as.Date(x))
p <- xts::addPolygon(xy1, on=-1, col="lightgrey")
Expand All @@ -126,7 +131,9 @@ backtest.plot <- function(R, log_return = FALSE, plotType='both', colorSet=NULL,
bg=rgb(t(col2rgb("white")), alpha = 200, maxColorValue = 255))

## ylim panel
ylim1 <- c(p$Env$ylim[[2]][1], p$Env$ylim[[2]][2])
# ylim1 <- c(p$Env$ylim[[2]][1], p$Env$ylim[[2]][2])
ylim1 <- p$Env$panels[[1]]$ylim

xy1 <- as.xts(matrix(rep(ylim1, length(x)),ncol=length(ylim1), byrow=TRUE),
order.by=as.Date(x))
p <- xts::addPolygon(xy1, on=-1, col="lightgrey") # top panel
Expand Down

0 comments on commit c1ea1ae

Please sign in to comment.