Monte Carlo Option Pricing formula

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Monte Carlo Option Pricing formula

darko
Hi All,

I am trying to cross check option implied employee option price that was derived using Monte Carlo simulation. Below is code and parameter used and after accounting for dividend yield ( 1.46%) the derived option price is 206.8843 using the code snippet provided. Approx 1 cent below 207.95 that is listed in company prospect using their Monte Carlo simulation and below parameters.

As we all know number of iteration can also slightly impact the average price, but am I rightly concerned that my methodology may not be correct?

Any feedback will be appreciated.


exercisePrice   = 0;
timeToExpiry    = 3;        #% in years
underlyingPrice = 490;      #% underlying in cents
expectedVol     = 0.5;      #% expected volatility
expectedDiv     = 0.0146;        #% expected dividend in cents
riskFreeRate    = 0.0425;   #% interest rate
itr = 500000              #% number of iterations
delS = 0*array(0,itr)

for( i in (1:itr))
{
    eps = rnorm(1)         #% random number generator
    dS = expectedDiv*underlyingPrice+underlyingPrice*(riskFreeRate*timeToExpiry) + (underlyingPrice*expectedVol*eps*sqrt(timeToExpiry))
    mv = dS - exercisePrice;

    delS[i] = max(mv,0);
}

mean(delS)

__________________________________________________
Commonwealth Bank
Darko Roupell
Associate Quantitative Analyst
Institutional Banking & Markets
Equities Research
Darling Park Tower 1
Level 23, 201 Sussex Street
Sydney, NSW 2000
P:  +61 2 9117 1254
F:  +61 2 9118 1000
M: +61 400 170 515
E: [hidden email]
Our vision is to be Australia's finest financial services organisation through excelling in customer service.

Email Security
This email is sent solely for informational purposes. Hoax emails, commonly referred to as phishing, can appear to be from the Commonwealth Bank and ask you to update or confirm details such as client numbers, passwords, personal identification questions, contact details or account numbers. The Commonwealth Bank will never send you an email asking you to confirm, update or reveal your confidential banking information.
Important Information
Produced by Global Markets Research, a business unit of Commonwealth Bank of Australia ABN 48 123 123 124 - AFSL 234945 (Commonwealth Bank). This publication is based on information available at the time of publishing.  We believe that the information in this communication is correct and any opinions, conclusions or recommendations are reasonably held or made as at the time of its compilation, but no warranty is made as to accuracy, reliability or completeness.  To the extent permitted by law, neither Commonwealth Bank nor any of its subsidiaries accept liability to any person for loss or damage arising from the use of this communication. This communication does not purport to be a complete statement or summary.
The information provided has been prepared without considering your objectives, financial situation or needs, and before acting on the information, you should consider its appropriateness to your circumstances. No person should act on the basis of this report without considering and if necessary taking appropriate professional advice upon their own particular circumstances.
Commonwealth Bank of Australia, as a provider of investment, borrowing and other financial services undertakes financial transactions with many corporate entities in Australia. This may include any corporate issuer referred to in this communication. Commonwealth Bank and its subsidiaries have effected or may effect transactions for their own account in any investments or related investments referred to herein. In the case of certain securities Commonwealth Bank is or may be the only market maker.


************** IMPORTANT MESSAGE *****************************      
This e-mail message is intended only for the addressee(s) and contains information which may be
confidential.
If you are not the intended recipient please advise the sender by return email, do not use or
disclose the contents, and delete the message and any attachments from your system. Unless
specifically indicated, this email does not constitute formal advice or commitment by the sender
or the Commonwealth Bank of Australia (ABN 48 123 123 124) or its subsidiaries.
We can be contacted through our web site: commbank.com.au.
If you no longer wish to receive commercial electronic messages from us, please reply to this
e-mail by typing Unsubscribe in the subject line.
**************************************************************



        [[alternative HTML version deleted]]

_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only. If you want to post, subscribe first.
-- Also note that this is not the r-help list where general R questions should go.
Reply | Threaded
Open this post in threaded view
|

Re: Monte Carlo Option Pricing formula

Enrico Schumann

Hi, Darko,

Am 02.02.2012 07:44, schrieb Roupell, Darko:
> Hi All,
>
> I am trying to cross check option implied employee option price that was derived using Monte Carlo simulation. Below is code and parameter used and after accounting for dividend yield ( 1.46%) the derived option price is 206.8843 using the code snippet provided. Approx 1 cent below 207.95 that is listed in company prospect using their Monte Carlo simulation and below parameters.
>
> As we all know number of iteration can also slightly impact the average price, but am I rightly concerned that my methodology may not be correct?

Hm, I have not really looked at your programme so I cannot comment
whether it is correct. But we are talking about a difference of about
half a percentage point here. Which is not much. I just ran you script
20 times.

 > summary(results)
    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
   205.6   206.0   206.3   206.3   206.8   206.9

Admittedly, all results are all below the company's price, but
nevertheless: they vary.

There are details that they might have done differently. For instance,
you do not compound (if I see correctly). What if you replaced

