|
From: steven e. p. <sha...@gm...> - 2010-11-05 23:03:06
|
hello;
I am trying to use the quantlib library from Matlab. As a test case, I
adapted the EquityOption.cpp example code from the quantlib webpage to a cpp
file which would generate the price of an American Put option with parameters
given by the user, using a few different pricing engines. Before writing the
mex, I had created a standalone version which accepted input from std::cin, and
this ran fine.
However, when I run the code from matlab, the results always come back as 0. I
do not know a lot about the guts of quantlib, and the lazy evaluation methods
being used. However, it seems that when I run the standalone, it takes about 1
second or so (there are some binomial lattice engines being used), whereas when
I run the mex file from matlab, it returns zeros instantaneously. I suspect
somehow that the << operator in the standalone (copied from EquityOption.cpp)
forces the option to be evaluated under the given engine, but this is not being
done in my matlab mex.
Am I wrong about this? Do I have to force evaluation somehow? As a snippet of
code, I have things like this in the mex:
americanOptionPut.setPricingEngine(boost::shared_ptr<PricingEngine>(
new BinomialVanillaEngine<JarrowRudd>(bsmProcess,timeSteps)));
P[iii] = (double)americanOptionPut.NPV(); //puts the results in the output
whereas in the standalone it looks more like:
americanOptionPut.setPricingEngine(boost::shared_ptr<PricingEngine>(
new BinomialVanillaEngine<JarrowRudd>(bsmProcess,timeSteps)));
std::cout << "the result is " << americanOptionPut.NPV() << std::endl;
any hints? thanks,
--sep
[ Steven E. Pav {bikes/bitters/linux} nerd ]
[ google voice: 909.SHBYCHF shabbychef a.t gmail d0t com ]
[ parent of tinyurl.com/oskarpix ]
[ a palindrome: wondered now ]
|