Retrieving American Option Values from QuantLib’s Finite Difference Engine
Summary
The document explains how to access values produced by QuantLib’s finite difference engine for an American equity option. The accepted answer describes retrieving a sampled price curve from the instrument’s results under the key “priceCurve.” This provides option values across the engine’s asset-price grid at the initial time, rather than a full surface across all asset prices and times. The sampled curve interface can expose the grid and its corresponding values.
The response cautions that available results are not comprehensively documented, so users may need to inspect the implementation of a particular engine to learn which results it exposes. A second answer says the engine updates an internal vector during rollback rather than retaining every grid state, partly to avoid the memory cost. To capture values at other times, a user can perform rollback and save the vector at chosen points. The document gives no complete example for that procedure, and access details may depend on the engine.
Key ideas
- QuantLib can expose a sampled option price curve through an instrument result.
- The retrieved curve represents values over the asset-price grid at time zero.
- The sampled curve interface provides access to grid points and values.
- Engine-specific result keys may require checking the implementation.
- Values at other times can be captured by rolling back and saving the internal vector.
Tags
Full text
# Full value function of an American option with QuantLib FD
# Full value function of an American option with QuantLib FD
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?
## Answer by Luigi Ballabio (score 1, accepted)
https://quant.stackexchange.com/a/29715
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.
## Answer by SmallChess (score 0)
https://quant.stackexchange.com/a/29678
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.Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.