Risiswaper
Risiswaper

Reputation: 21

QuantLib Vanilla Swap Pricing with Python - Error

I have the project to build my own Vanilla Swap Pricer using QuantLib. I would like to compute from market prices of ois swap for discounting, and Euribor 6M swap + FRA for projecting fixing.

To summary, my objective to get as close as possible of Bloomberg to price a standard Euribor 6M Swap (discounting ois - fwd Euribor 6M).

Well to start easily I got the doc of QuantLib but when following exactly this piece of code I have an error...

https://quantlib-python-docs.readthedocs.io/en/latest/examples/fixedincome/vanillaswap.html

Error is the following:

TypeError: MakeVanillaSwap() got an unexpected keyword argument 'Nominal'

I would really appreciate your help as I am stuck at the very first step of my project....

I tried to remove the nominal, so it's working with a 1 default value I think but I don't know where should I input the nominal.

Upvotes: 2

Views: 202

Answers (1)

steve16351
steve16351

Reputation: 5812

The documentation appears to be incorrect for the current version of QuantLib at least.

Inspecting the source for MakeVanillaSwap (https://github.com/lballabio/QuantLib-SWIG/blob/master/SWIG/swap.i) shows a lookup of argument names to a corresponding method name that is invoked on the Python swig wrapper class for the C++ QuantLib swap object:

_MAKEVANILLA_METHODS = {
    "receiveFixed": "receiveFixed",
    "swapType": "withType",
    "nominal": "withNominal",
    "settlementDays": "withSettlementDays",
    "effectiveDate": "withEffectiveDate",
    "terminationDate": "withTerminationDate",
    "dateGenerationRule": "withRule",
    "paymentConvention": "withPaymentConvention",
    "fixedLegTenor": "withFixedLegTenor",
    "fixedLegCalendar": "withFixedLegCalendar",
    "fixedLegConvention": "withFixedLegConvention",
    "fixedLegTerminationDateConvention": "withFixedLegTerminationDateConvention",
    "fixedLegDateGenRule": "withFixedLegRule",
    "fixedLegEndOfMonth": "withFixedLegEndOfMonth",
    "fixedLegFirstDate": "withFixedLegFirstDate",
    "fixedLegNextToLastDate": "withFixedLegNextToLastDate",
    "fixedLegDayCount": "withFixedLegDayCount",
    "floatingLegTenor": "withFloatingLegTenor",
    "floatingLegCalendar": "withFloatingLegCalendar",
    "floatingLegConvention": "withFloatingLegConvention",
    "floatingLegTerminationDateConvention": "withFloatingLegTerminationDateConvention",
    "floatingLegDateGenRule": "withFloatingLegRule",
    "floatingLegEndOfMonth": "withFloatingLegEndOfMonth",
    "floatingLegFirstDate": "withFloatingLegFirstDate",
    "floatingLegNextToLastDate": "withFloatingLegNextToLastDate",
    "floatingLegDayCount": "withFloatingLegDayCount",
    "floatingLegSpread": "withFloatingLegSpread",
    "discountingTermStructure": "withDiscountingTermStructure",
    "pricingEngine": "withPricingEngine",
    "withIndexedCoupons": "withIndexedCoupons",
    "atParCoupons": "withAtParCoupons",
}

So it is clear from this it is expecting Nominal in lowercase. Therefore simply changing the call to MakeVanillaSwap as below should make it work as expected.

swap = ql.MakeVanillaSwap(tenor, index, fixedRate, forwardStart, nominal=10e6, pricingEngine=engine)

Upvotes: 3

Related Questions