I've built a very simple function to estimate the probability for a Long Straddle (derivative strategy) to be positive at expiration.
derivativeStrategyLongStraddle[currentPrice_, strikePrice_?NumberQ,
callPremium_?NumberQ, putPremium_?NumberQ] :=
Max[0, currentPrice - strikePrice] - callPremium +
Max[0, strikePrice - currentPrice] - putPremium;
r= NProbability[derivativeStrategyLongStraddle[x, 39, 2.38, 0.02] >= 0,
x \[Distributed] NormalDistribution[41.57339177753672`, 0.9105010291072763`]]
0.575516
Now, I want to accelerate this by compiling my simple derivativeStrategyLongStraddle function.
derivativeStrategyLongStraddleCompiled =
Compile[{{currentPrice}, {strikePrice}, {callPremium}, {putPremium}},
Max[0, currentPrice - strikePrice] - callPremium +
Max[0, strikePrice - currentPrice] - putPremium,
RuntimeAttributes -> {Listable}]
But I get the following error message when I try to run:
rC= NProbability[derivativeStrategyLongStraddleCompiled[x, 39, 2.38, 0.02] >= 0,
x \[Distributed] NormalDistribution[41.57339177753672`, 0.9105010291072763`]]
CompiledFunction::cfsa: Argument x at position 1 should be a machine-size real number. >>
0.575516
Any idea why? It's the first time I use Compile so I might be missing obvious!
Xavier
Update. I've tried using N but get the same error message. How do I fix that?
rC= NProbability[derivativeStrategyLongStraddleCompiled[N[x], 39, 2.38, 0.02] >= 0,
x \[Distributed] NormalDistribution[41.57339177753672`, 0.9105010291072763`]]
"RuntimeOptions -> {"EvaluateSymbolically" -> False}
and it adds more error messages, so really doesn't fix my problem. I've tried"RuntimeOptions -> {"WarningMessages"->False}
and removes the error message but doesn't fix the problem. Any other ideas? $\endgroup$