knitr::opts_chunk$set(echo = TRUE)
Contents:
0 - Install ahead
1 - Get and transform data
2 - Risk-neutralize simulations
3 - Visualization
ahead
ahead
is released under the BSD Clear license. Here's how to install the R version of the package:
1st method: from R-universe
In R console:
``` r options(repos = c( techtonique = 'https://techtonique.r-universe.dev', CRAN = 'https://cloud.r-project.org'))
install.packages("ahead") ```
2nd method: from Github
In R console:
r
devtools::install_github("Techtonique/ahead")
Or
r
remotes::install_github("Techtonique/ahead")
Using ahead
:
library(ahead)
library(ahead) library(fpp)
data(EuStockMarkets) EuStocks <- ts(EuStockMarkets[1:100, ], start = start(EuStockMarkets), frequency = frequency(EuStockMarkets)) EuStocksLogReturns <- ahead::getreturns(EuStocks, type = "log") print(head(EuStocksLogReturns))
ym <- c(0.03013425, 0.03026776, 0.03040053, 0.03053258, 0.03066390, 0.03079450, 0.03092437) freq <- frequency(EuStocksLogReturns) (start_preds <- tsp(EuStocksLogReturns)[2] + 1 / freq) (ym <- stats::ts(ym, start = start_preds, frequency = frequency(EuStocksLogReturns)))
obj <- ahead::ridge2f(EuStocksLogReturns, h = 7L, type_pi = 'bootstrap', B = 10L, ym = ym)
rowMeans(obj$neutralized_sims$CAC)
print(ym)
rowMeans(obj$neutralized_sims$DAX)
print(ym)
#par(mfrow = c(2, 2)) matplot(EuStocksLogReturns, type = 'l', main = "Historical log-Returns", xlab = "time") plot(ym, main = "fake spot curve", xlab = "time to maturity", ylab = "yield", ylim = c(0.02, 0.04)) matplot(obj$neutralized_sims$DAX, type = 'l', main = "simulations of \n predicted DAX log-returns ('risk-neutral')", ylim = c(0.02, 0.04), ylab = "log-returns") ci <- apply(obj$neutralized_sims$DAX, 1, function(x) t.test(x)$conf.int) plot(rowMeans(obj$neutralized_sims$DAX), type = 'l', main = "average predicted \n DAX log-returns ('risk-neutral')", col = "blue", ylim = c(0.02, 0.04), ylab = "log-returns") lines(ci[1, ], col = "red") lines(ci[2, ], col = "red")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.