# 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()

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!

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.