So I have created a Swaption object and can get the premium with the NPV() function. However, I would also like to calculate the greeks (eg. delta, vega).

From some searching, I found that vega can be extracted from the additionalResults () function of the instrument class, but it doesn't seem to be defined for the Python version of Quantlib.

For example, let swaption be an initialized instance of a Swaption object.

swaption.NPV() gives me the value as expected, but swaption.additionalResults() and swaption.result("Vega") are not defined.

http://cogitolearning.co.uk/?p=490 This link shows the c++ analogue of these functions.

Otherwise, how could I calculate these values? I'm not sure if BlackCalculator is appropriate for these calculations on a swaption.


1 Answer 1


Neither the additionalResults nor the result method are exported to Python via SWIG. This is unlikely to change in the future: result is a template method, and it can't be exported to Python as such, whereas additionalResults would require a sensible way to export boost::any to Python and to convert it to a given data type.

If you can recompile the QuantLib Python module, though, you can add to the Swaption class a vega method that makes the call you cite in the link. Edit swaption.i in the QuantLib-SWIG distribution and add

Real vega() {
    return self->result<Real>("vega");

to the %extend section of the Swaption interface (self is a variable used by SWIG to denote the current object, as in Python). This will add a vega method to the Python wrapper that executes the call above.

(A note: when you get it running, please consider opening a pull request with your change for the QuantLib-SWIG repository on Github.)


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.