0
$\begingroup$

I am trying to construct and price the zero coupon swap. However its giving me the AttributeError: module 'Quantlib' has no attribute 'ZeroCouponSwap'. Please let me know how to price the zero coupon swap using below details.

# construct discount curve and libor curve

maturity = []
discountfactor = []
day_count = ql.Actual360()
calendar = ql.JointCalendar(ql.UnitedStates(), ql.UnitedKingdom())
yield_curve = ql.DiscountCurve(maturity, discountfactor, day_count, calendar)
yield_curve.enableExtrapolation()
curve_handle = ql.YieldTermStructureHandle(yield_curve)


# BRL index
 BRL_index = ql.OvernightIndex('cdi', 0, ql.BRLCurrency(), ql.Brazil(), ql.Business252())
notional = 10000000
fixed_rate = 0.025
fixed_leg_daycount = ql.Business252()
float_spread = 0.0
float_leg_daycount = ql.Business252()
payment frequency = ql.Once

# creating schedule for zero coupon swap

fixed_schedule = ql.MakeSchedule(EffectiveDate, terminationDate, ql.Once)

 float_schedule = ql.MakeSchedule (EffectiveDate, terminationDate, ql.Once, calendar, ql.ModifiedFollowing, False)


 swap = ql.ZeroCouponSwap(ql.Receiver, 1000000, fixed_schedule, 
                     fixed_rate, fixed_leg_daycount, curve_handle)

 engine = ql.DiscountingSwapEngine(yield_curve)
 swap.setPricingEngine(engine)
$\endgroup$
3
  • $\begingroup$ Related: quant.stackexchange.com/questions/77369 and quant.stackexchange.com/questions/65559 $\endgroup$ Commented Nov 21, 2023 at 20:09
  • $\begingroup$ @DimitriVulis Thanks for reply. But my question is not specific to BRL, instead, it is on zero coupon swap pricing. Let me know your thoughts on zero coupon swap $\endgroup$
    – John83
    Commented Nov 21, 2023 at 20:20
  • $\begingroup$ That error is pretty clear in Python. You cannot call ql.ZeroCouponSwap because it doesn't exist as an object. Have you got the wrong class? Is it an error in QL that it is not a publicly exposed class? $\endgroup$
    – Attack68
    Commented Nov 21, 2023 at 20:58

1 Answer 1

2
$\begingroup$

I am running QuantLib version 1.30 and it works for me. Here is the code I compiled to investigate as unfortunately yours did not work for me

import QuantLib as ql

# Set the reference date
ql.Settings.instance().evaluationDate = ql.Date(1, 1, 2022)

dfs = [1, 0.965, 0.94]  # discount factors
dates = [
    ql.Date(1, 1, 2022),
    ql.Date(1, 1, 2023),
    ql.Date(1, 1, 2024),
]  # maturity dates of the discount factors

day_counter = ql.Actual360()

# Create the discount curve
curve = ql.DiscountCurve(dates, dfs, day_counter)

# The curve will note be linked in case we want to update the quotes later on
ts_handle = ql.YieldTermStructureHandle(curve)

custom_index= ql.IborIndex(
    "MyIndex",
    ql.Period("3m"),
    0,
    ql.SEKCurrency(),
    ql.Sweden(),
    ql.ModifiedFollowing,
    False,
    ql.Actual360(),
    ts_handle,
)

start_date= ql.Date(3,2,2022)
end_date = ql.Date(3,6,2022)

swap = ql.ZeroCouponSwap(
    ql.Swap.Receiver,
    1000000,
    start_date,
    end_date,
    0.02,
    day_counter,
    custom_index,
    ql.Sweden(),
)

engine = ql.DiscountingSwapEngine(ts_handle)
swap.setPricingEngine(engine)
print(swap.NPV())

Which gives me the NPV -5090. As I have not previously worked with ZeroCouponSwap I used the following sources to investigate your issue:

  1. https://github.com/lballabio/QuantLib-SWIG/blob/master/SWIG/swap.i
  2. https://github.com/lballabio/QuantLib/blob/master/test-suite/zerocouponswap.cpp
$\endgroup$
6
  • $\begingroup$ Thanks for the input. I am using QuantLib 1.19. Is there any chance to get 1.30 QuantLib version using Conda? $\endgroup$
    – John83
    Commented Nov 21, 2023 at 23:45
  • 1
    $\begingroup$ Have you tried to update your conda package with the following command conda update quantlib else I suggest using pip: pip install QuantLib (pypi.org/project/QuantLib). $\endgroup$
    – Xiarpedia
    Commented Nov 22, 2023 at 8:33
  • $\begingroup$ thanks. I have 1.32 version now. As we know ZC swaps fixed payer pays single payment in maturity and float payer pays the interim payments till maturity. So in this case, where is frequency or schedule attribute for pricing this swap. $\endgroup$
    – John83
    Commented Nov 26, 2023 at 15:37
  • $\begingroup$ Xiarpedia . Any further inputs on my comments? $\endgroup$
    – John83
    Commented Nov 27, 2023 at 17:21
  • 1
    $\begingroup$ @ Xiarpedia. I have marked this answer correct and posted the new question. Please visit my other post to start a new conversation. $\endgroup$
    – John83
    Commented Nov 28, 2023 at 16:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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