riskFreeRate*timeToExpiry

with

(1+riskFreeRate)*timeToExpiry-1

But even if that gives you the price: from a practical point of view,
the difference is small, really.

(Much better would be to check what would happen if the div did not turn
out as expected, if the vol were different, etc)

Regards,
Enrico


>
> Any feedback will be appreciated.
>
>
> exercisePrice   = 0;
> timeToExpiry    = 3;        #% in years
> underlyingPrice = 490;      #% underlying in cents
> expectedVol     = 0.5;      #% expected volatility
> expectedDiv     = 0.0146;        #% expected dividend in cents
> riskFreeRate    = 0.0425;   #% interest rate
> itr = 500000              #% number of iterations
> delS = 0*array(0,itr)
>
> for( i in (1:itr))
> {
>      eps = rnorm(1)         #% random number generator
>      dS = expectedDiv*underlyingPrice+underlyingPrice*(riskFreeRate*timeToExpiry) + (underlyingPrice*expectedVol*eps*sqrt(timeToExpiry))
>      mv = dS - exercisePrice;
>
>      delS[i] = max(mv,0);
> }
>
> mean(delS)
>
> __________________________________________________
> Commonwealth Bank
> Darko Roupell
> Associate Quantitative Analyst
> Institutional Banking&  Markets
> Equities Research
> Darling Park Tower 1
> Level 23, 201 Sussex Street
> Sydney, NSW 2000
> P:  +61 2 9117 1254
> F:  +61 2 9118 1000
> M: +61 400 170 515
> E: [hidden email]

[...]
> _______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions should go.
>

--
Enrico Schumann
Lucerne, Switzerland
http://nmof.net/

_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only. If you want to post, subscribe first.
-- Also note that this is not the r-help list where general R questions should go.
Reply | Threaded
Open this post in threaded view
|

Re: Monte Carlo Option Pricing formula R code vs Matlab

darko
Thanks Enrico,

To test if the code structure is correct I googled for alternative samples of Monte Carlo Option pricing coded in Matlab.

What I find the most puzzling is that even if I re-code using sample from matlab the results obtained in R are very different to those obtained by matlab, despite using the same parameters apart of Rnorm(). As I am at loss I am hoping that you or someone else in R-SIG may spot the difference that explains it.

########################################## R code ###########################################################

exercisePrice   = 100;
timeToExpiry    = 5;        #% in years
underlyingPrice = 100;      #% underlying in cents
expectedVol     = 0.2;      #% expected volatility
expectedDiv     = 0;        # expected dividend
riskFreeRate    = 0.06;   #% interest rate
itr = 10000              #% number of iterations
delS = 0*array(0,itr)

dt = 1/252
nudt = (riskFreeRate - expectedDiv - 0.5 * expectedVol^ 2)* dt
sigsdt = expectedVol * sqrt(dt)
itr = 10000
delS = array(0,itr)
drifts = 255 * timeToExpiry

for( i in (1:itr))
{
dS =  underlyingPrice

    for (j in (1:drifts))
    {
    eps = rnorm(1, mean = 0, sd = 1)
    dS  = dS * exp(nudt +sigsdt*eps)
    }
delS[i] =dS
}

payoff = max(delS - exercisePrice, 0);
cal=mean(payoff) * exp(-riskFreeRate*timeToExpiry)

results:
> cal
[1] 396.2675

################################################## MATLAB ###########################################

S0=100; K=100; r=0.06; sig=0.2; T=5; div=0;

dt = 1/252;
nudt = (r - div - 0.5 * sig ^ 2) * dt;
sigsdt = sig * sqrt(dt)
sim=10000;
Si=zeros(1,sim);

drifts=255*T
for i=1:sim
S=S0;
for j=1:drifts;
z=randn(1,1);

S = S* exp(nudt + sigsdt * z);
end
Si(i)=S;
end

payoff = max(Si - K, 0);
cal=mean(payoff) * exp(-r* T)

calbs=blsprice(S0,K,r,T,sig,div) <---B&S

results:

cal = 32.0173


calbs = 31.6150

http://www.quantnet.com/forum/threads/accuracy-of-monte-carlo-simulation-for-option-pricing.2224/

__________________________________________________
Commonwealth Bank
Darko Roupell
Associate Quantitative Analyst
Institutional Banking & Markets
Equities Research
Darling Park Tower 1
Level 23, 201 Sussex Street
Sydney, NSW 2000
P:  +61 2 9117 1254
F:  +61 2 9118 1000
M: +61 400 170 515
E: [hidden email]
Our vision is to be Australia's finest financial services organisation through excelling in customer service.

