[R-SIG-Finance] Pricing option using Explicit Finite Differencemethod
Panov, Evgeny
evgeny.panov at citi.com
Tue Jul 17 16:26:08 CEST 2007
Dear Joseph,
It seems like you need to price a European option.
Doing it R with finite-difference method will be very inefficient (will probably take more than one second per option), because R is inefficient with "for" loops (unless you can represent these multiplications that you are doing within the loop as one or two a huge matrix multiplications).
However, if it is just a European option, you can do everything in closed-form (Black-Scholes for lognormal RND or Black-Scholes with moment-matching for non-lognormal with discrete dividends will do the job), and it will take less than a second in R.
So maybe instead of debugging finite-differences in R, you may consider not using them at all (if you want to do finite-differences, it can be done much more efficiently in c++, .net or java).
Best regards,
Gene
-----Original Message-----
From: r-sig-finance-bounces at stat.math.ethz.ch
[mailto:r-sig-finance-bounces at stat.math.ethz.ch]On Behalf Of Joseph
Khalil
Sent: Tuesday, July 17, 2007 9:56 AM
To: r-sig-finance at stat.math.ethz.ch
Subject: Re: [R-SIG-Finance] Pricing option using Explicit Finite
Differencemethod
I am a new user of R and new to this mailing list. I am using
the book "Implementing Derivatives Models" by Les Clewlow and Chris
Strickland, and I am trying to simulate
the example on pricing options using the explicit finite difference
method in chapter 3. I have tried the following to price plain European calls but I am getting errors.
K<-100 #Strike price
T<-1 #Time of maturity
t<-0 #Current time
sigma<-0.2 #Volatility
r<-0.06 #Interest rate
div<-0.03 # Dividend yield
S<-100 #Central stock price
dx<-0.02 #Space step around central asset price (logarithmic measurement exp(dx))
Nj<-30 #Number of space steps
N<-500 #Number of time steps until T
dt<-T/N # Time step
nu<-r-div-0.5*sigma^2
pu<-0.5*dt*((sigma/dx)^2+nu/dx) # Probability for go up
pm<-1-dt*(sigma/dx)^2-r*dt # Probability for stay the same
pd<-0.5*dt*((sigma/dx)^2-nu/dx) # Probability for go down
# Initialise matrices
St<-matrix(data=0,nrow=2*Nj+1,ncol=1)
Call<-matrix(data=0,nrow=2*Nj+1,ncol=N+1)
#Compute independent values
for (j in (-Nj:Nj)) {
St[Nj-j+1,1]<-S*exp(j*dx) # Initialise asset prices at maturity
Call[Nj-j+1,N+1]<-max(0,St[Nj-j+1,1]-K) } # Initialise option prices at maturity
#Compute dependent option values
for (i in (N:1)) {
# Explicit compution of option values (backwards)
for (j in (-Nj+1:Nj-1)) {
Call[j+Nj+1,i]<-as.matrix(pu*(as.matrix(Call[j+Nj,i+1])))+as.matrix(pm*Call[j+Nj+1,i+1])+as.matrix(pd*Call[j+Nj+2,i+1])
}
Call[1,i]<-Call[2,i]+St[1,1]-St[2,1] # Upper boundary condition
Call[2*Nj+1,i]<-Call[2*Nj,i] #Lower boundary condition
}
----- Original Message ----
From: Joseph Khalil <joedtka at yahoo.com>
To: r-sig-finance at stat.math.ethz.ch
Sent: Monday, July 16, 2007 10:01:27 PM
Subject: [R-SIG-Finance] Pricing option using Explicit Finite Difference method
Hi,
Does anyone have R code to calculate option prices (European, plain vanilla) using Explicit Finite
Difference method?
Thanks,
Joe
_______________________________________________
R-SIG-Finance at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only.
-- If you want to post, subscribe first.
_______________________________________________
R-SIG-Finance at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only.
-- If you want to post, subscribe first.
More information about the R-SIG-Finance
mailing list