Skip to content
All library documents

Calculating Swap Rolldown Rates with RatesLib Curves

Article Quant Q&A · Author: barnslinger

Summary

The document addresses how to calculate a swap rate from a rolled curve in RatesLib. The questioner builds an EUR interest-rate curve from market quotes, solves for discount factors, and prices a swap at its initial start and maturity dates. They then roll the curve forward and pass it to the swap’s rate method, wondering whether the missing Solver argument makes the rolled calculation invalid.

The answer explains that the rolled Curve is supplied as the method’s positional curves argument, so the call is valid without explicitly passing a Solver. It also notes that the curve definition should include the relevant TARGET calendar. The discussion clarifies Python argument binding and the library’s curve input, but it does not assess whether the curve construction, market data, or resulting rolldown estimate is otherwise correct.

Key ideas

  • A rolled RatesLib Curve can be passed directly to the swap rate method.
  • The positional curve argument is interpreted as the curves parameter.
  • A Solver is not required for the rolled-curve call described.
  • The EUR curve setup should include the TARGET calendar.

Tags

Full text
# Calculating swap rolldown using the RatesLib Python Library


# Calculating swap rolldown using the RatesLib Python Library












The code I am using is below, pulling in swap curves from BBG and then using RatesLib to price the swaps.

```
from rateslib import *
import pandas as pd
from tia.bbg import LocalTerminal

today = dt.today()
start = add_tenor(today,"1Y","F",get_calendar("tgt"))
mat = add_tenor(start,"1Y","F",get_calendar("tgt"))

curves = {
    'EUR':'514', 
}
curve_ids = []

for ccy, curve in curves.items():
    curve_id = 'YCSW' + curve.zfill(4) + ' Index'
    curve_ids.append(curve_id)
resp = LocalTerminal.get_reference_data(curve_ids, 'CURVE_TENOR_RATES')
df = resp.as_frame()
tenors = df['CURVE_TENOR_RATES'].iloc[0]['Tenor'].to_list()
rates = df['CURVE_TENOR_RATES'].iloc[0]['Mid Yield'].to_list()

data = pd.DataFrame({"Term": tenors,
                     "Rate":rates})

data["Termination"] = [add_tenor(today, _, "F", "tgt") for _ in data["Term"]]

ESTR = Curve(
    id="ESTR",
    convention = defaults.spec["eur_irs"]['convention'],
    modifier = defaults.spec["eur_irs"]['modifier'],
    interpolation="log_linear",
    nodes={
        **{today: 1.0},
        **{_: 1.0 for _ in data["Termination"]},
    }
)

estr_args = dict(spec="eur_irs", curves="ESTR")

solver = Solver(
    curves=[ESTR],
    instruments=[IRS(termination=_,effective=today, **estr_args) for _ in data["Termination"]],
    s=data["Rate"],
    instrument_labels=data["Term"],
    id="eur_rates",
)

data["DF"] = [float(ESTR[_]) for _ in data["Termination"]]

irs = IRS(
    effective= start ,
    termination=mat,
    notional=-10e6,
    **estr_args
)

swap_rate = float(irs.rate(solver=solver))
print(swap_rate)

rolled_swap_rate = float(irs.rate(ESTR.roll("3m")))

print(rolled_swap_rate)
```

This doesn't feel right, as i'm not passing in a solver when calculating the rate of the 'rolled_swap_rate', which is what is written in the best practices in the docs, however the result is pretty close to what i would expect.

Does anyone see any errors in this code that they could point out? would be v helpful!

## Answer by Attack68 (score 4, accepted)

https://quant.stackexchange.com/a/79774

Your question seems restricted only to the lines:

```
swap_rate = float(irs.rate(solver=solver))
print(swap_rate)
rolled_swap_rate = float(irs.rate(ESTR.roll("3m")))
```

with the comment that you are not passing a `Solver`. That's OK, you are passing a `Curve`. Python is actually interpreting this (via positional arguments) as equivalent to:

```
rolled_swap_rate = float(irs.rate(curves=ESTR.roll("3m")))
```

The `roll` method returns a new `Curve` so this is all valid.

The part of docs that explains this is here

Btw you should add the "tgt" `calendar` to your ESTR curve definintion.

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.