Email Security
This email is sent solely for informational purposes. Hoax emails, commonly referred to as phishing, can appear to be from the Commonwealth Bank and ask you to update or confirm details such as client numbers, passwords, personal identification questions, contact details or account numbers. The Commonwealth Bank will never send you an email asking you to confirm, update or reveal your confidential banking information.
Important Information
Produced by Global Markets Research, a business unit of Commonwealth Bank of Australia ABN 48 123 123 124 - AFSL 234945 (Commonwealth Bank). This publication is based on information available at the time of publishing.  We believe that the information in this communication is correct and any opinions, conclusions or recommendations are reasonably held or made as at the time of its compilation, but no warranty is made as to accuracy, reliability or completeness.  To the extent permitted by law, neither Commonwealth Bank nor any of its subsidiaries accept liability to any person for loss or damage arising from the use of this communication. This communication does not purport to be a complete statement or summary. 
The information provided has been prepared without considering your objectives, financial situation or needs, and before acting on the information, you should consider its appropriateness to your circumstances. No person should act on the basis of this report without considering and if necessary taking appropriate professional advice upon their own particular circumstances. 
Commonwealth Bank of Australia, as a provider of investment, borrowing and other financial services undertakes financial transactions with many corporate entities in Australia. This may include any corporate issuer referred to in this communication. Commonwealth Bank and its subsidiaries have effected or may effect transactions for their own account in any investments or related investments referred to herein. In the case of certain securities Commonwealth Bank is or may be the only market maker.

-----Original Message-----
From: Enrico Schumann [mailto:[hidden email]]
Sent: Thursday, 2 February 2012 8:45 PM
To: Roupell, Darko
Cc: [hidden email]
Subject: Re: [R-SIG-Finance] Monte Carlo Option Pricing formula


Hi, Darko,

Am 02.02.2012 07:44, schrieb Roupell, Darko:
> Hi All,
>
> I am trying to cross check option implied employee option price that was derived using Monte Carlo simulation. Below is code and parameter used and after accounting for dividend yield ( 1.46%) the derived option price is 206.8843 using the code snippet provided. Approx 1 cent below 207.95 that is listed in company prospect using their Monte Carlo simulation and below parameters.
>
> As we all know number of iteration can also slightly impact the average price, but am I rightly concerned that my methodology may not be correct?

Hm, I have not really looked at your programme so I cannot comment
whether it is correct. But we are talking about a difference of about
half a percentage point here. Which is not much. I just ran you script
20 times.

 > summary(results)
    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
   205.6   206.0   206.3   206.3   206.8   206.9

Admittedly, all results are all below the company's price, but
nevertheless: they vary.

There are details that they might have done differently. For instance,
you do not compound (if I see correctly). What if you replaced

riskFreeRate*timeToExpiry

with

(1+riskFreeRate)*timeToExpiry-1

But even if that gives you the price: from a practical point of view,
the difference is small, really.

(Much better would be to check what would happen if the div did not turn
out as expected, if the vol were different, etc)

Regards,
Enrico


>
> Any feedback will be appreciated.
>
>
> exercisePrice   = 0;
> timeToExpiry    = 3;        #% in years
> underlyingPrice = 490;      #% underlying in cents
> expectedVol     = 0.5;      #% expected volatility
> expectedDiv     = 0.0146;        #% expected dividend in cents
> riskFreeRate    = 0.0425;   #% interest rate
> itr = 500000              #% number of iterations
> delS = 0*array(0,itr)
>
> for( i in (1:itr))
> {
>      eps = rnorm(1)         #% random number generator
>      dS = expectedDiv*underlyingPrice+underlyingPrice*(riskFreeRate*timeToExpiry) + (underlyingPrice*expectedVol*eps*sqrt(timeToExpiry))
>      mv = dS - exercisePrice;
>
>      delS[i] = max(mv,0);
> }
>
> mean(delS)
>
> __________________________________________________
> Commonwealth Bank
> Darko Roupell
> Associate Quantitative Analyst
> Institutional Banking&  Markets
> Equities Research
> Darling Park Tower 1
> Level 23, 201 Sussex Street
> Sydney, NSW 2000
> P:  +61 2 9117 1254
> F:  +61 2 9118 1000
> M: +61 400 170 515
> E: [hidden email]

[...]
> _______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions should go.
>

--
Enrico Schumann
Lucerne, Switzerland
http://nmof.net/

************** IMPORTANT MESSAGE *****************************      
This e-mail message is intended only for the addressee(s) and contains information which may be
confidential.
If you are not the intended recipient please advise the sender by return email, do not use or
disclose the contents, and delete the message and any attachments from your system. Unless
specifically indicated, this email does not constitute formal advice or commitment by the sender
or the Commonwealth Bank of Australia (ABN 48 123 123 124) or its subsidiaries.
We can be contacted through our web site: commbank.com.au.
If you no longer wish to receive commercial electronic messages from us, please reply to this
e-mail by typing Unsubscribe in the subject line.

_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only. If you want to post, subscribe first.
-- Also note that this is not the r-help list where general R questions should go.
Reply | Threaded
Open this post in threaded view
|

Re: Monte Carlo Option Pricing formula

Rex-2
In reply to this post by darko
Roupell, Darko <[hidden email]> [2012-02-01 22:45]:

