lundi 3 avril 2017

Conditional regression in R

Using regression to price an Bermudan call option is an effective way. Even more effective is to regress on only in-the-money options.

I'am struggeling a bit with the implementation of regression only in-the-money options from a n*m simulated stock pathes. I've tried to follow both http://ift.tt/1dRywRI and Linear regression in R with if statement without any success.

T <- 2         #Years to maturity
S0 <- 100      #Today's stock price
sigma <- 0.2   #Volatility
K <- 100       #Strike price
delta <- 0.25  #Quarterly exercise
r <- 0.01      #Continous risk-free interest rate
n <- 10^5      #Number of times to perform the simulation

#Simulating n*m stock prices: 
m <- T/delta
W <- rnorm(n * m)
e <- matrix(exp((r - 0.5 * sigma^2)*delta + sigma * sqrt(delta) * W), n, m)
S <- (t(S0 * apply(e, 1, cumprod)))
V2 <- c() #Empty vector to be used on conditional statements

#Creating a for-loop in order to get the right discount rates for each quarter. 
#h is the pay-off if exercising the option.
for (i in 1:m) {
  h <- exp(-r * delta * i) * pmax(S - K, 0)
}

#Variables to be used in the regression:
m <- ncol(S) #Number of coloumns in the stock price matrix.
V <- h[, m]
j <- m - 1 #Counting variable used in the regression.

Then I'm creating X as a new variable containing only in-the-money options to perform my regression:

X <- ifelse(S > K, S, NA)
for (j in (m - 1):1) {
  cv <- lm(V ~ X[, j], na.action = na.omit)$fitted.values
  V <- pmax(h[, j], cv)
}

However, this yielded the result of In pmax(h[, j], cv) : an argument will be fractionally recycled due to the differences in length. I've tried all of the different options provided by in lm, but got no closer to the answer. Running the same regression, but defining X as X <- ifelse(S > K, S, 0) doesn't fix the problem. It only returns values two values; ~14 and ~23.

Aucun commentaire:

Enregistrer un commentaire