Log-Return simulation in R does not lead to expected result -
i'm trying simulate log-returns in r , calculate expected p&l simple investment. code working, have problem in understanding why expected profit not equal to:
(exp(annual_mean * (holding_period/253)) * investment) - investment
which equals 5350 in example. however, running following simulation results profit of around 5580:
investment <- 1000000 holding_period <- 45 annual_mean <- 0.03 annual_sd <- 0.05 simulations <- 1000000 # create matrix log-returns paths <- matrix(data = na, nrow = holding_period, ncol = simulations); # feed matrix log-returns (k in 1:simulations) { returns <- rnorm(holding_period, mean = annual_mean/253, sd = annual_sd/sqrt(253)); paths[, k] <- investment * exp(cumsum(returns)); } # calculate epnl epnl <- mean(paths[holding_period, ] - investment); print(epnl)
considering high number of simulations wouldn't expect such big deviation expected profit. tried higher number of simulations result still same.
i'm trying show simulation higher number of simulations closer actual value gets expected value.
i hope guys understand question. know more finance related topic guess there misinterpretation in code side.
thanks lot!
i believe issue use of cumsum
- treating returns if rates add rather multiply/compound. if alter code , use cumprod
instead, seems give right result...
# feed matrix log-returns (k in 1:simulations) { returns <- rnorm(holding_period, mean = annual_mean/253, sd = annual_sd/sqrt(253)) returns <- 1 + returns paths[, k] <- investment * cumprod(returns) } # calculate epnl epnl <- mean(paths[holding_period, ] - investment) print(epnl)
Comments
Post a Comment