Fwd: Bug: fOptions-MonteCarloOptions

Matthias Fuchs mat69 at gmx.net
Wed Jan 19 15:50:20 CET 2011


Hi,

I already mailed Diethelm Wuertz [1] yet did not receive a response so far, 
that is why I send the mail again to you.
Hope this helps.

Cheers,
matthias

[1] Did not RTFM thorough and thus did not see the maintainer mail. ;)

----------  Weitergeleitete Nachricht  ----------

Betreff: RMetrics: fOptions-MonteCarloOptions
Datum: Dienstag 11 Januar 2011, 18:24:04
Von: Matthias Fuchs <mat69 at gmx.net>
An:  Diethelm Wuertz <wuertz at itp.phys.ethz.ch>

Hi,

I was trying to implement the Monte-Carlo-Simulation for a Plain Vanilla call 
(see ex.R), similar to the example in the documentation.

Yet I did not get meaningful results, it appeared to me as if the mcSteps 
variable is ignored in the payoff.calc function.

So I digged a little into the code:
There is a bug in MonteCarloOptions.R, see the attached mc1.patch.
Further the code could be optimized by avoiding the loop and the matrix 
transpose, see mc2.patch.

I did not run any unit tests so I am not sure if those would work with either 
patch.


Cheers,
matthias

PS.: I hope it is ok for me to send this mail directly to you.

-------------------------------------------------------------
-------------- next part --------------
library("fOptions")
set.seed(0) #for reproduceable results

TypeFlag = "c"
S = 50
X = 40
r = 0.05
b = 0.05
vola = 0.4
Time = 1
delT = Time / 1

print(GBSOption(TypeFlag = TypeFlag, S = S, X = X, Time = Time, r = r, b = b, sigma = vola)) #14.48821

wienerPath <- function(randNum)
{
    path = (b - vola * vola / 2) * delT + vola * sqrt(delT) * randNum
}

plainVanillaPayoff = function(path)
{
    ST = S * exp(sum(path))
    if (TypeFlag == "c") {
        payoff = exp(-r * Time) * max(ST - X, 0)
    } else if (TypeFlag == "p") {
        payoff = exp(-r * Time) * max(0, X - ST)
    } else {
        payoff = NaN
    }
}


mc = MonteCarloOption(delta.t = 1, pathLength = 1, mcSteps = 20000, mcLoops = 1, innovations.gen = rnorm.pseudo, path.gen = wienerPath, payoff.calc = plainVanillaPayoff,
antithetic = TRUE, standardization = FALSE, trace = TRUE)

## mc has a ridiculous value of 38.44424 despite 20,000 steps, with both patches it has a value of 14.50386
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mc1.patch
Type: text/x-patch
Size: 555 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/rmetrics-core/attachments/20110119/5028134f/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mc2.patch
Type: text/x-patch
Size: 735 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/rmetrics-core/attachments/20110119/5028134f/attachment-0001.bin>


More information about the Rmetrics-core mailing list