Philipp
Philipp

Reputation: 57

Log-Return simulation in R does not lead to expected result

I'm currently trying to simulate log-returns in R and calculate the expected P&L for a simple investment. My code is working, but I have a problem in understanding why the expected profit is not equal to:

(exp(annual_mean * (holding_period/253)) * investment) - investment

which equals 5350 in my example. However, running the following simulation always results into a profit of around 5580:

investment <- 1000000
holding_period <- 45
annual_mean <- 0.03
annual_sd <- 0.05
simulations <- 1000000

  # Create Matrix for log-returns
  Paths <- matrix(data = NA, nrow = holding_period, ncol = simulations); 

  # feed matrix with log-returns
  for (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 the high number of simulations I wouldn't expect such a big deviation from the expected profit. I also tried a higher number of simulations but the result is still the same.

I'm trying to show with this simulation that the higher the number of simulations the closer the actual value gets to the expected value.

I hope you guys understand my question. I know this is more a finance related topic but I guess there is some misinterpretation in the code from my side.

Thanks a lot!

Upvotes: 0

Views: 460

Answers (2)

Philipp
Philipp

Reputation: 57

I finally found the answer to this problem. I totally neglected the fact that I'm transforming the normally distributed return by multiplying it with the initial investment and continuously compounding. While multiplication leaves the returns normally distributed, the exponential function transforms the random variable so that is is log-normally distributed. Therefore the mean is equal to exp(μ+σ^2/2) with μ and σ^2 equal to the mean and the standard deviation of the associated normal distrbution.

Upvotes: 1

Dan Lewer
Dan Lewer

Reputation: 956

I believe the issue is with your use of cumsum - you are treating the returns as if the rates add up rather than multiply/compound. If you alter the code slightly and use cumprod instead, it seems to give the right result...

# feed matrix with log-returns
for (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)

Upvotes: 2

Related Questions