>
>I am trying to cross check option implied employee option price that
>was derived using Monte Carlo simulation. Below is code and parameter
>used and after accounting for dividend yield ( 1.46%) the derived
>option price is 206.8843 using the code snippet provided. Approx 1
>cent below 207.95 that is listed in company prospect using their
>Monte Carlo simulation and below parameters.
>
>As we all know number of iteration can also slightly impact the
>average price, but am I rightly concerned that my methodology may not
>be correct?

Hi Darko,

Yes -- or at least different from the company's assumptions. Enrico
has informally shown that there is a statistically significant
difference in the two means. Conceptually, it may be important, but
practically, the difference is insignificant.

I have 3 other observations: first, your code uses a "for" loop which
should be avoided in code that takes a significant amount of time to
run in R, if possible. rnorm() can obviously be moved out of the loop
and called once to generate the eps vector, but delS[i] = max(mv,0) can
also be moved out of the loop, and then there's no need for a loop.

To see the difference eliminating the loop makes, let's compare your
code to a no-loop version:

start = Sys.time()
exercisePrice   = 0;
timeToExpiry    = 3;        #% in years
underlyingPrice = 490;      #% underlying in cents
expectedVol     = 0.5;      #% expected volatility
expectedDiv     = 0.0146;   #% expected dividend in cents
riskFreeRate    = 0.0425;   #% interest rate
itr = 500000                #% number of iterations
delS = 0*array(0,itr)

for( i in (1:itr))
{
      eps = rnorm(1)          #% random number generator
      dS = expectedDiv*underlyingPrice+underlyingPrice*(riskFreeRate*timeToExpiry) + (underlyingPrice*expectedVol*eps*sqrt(timeToExpiry))
      mv = dS - exercisePrice;

      delS[i] = max(mv,0);
}
mean(delS)
#206.3257
Sys.time - start
Time difference of 36.64036 secs

BTW, you multiply the dividend by the stock price, which is
inconsistent with your"expected dividend in cents" code comment. Plus,
it's a percentage per year, right? If so, I think the first term in
your dS expression should be: expectedDiv*underlyingPrice*timeToExpiry.

I'm going to rewrite your code using short variable names; long
names make the math itself more difficult for me to immediately see.

start <- Sys.time()
E   <- 0             #exercise price
t   <- 3             #option life (years)
S   <- 490           #stock price (cents)
v   <- 0.5           #est. future annual volatility
d   <- 0.0146        #dividend (code suggests this is a percentage of S)
r   <- 0.0425        #annual interest rate
N   <- 5000000
z   <- S*(d+r*t + rnorm(N, 0, v*sqrt(t)))
sum(z[z > E])/N
#206.203
Sys.time() - start
Time difference of 0.5397904 secs

The loop code takes 68 times as long to run.

Second, why are you using a normal distribution? The usual rough
approximation is to assume a lognormal distribution for stock prices,
but that's flawed, too.

Third, what is the annual interest rate? From your code, it appears to
be the drift rate of the process driving the stock price, which has
nothing to do with interest rates. A more realistic model will
estimate the future drift rate, and using that plus the other
parameters, will calculate a future value for the option. The present
value is that future value discounted at the rate you choose (which is
unlikely to be the riskless rate). The Black-Scholes-Merton derivation
has confused many people on this point.

HTH,

-rex
--
For every complex problem there is an answer that is clear, simple,
and wrong. --H. L. Mencken

_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only. If you want to post, subscribe first.
-- Also note that this is not the r-help list where general R questions should go.
Reply | Threaded
Open this post in threaded view
|

Re: Monte Carlo Option Pricing formula R code vs Matlab

Enrico Schumann
In reply to this post by darko

Hi Darko,

R's 'max' function behaves differently from MATLAB's. You probably don't
want

payoff = max(delS - exercisePrice, 0);

but

payoff = pmax(delS - exercisePrice, 0)

(and you should settle on one number of time steps per year; either 255
or 252).

If you only work with European options and use the
Black--Scholes--Merton SDE for the underlier, then there is no need to
simulate the paths of the SDEs; you can do one time step and "jump from
0 to T".

And as rex has pointed out, there would indeed be a substantial speedup
if you rewrote your code in a vectorised fashion. (This is also true for
MATLAB, though the speedup is typically much smaller than in R.)

Regards,
Enrico



Am 03.02.2012 00:36, schrieb Roupell, Darko:

