1
$\begingroup$

I am looking at the Equity Option example of QuantLib: http://quantlib.org/reference/_equity_option_8cpp-example.html and more particularly the FDAmericanEngine. However, I am not interested in the point value of the Finite Difference evaluation that is provided by the NPV function, but rather the full value function, for all asset prices (in [x_min, x_max]) and times to maturity (in [0, T]) in some grid of times and asset prices that I can define.

Surely the Finite Difference solver produces the full value function on a mesh of points in order to produce point value, how can I access this value function?

$\endgroup$
1
$\begingroup$

QuantLib does give you the value function, but it's very well hidden. Also, it's only for $t=0$.

Once you have your option built and your finite-difference engine set, you can write for instance:

SampledCurve prices = option.result<SampledCurve>("priceCurve");
for (Size i=0; i<prices.size(); ++i)
    std::cout << prices.gridValue(i) << "\t" << prices.value(i) << "\n";

You can also retrieve the full grid or the full set of values at once; see the <ql/math/sampledcurve.hpp> header for the full interface available from the SampledCurve class.

Unfortunately, there's no reference for the values one can possibly retrieve from any given engine via the Instrument::result function; you'll have to look them up in the code for each engine.

$\endgroup$
  • $\begingroup$ Perhaps this is a stupid question, but I'll ask just to make sure: when you say I can only get T=0, you mean essentially that I can only get the values of the payoff function? $\endgroup$ – Yu-Ho Haeppoelae Aug 19 '16 at 0:23
  • $\begingroup$ No, the payoff would be the value at maturity. By value at $T=0$ I meant the present value of the option. (But you're right, I should have written $t=0$ instead. I'll edit the answer.) $\endgroup$ – Luigi Ballabio Aug 19 '16 at 5:55
  • $\begingroup$ So do I understand correctly: if I still insisted on solving the full value function on a mesh of maturities and using QuantLib for it, I'd have to specify the mesh, and run a sequence of solver calls, using the previous solver call's solution (value function) as the payoff for the next? $\endgroup$ – Yu-Ho Haeppoelae Aug 20 '16 at 19:42
  • $\begingroup$ Yes, that would work. $\endgroup$ – Luigi Ballabio Aug 20 '16 at 20:03
  • $\begingroup$ Would this work for FdBlackScholesBarrierEngine ? I'm trying to make it work but so far I can´t $\endgroup$ – Tulio Carnelossi Oct 15 '18 at 4:06
0
$\begingroup$

I think you mean the state of the simulation in all grid points?

QuantLib doesn't have anything to store all grid points, because that'd be very memory consuming. Instead, QuantLib updates an internal vector while doing rollback. You can always do the rollback yourself to any maturity, and save the vector to your own data structure.

$\endgroup$
  • $\begingroup$ I am not sure I would call the finite-difference timestepper a simulation, but yes. I probably would not need the state of the timestepper after each time step, but in a reasonably dense grid anyways, say a couple of thousand maturities. I don't think a couple of million numbers would be that memory consuming. The numbers are so inaccurate anyways that a single-precision would do the job. In any case I take it from you that it's best to look elsewher. $\endgroup$ – Yu-Ho Haeppoelae Aug 18 '16 at 5:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.