library(tidyverse)
library(purrr)
monte_carlo_paths <- function(days=250,mean=1.001,sd=0.005,S0=40,number_of_possible_futures=1000){
monte_carlo_sim_fun = function(rep_id_val){
monte_carlo_one_path= 1:days %>%
as_tibble() %>%
rename(t = value) %>%
mutate(
changes = rnorm(n(),mean=mean,sd=sd), # normal distribution with typical mean change of daily financial returns of of 1.001 and sd of 0.005
sample_path= cumprod(c(S0,changes[-1])), # cumulative product of changes with an inital price of S0
rep_id = rep_id_val)
}
monte_carlo_sims = 1:number_of_possible_futures %>%
map_dfr(monte_carlo_sim_fun) %>%
rename(possible_path_no=rep_id)
return(monte_carlo_sims)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.