> Thanks Enrico,
>
> To test if the code structure is correct I googled for alternative samples of Monte Carlo Option pricing coded in Matlab.
>
> What I find the most puzzling is that even if I re-code using sample from matlab the results obtained in R are very different to those obtained by matlab, despite using the same parameters apart of Rnorm(). As I am at loss I am hoping that you or someone else in R-SIG may spot the difference that explains it.
>
> ########################################## R code ###########################################################
>
> exercisePrice   = 100;
> timeToExpiry    = 5;        #% in years
> underlyingPrice = 100;      #% underlying in cents
> expectedVol     = 0.2;      #% expected volatility
> expectedDiv     = 0;        # expected dividend
> riskFreeRate    = 0.06;   #% interest rate
> itr = 10000              #% number of iterations
> delS = 0*array(0,itr)
>
> dt = 1/252
> nudt = (riskFreeRate - expectedDiv - 0.5 * expectedVol^ 2)* dt
> sigsdt = expectedVol * sqrt(dt)
> itr = 10000
> delS = array(0,itr)
> drifts = 255 * timeToExpiry
>
> for( i in (1:itr))
> {
> dS =  underlyingPrice
>
>      for (j in (1:drifts))
>      {
>      eps = rnorm(1, mean = 0, sd = 1)
>      dS  = dS * exp(nudt +sigsdt*eps)
>      }
> delS[i] =dS
> }
>
> payoff = max(delS - exercisePrice, 0);
> cal=mean(payoff) * exp(-riskFreeRate*timeToExpiry)
>
> results:
>> cal
> [1] 396.2675
>
> ################################################## MATLAB ###########################################
>
> S0=100; K=100; r=0.06; sig=0.2; T=5; div=0;
>
> dt = 1/252;
> nudt = (r - div - 0.5 * sig ^ 2) * dt;
> sigsdt = sig * sqrt(dt)
> sim=10000;
> Si=zeros(1,sim);
>
> drifts=255*T
> for i=1:sim
> S=S0;
> for j=1:drifts;
> z=randn(1,1);
>
> S = S* exp(nudt + sigsdt * z);
> end
> Si(i)=S;
> end
>
> payoff = max(Si - K, 0);
> cal=mean(payoff) * exp(-r* T)
>
> calbs=blsprice(S0,K,r,T,sig,div)<---B&S
>
> results:
>
> cal = 32.0173
>
>
> calbs = 31.6150
>
> http://www.quantnet.com/forum/threads/accuracy-of-monte-carlo-simulation-for-option-pricing.2224/
>
> __________________________________________________
> Commonwealth Bank
> Darko Roupell
> Associate Quantitative Analyst
> Institutional Banking&  Markets
> Equities Research
> Darling Park Tower 1
> Level 23, 201 Sussex Street
> Sydney, NSW 2000
> P:  +61 2 9117 1254
> F:  +61 2 9118 1000
> M: +61 400 170 515
> E: [hidden email]
> Our vision is to be Australia's finest financial services organisation through excelling in customer service.
>
> Email Security
> This email is sent solely for informational purposes. Hoax emails, commonly referred to as phishing, can appear to be from the Commonwealth Bank and ask you to update or confirm details such as client numbers, passwords, personal identification questions, contact details or account numbers. The Commonwealth Bank will never send you an email asking you to confirm, update or reveal your confidential banking information.
> Important Information
> Produced by Global Markets Research, a business unit of Commonwealth Bank of Australia ABN 48 123 123 124 - AFSL 234945 (Commonwealth Bank). This publication is based on information available at the time of publishing.  We believe that the information in this communication is correct and any opinions, conclusions or recommendations are reasonably held or made as at the time of its compilation, but no warranty is made as to accuracy, reliability or completeness.  To the extent permitted by law, neither Commonwealth Bank nor any of its subsidiaries accept liability to any person for loss or damage arising from the use of this communication. This communication does not purport to be a complete statement or summary.
> The information provided has been prepared without considering your objectives, financial situation or needs, and before acting on the information, you should consider its appropriateness to your circumstances. No person should act on the basis of this report without considering and if necessary taking appropriate professional advice upon their own particular circumstances.
> Commonwealth Bank of Australia, as a provider of investment, borrowing and other financial services undertakes financial transactions with many corporate entities in Australia. This may include any corporate issuer referred to in this communication. Commonwealth Bank and its subsidiaries have effected or may effect transactions for their own account in any investments or related investments referred to herein. In the case of certain securities Commonwealth Bank is or may be the only market maker.
>
> -----Original Message-----
> From: Enrico Schumann [mailto:[hidden email]]
> Sent: Thursday, 2 February 2012 8:45 PM
> To: Roupell, Darko
> Cc: [hidden email]
> Subject: Re: [R-SIG-Finance] Monte Carlo Option Pricing formula
>
>
> Hi, Darko,
>
> Am 02.02.2012 07:44, schrieb Roupell, Darko:
>> Hi All,
>>
>> I am trying to cross check option implied employee option price that was derived using Monte Carlo simulation. Below is code and parameter used and after accounting for dividend yield ( 1.46%) the derived option price is 206.8843 using the code snippet provided. Approx 1 cent below 207.95 that is listed in company prospect using their Monte Carlo simulation and below parameters.
>>
>> As we all know number of iteration can also slightly impact the average price, but am I rightly concerned that my methodology may not be correct?
>
> Hm, I have not really looked at your programme so I cannot comment
> whether it is correct. But we are talking about a difference of about
> half a percentage point here. Which is not much. I just ran you script
> 20 times.
>
>   >  summary(results)
>      Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
>     205.6   206.0   206.3   206.3   206.8   206.9
>
> Admittedly, all results are all below the company's price, but
> nevertheless: they vary.
>
> There are details that they might have done differently. For instance,
> you do not compound (if I see correctly). What if you replaced
>
> riskFreeRate*timeToExpiry
>
> with
>
> (1+riskFreeRate)*timeToExpiry-1
>
> But even if that gives you the price: from a practical point of view,
> the difference is small, really.
>
> (Much better would be to check what would happen if the div did not turn
> out as expected, if the vol were different, etc)
>
> Regards,
> Enrico
>
>
>>
>> Any feedback will be appreciated.
>>
>>
>> exercisePrice   = 0;
>> timeToExpiry    = 3;        #% in years
>> underlyingPrice = 490;      #% underlying in cents
>> expectedVol     = 0.5;      #% expected volatility
>> expectedDiv     = 0.0146;        #% expected dividend in cents
>> riskFreeRate    = 0.0425;   #% interest rate
>> itr = 500000              #% number of iterations
>> delS = 0*array(0,itr)
>>
>> for( i in (1:itr))
>> {
>>       eps = rnorm(1)         #% random number generator
>>       dS = expectedDiv*underlyingPrice+underlyingPrice*(riskFreeRate*timeToExpiry) + (underlyingPrice*expectedVol*eps*sqrt(timeToExpiry))
>>       mv = dS - exercisePrice;
>>
>>       delS[i] = max(mv,0);
>> }
>>
>> mean(delS)
>>
>> __________________________________________________
>> Commonwealth Bank
>> Darko Roupell
>> Associate Quantitative Analyst
>> Institutional Banking&   Markets
>> Equities Research
>> Darling Park Tower 1
>> Level 23, 201 Sussex Street
>> Sydney, NSW 2000
>> P:  +61 2 9117 1254
>> F:  +61 2 9118 1000
>> M: +61 400 170 515
>> E: [hidden email]
>
> [...]
>> _______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
>> -- Subscriber-posting only. If you want to post, subscribe first.
>> -- Also note that this is not the r-help list where general R questions should go.
>>
>

