---
title: "Martingale tests"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Martingale tests}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r fig.width=7.5}
rm(list=ls()) # beware, removes everything in your environment

library(esgtoolkit)

r0 <- 0.03
S0 <- 100

set.seed(10)
eps0 <- esgtoolkit::simshocks(n = 100, horizon = 3, frequency = "quart")
eps_trend <- eps0 + 0.1 * seq_len(nrow(eps0))
sim.GBM <- esgtoolkit::simdiff(n = 100, horizon = 3, frequency = "quart",   
                   model = "GBM", 
                   x0 = S0, theta1 = r0, theta2 = 0.1, 
                   eps = eps0, seed=10001)

sim.GBM_trend <- esgtoolkit::simdiff(n = 100, horizon = 3, frequency = "quart",   
                   model = "GBM", 
                   x0 = S0, theta1 = r0, theta2 = 0.1, 
                   eps = eps_trend, seed=10001)

(test1 <- esgtoolkit::esgmartingaletest(r = r0, X = sim.GBM, p0 = S0, 
                            alpha = 0.05, method = "trend"))

(test2 <- esgtoolkit::esgmartingaletest(r = r0, X = sim.GBM_trend, p0 = S0, 
                            alpha = 0.05, method = "trend"))

(test1_ratio <- esgtoolkit::esgmartingaletest(r = r0, X = sim.GBM, p0 = S0, 
                            alpha = 0.05, method = "ratio"))

(test2_ratio <- esgtoolkit::esgmartingaletest(r = r0, X = sim.GBM_trend, p0 = S0, 
                            alpha = 0.05, method = "ratio"))

(test3 <- esgtoolkit::esgmartingaletest(r = r0, X = sim.GBM, p0 = S0, 
alpha = 0.05))
esgplotbands(test3) 

(test4 <- esgtoolkit::esgmartingaletest(r = r0, X = sim.GBM_trend, p0 = S0, 
alpha = 0.05))
esgplotbands(test4) 
```