--
Enrico Schumann
Lucerne, Switzerland
http://nmof.net/

_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only. If you want to post, subscribe first.
-- Also note that this is not the r-help list where general R questions should go.
Reply | Threaded
Open this post in threaded view
|

Re: Monte Carlo Option Pricing formula R code vs Matlab

mark leeds
darko: stefano iacus book "simulation and inference for stochastic
differential equations" ( useR) has very nice code samples in it some of
which do option pricing. it's a very nice book
and i highly recommend it for the type of things you're doing. he also has
a new book out
with a related title but I don't have it so I can't say anything about it.
but, if it's anything like
the former, I highly recommend it also.


mark


On Fri, Feb 3, 2012 at 3:08 AM, Enrico Schumann <[hidden email]>wrote:

>
> Hi Darko,
>
> R's 'max' function behaves differently from MATLAB's. You probably don't
> want
>
> payoff = max(delS - exercisePrice, 0);
>
> but
>
> payoff = pmax(delS - exercisePrice, 0)
>
> (and you should settle on one number of time steps per year; either 255 or
> 252).
>
> If you only work with European options and use the Black--Scholes--Merton
> SDE for the underlier, then there is no need to simulate the paths of the
> SDEs; you can do one time step and "jump from 0 to T".
>
> And as rex has pointed out, there would indeed be a substantial speedup if
> you rewrote your code in a vectorised fashion. (This is also true for
> MATLAB, though the speedup is typically much smaller than in R.)
>
> Regards,
> Enrico
>
>
>
> Am 03.02.2012 00:36, schrieb Roupell, Darko:
>
>> Thanks Enrico,
>>
>> To test if the code structure is correct I googled for alternative
>> samples of Monte Carlo Option pricing coded in Matlab.
>>
>> What I find the most puzzling is that even if I re-code using sample from
>> matlab the results obtained in R are very different to those obtained by
>> matlab, despite using the same parameters apart of Rnorm(). As I am at loss
>> I am hoping that you or someone else in R-SIG may spot the difference that
>> explains it.
>>
>> ##############################**############ R code
>> ##############################**#############################
>>
>> exercisePrice   = 100;
>> timeToExpiry    = 5;        #% in years
>> underlyingPrice = 100;      #% underlying in cents
>> expectedVol     = 0.2;      #% expected volatility
>> expectedDiv     = 0;        # expected dividend
>> riskFreeRate    = 0.06;   #% interest rate
>> itr = 10000              #% number of iterations
>> delS = 0*array(0,itr)
>>
>> dt = 1/252
>> nudt = (riskFreeRate - expectedDiv - 0.5 * expectedVol^ 2)* dt
>> sigsdt = expectedVol * sqrt(dt)
>> itr = 10000
>> delS = array(0,itr)
>> drifts = 255 * timeToExpiry
>>
>> for( i in (1:itr))
>> {
>> dS =  underlyingPrice
>>
>>     for (j in (1:drifts))
>>     {
>>     eps = rnorm(1, mean = 0, sd = 1)
>>     dS  = dS * exp(nudt +sigsdt*eps)
>>     }
>> delS[i] =dS
>> }
>>
>> payoff = max(delS - exercisePrice, 0);
>> cal=mean(payoff) * exp(-riskFreeRate***timeToExpiry)
>>
>> results:
>>
>>> cal
>>>
>> [1] 396.2675
>>
>> ##############################**#################### MATLAB
>> ##############################**#############
>>
>> S0=100; K=100; r=0.06; sig=0.2; T=5; div=0;
>>
>> dt = 1/252;
>> nudt = (r - div - 0.5 * sig ^ 2) * dt;
>> sigsdt = sig * sqrt(dt)
>> sim=10000;
>> Si=zeros(1,sim);
>>
>> drifts=255*T
>> for i=1:sim
>> S=S0;
>> for j=1:drifts;
>> z=randn(1,1);
>>
>> S = S* exp(nudt + sigsdt * z);
>> end
>> Si(i)=S;
>> end
>>
>> payoff = max(Si - K, 0);
>> cal=mean(payoff) * exp(-r* T)
>>
>> calbs=blsprice(S0,K,r,T,sig,**div)<---B&S
>>
>> results:
>>
>> cal = 32.0173
>>
>>
>> calbs = 31.6150
>>
>> http://www.quantnet.com/forum/**threads/accuracy-of-monte-**
>> carlo-simulation-for-option-**pricing.2224/<http://www.quantnet.com/forum/threads/accuracy-of-monte-carlo-simulation-for-option-pricing.2224/>
>>
>> ______________________________**____________________
>> Commonwealth Bank
>> Darko Roupell
>> Associate Quantitative Analyst
>> Institutional Banking&  Markets
>> Equities Research
>> Darling Park Tower 1
>> Level 23, 201 Sussex Street
>> Sydney, NSW 2000
>> P:  +61 2 9117 1254
>> F:  +61 2 9118 1000
>> M: +61 400 170 515
>> E: [hidden email]
>> Our vision is to be Australia's finest financial services organisation
>> through excelling in customer service.
>>
>> Email Security
>> This email is sent solely for informational purposes. Hoax emails,
>> commonly referred to as phishing, can appear to be from the Commonwealth
>> Bank and ask you to update or confirm details such as client numbers,
>> passwords, personal identification questions, contact details or account
>> numbers. The Commonwealth Bank will never send you an email asking you to
>> confirm, update or reveal your confidential banking information.
>> Important Information
>> Produced by Global Markets Research, a business unit of Commonwealth Bank
>> of Australia ABN 48 123 123 124 - AFSL 234945 (Commonwealth Bank). This
>> publication is based on information available at the time of publishing.
>>  We believe that the information in this communication is correct and any
>> opinions, conclusions or recommendations are reasonably held or made as at
>> the time of its compilation, but no warranty is made as to accuracy,
>> reliability or completeness.  To the extent permitted by law, neither
>> Commonwealth Bank nor any of its subsidiaries accept liability to any
>> person for loss or damage arising from the use of this communication. This
>> communication does not purport to be a complete statement or summary.
>> The information provided has been prepared without considering your
>> objectives, financial situation or needs, and before acting on the
>> information, you should consider its appropriateness to your circumstances.
>> No person should act on the basis of this report without considering and if
>> necessary taking appropriate professional advice upon their own particular
>> circumstances.
>> Commonwealth Bank of Australia, as a provider of investment, borrowing
>> and other financial services undertakes financial transactions with many
>> corporate entities in Australia. This may include any corporate issuer
>> referred to in this communication. Commonwealth Bank and its subsidiaries
>> have effected or may effect transactions for their own account in any
>> investments or related investments referred to herein. In the case of
>> certain securities Commonwealth Bank is or may be the only market maker.
>>
>> -----Original Message-----
>> From: Enrico Schumann [mailto:enricoschumann@yahoo.**de<[hidden email]>
>> ]
>> Sent: Thursday, 2 February 2012 8:45 PM
>> To: Roupell, Darko
>> Cc: [hidden email]
>> Subject: Re: [R-SIG-Finance] Monte Carlo Option Pricing formula
>>
>>
>> Hi, Darko,
>>
>> Am 02.02.2012 07:44, schrieb Roupell, Darko:
>>
>>> Hi All,
>>>
>>> I am trying to cross check option implied employee option price that was
>>> derived using Monte Carlo simulation. Below is code and parameter used and
>>> after accounting for dividend yield ( 1.46%) the derived option price is
>>> 206.8843 using the code snippet provided. Approx 1 cent below 207.95 that
>>> is listed in company prospect using their Monte Carlo simulation and below
>>> parameters.
>>>
>>> As we all know number of iteration can also slightly impact the average
>>> price, but am I rightly concerned that my methodology may not be correct?
>>>
>>
>> Hm, I have not really looked at your programme so I cannot comment
>> whether it is correct. But we are talking about a difference of about
>> half a percentage point here. Which is not much. I just ran you script
>> 20 times.
>>
>>  >  summary(results)
>>     Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
>>    205.6   206.0   206.3   206.3   206.8   206.9
>>
>> Admittedly, all results are all below the company's price, but
>> nevertheless: they vary.
>>
>> There are details that they might have done differently. For instance,
>> you do not compound (if I see correctly). What if you replaced
>>
>> riskFreeRate*timeToExpiry
>>
>> with
>>
>> (1+riskFreeRate)*timeToExpiry-**1
>>
>> But even if that gives you the price: from a practical point of view,
>> the difference is small, really.
>>
>> (Much better would be to check what would happen if the div did not turn
>> out as expected, if the vol were different, etc)
>>
>> Regards,
>> Enrico
>>
>>
>>
>>> Any feedback will be appreciated.
>>>
>>>
>>> exercisePrice   = 0;
>>> timeToExpiry    = 3;        #% in years
>>> underlyingPrice = 490;      #% underlying in cents
>>> expectedVol     = 0.5;      #% expected volatility
>>> expectedDiv     = 0.0146;        #% expected dividend in cents
>>> riskFreeRate    = 0.0425;   #% interest rate
>>> itr = 500000              #% number of iterations
>>> delS = 0*array(0,itr)
>>>
>>> for( i in (1:itr))
>>> {
>>>      eps = rnorm(1)         #% random number generator
>>>      dS = expectedDiv*underlyingPrice+**underlyingPrice*(riskFreeRate***timeToExpiry)
>>> + (underlyingPrice*expectedVol***eps*sqrt(timeToExpiry))
>>>      mv = dS - exercisePrice;
>>>
>>>      delS[i] = max(mv,0);
>>> }
>>>
>>> mean(delS)
>>>
>>> ______________________________**____________________
>>> Commonwealth Bank
>>> Darko Roupell
>>> Associate Quantitative Analyst
>>> Institutional Banking&   Markets
>>> Equities Research
>>> Darling Park Tower 1
>>> Level 23, 201 Sussex Street
>>> Sydney, NSW 2000
>>> P:  +61 2 9117 1254
>>> F:  +61 2 9118 1000
>>> M: +61 400 170 515
>>> E: [hidden email]
>>>
>>
>> [...]
>>
>>> ______________________________**_________________
>>> [hidden email] mailing list
>>> https://stat.ethz.ch/mailman/**listinfo/r-sig-finance<https://stat.ethz.ch/mailman/listinfo/r-sig-finance>
>>> -- Subscriber-posting only. If you want to post, subscribe first.
>>> -- Also note that this is not the r-help list where general R questions
>>> should go.
>>>
>>>
>>
> --
> Enrico Schumann
> Lucerne, Switzerland
> http://nmof.net/
>
> ______________________________**_________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/**listinfo/r-sig-finance<https://stat.ethz.ch/mailman/listinfo/r-sig-finance>
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions
> should go.
>

        [[alternative HTML version deleted]]

_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only. If you want to post, subscribe first.
-- Also note that this is not the r-help list where general R questions should go.
Reply | Threaded
Open this post in threaded view
|

Re: Monte Carlo Option Pricing formula R code vs Matlab

Rex-2
In reply to this post by darko
Roupell, Darko <[hidden email]> [2012-02-02 15:37]:

>What I find the most puzzling is that even if I re-code using sample from matlab the results obtained in R are very different to those obtained by matlab, despite using the same parameters apart of Rnorm(). As I am at loss I am hoping that you or someone else in R-SIG may spot the difference that explains it.

As Enrico pointed out, you want pmax, not max, and the final price is
all that matters, not the path, so you don't need the inner loop. And,
you don't need the outer loop, either. Here, your code runs in 38.9
seconds with itr = 10000.

large nested loops in R are an abomination; using the language
effectively requires learning to avoid them whenever possible. In this
case, your code takes 18702(!) times as long to run as a vectorized
Monte Carlo version.

For possible pedagogical value, here's a vectorized MC approach:

start = Sys.time()
E    = 100                            #exercise price
S    = 100                            #initial stock price
t    = 5                              #time to expiration (years)
sd   = 0.2                            #annual volatility
d    = 0.0                            #annual dividend rate
r    = 0.06                           #riskless interest rate
N    = 1000000                        #number of random walks
mu   = (r - d - 0.5*sd^2)*t           #total drift
SD   = sd*sqrt(t)                     #total volatility
z    = as.vector(rlnorm(N, mu, SD))   #generate all lognormal randoms
endS = S*z                            #ending stock prices
fv   = pmax(0, endS-E)                #future option values
opt  = fv*exp(-r*t)                   #present option values
mean(opt)
#31.6
Sys.time() - start
Time difference of 0.2075577 secs

Note that N is 100 times as large in the above, so the nested loop
version takes 100*38.9/0.208 = 18702 times as long as the vectorized
version does.

HTH,

-rex
--
"In the real world, this would be a problem.  But in mathematics, we
can just define a place where this problem doesn't exist.  So we'll go
ahead and do that now..."

_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only. If you want to post, subscribe first.
-- Also note that this is not the r-help list where general R questions should go.