linerapy
A quantitative libary for linear interest rates - LineRaPy (Pronunciation: /ˈlɪniər paɪ/). The package introduces two types related to the linear rates: YieldCurve and IRS. The YieldCurve can be constructed using the key rates, e.g. tenors and values. The IRS is constructed from the dictionary.
The object of type YieldCurve can be queries for dates and zero rates. The object of type IRS can be queries for price and cash flows.
The library currently supports US, USGS calendars and a vanilla IRS paying compounded SOFR vs fixed rate.
The library supports USD, EUR, GBP, SGD, JPY and CHF currencies. The corresponding generators are:
- USD SOFR SW
- GBP SONIA SW
- EUR ESTR SW
- SGD SORA SW
- JPY TONA SW
- CHF SARON SW
The valid calendars are US, USSG, EN, TG, SG, JP and CH. Here TG is the TARGET2 calendar. Supported day count conventions are
- ACT/360
- ACT/365F
- ACT/ACT
- 30/360
- 30E/360
To price the swap where the coupon already had started compounding, the user needs to provide the fixings. The user should first check the swap object for required fixing dates and provide the rate fixings for those dates.
The curve implements two interpolation methods
- LinearLogDf
- LinearRates
By default the LinearLogDf method is used.
Requirements
- Python 3.12+
- Windows / Linux
Installation
pip install linerapy
Usage
import linerapy
import datetime
import pandas as pd
if __name__ == '__main__':
obj_dict = {
'id': 'USD SOFR',
'value date': datetime.date(2026, 3, 20),
'currency': 'USD',
'instruments': {
'generator': ['USD SOFR SW', 'USD SOFR SW', 'USD SOFR SW', 'USD SOFR SW'],
'tenor': ['1M', '1Y', '5Y', '10Y'],
'quote': [3.65, 3.65, 3.65, 3.65],
'in use': [True, True, True, True]
}
}
yield_curve = linerapy.YieldCurve(obj_dict)
print('Discount Factor:', yield_curve.df(datetime.date(2027, 3, 20)))
df = pd.DataFrame.from_dict({
'Date': yield_curve.dates(),
'Zero Rate': yield_curve.rates(),
'Discount Factor': [yield_curve.df(d) for d in yield_curve.dates()]})
print(df)
The IRS can be created from the dictionary by providing the necessary input.
obj_dict = {
'id': 'IRS_001',
'effective date': datetime.date(2026, 3, 24),
'termination date': datetime.date(2031, 3, 24),
'schedule roll': 'Backward',
'leg1': {
'currency': 'USD',
'notional': 10000,
'is fixed': True,
'is paid': True,
'rate': 0.0365,
'calendar': 'US',
'frequency': '6M',
'day count convention': 'ACT/360',
'pay lag': 2,
'accrual adjustment': 'Modified Following',
'accrual calendar': 'US',
'pay adjustment': 'Modified Following',
'pay calendar': 'US'
},
'leg2': {
'currency': 'USD',
'notional': 10000,
'is fixed': False,
'is paid': False,
'index': 'SOFR',
'margin': 0.0025,
'calendar': 'USD',
'frequency': '3M',
'day count convention': 'ACT/360',
'pay lag': 2,
'accrual adjustment': 'Modified Following',
'accrual calendar': 'US',
'pay adjustment': 'Modified Following',
'pay calendar': 'US'
}
}
irs = linerapy.IRS(obj_dict)
npv = irs.price(yield_curve)
print(npv)
pd.set_option('display.max_columns', None)
pd.set_option('display.width', None)
cf = irs.cashflows(yield_curve)
df = pd.DataFrame.from_dict(cf['Leg1'])
print(df)
df = pd.DataFrame.from_dict(cf['Leg2'])
print(df)
First request the fixing dates from the swap. Note that the valuation date is to be passed to the method.
fixings = irs.required_fixings(datetime.date(2026, 4, 10))
Then pass the fixings to the price or cashflow method of the the swap.
fixings_data = { 'SOFR':
{
'dates': fixings['SOFR'],
'values': [0.02 for d in fixings['SOFR']]
}
}
cf = irs.cashflows(yield_curve2, fixings_data)
pvs = irs.price(yield_curve2, fixings_data)
Similarly, the first order Greeks can be calculated:
pv01 = irs.risk(yield_curve, fixings_data)
pv01_df = pd.DataFrame.from_dict(pv01)
print(pv01_df)
API Reference
dates()
Returns the yield curve's dates.
Returns:
list: List of dates.
Example:
>>> yield_curve_.dates()
[datetime.date(2026, 4, 28), datetime.date(2026, 9, 28), datetime.date(2027, 3, 26), datetime.date(2028, 3, 28)]
rates()
Returns the zero rates corresponding to the yield curve's dates.
Returns:
list: List of zero rates.
Example:
>>> yield_curve_.rates()
[0.03694890857811573, 0.0366704955510695, 0.03634333943914385, 0.03634104468177242]
cashflows(yc, fixings)
Returns leg-wise cash flows. If the yield curve argument provided, the forward rates are estimated and the cash flows are projected.
Parameters:
yc(YieldCurve): An optional yield curve argument.fixings(dict): An optional argument for fixings. If the trade has no past compounding dates, this argument is not required.
Returns:
dict: Dictionary of leg-wise cash flows.
Example:
>>> irs.cashflows(yield_curve)
Accrual Start Date Accrual End Date Payment Date Day Count Fraction Rate Notional Cash Flow Discount Factor Cash Flow PV
0 2026-03-24 2026-09-24 2026-09-28 0.511111 0.0365 10000.0 186.555556 0.981029 183.016423
1 2026-09-24 2027-03-24 2027-03-26 0.502778 0.0365 10000.0 183.513889 0.963732 176.858158
2 2027-03-24 2027-09-24 2027-09-28 0.511111 0.0365 10000.0 186.555556 0.946050 176.490961
3 2027-09-24 2028-03-24 2028-03-28 0.505556 0.0365 10000.0 184.527778 0.929063 171.438002
4 2028-03-24 2028-09-25 2028-09-27 0.513889 0.0365 10000.0 187.569444 0.912291 171.117831
5 2028-09-25 2029-03-26 2029-03-28 0.505556 0.0365 10000.0 184.527778 0.895910 165.320226
6 2029-03-26 2029-09-24 2029-09-26 0.505556 0.0365 10000.0 184.527778 0.879823 162.351780
7 2029-09-24 2030-03-25 2030-03-27 0.505556 0.0365 10000.0 184.527778 0.864025 159.436635
8 2030-03-25 2030-09-24 2030-09-26 0.508333 0.0365 10000.0 185.541667 0.848426 157.418456
9 2030-09-24 2031-03-24 2031-03-26 0.502778 0.0365 10000.0 183.513889 0.833275 152.917586
price(yc, fixings)
Values the IRS using the yield curve.
Parameters:
yc(YieldCurve): A yield curve argument.fixings(dict): An optional fixings argument. It is only required if the swap has past dates on which it compounds the coupon.
Returns:
dict: Dictionary of leg-wise PV and the total NPV.
Example:
>>> npv = irs.price(yield_curve)
{'Leg1 PV': -1676.3660572375327, 'Leg2 PV': 1776.4412024912517, 'NPV': 100.07514525371903}
risk(yc, fixings)
Calculates PV01 for each key rate of the yield curve. The results are leg-wise and the netted value. The sensitivities are calculated for 1bp change. The direction of the leg, e.g. pay or receive, is taken into account when the value is return.
Parameters:
yc(YieldCurve): A yield curve argument.fixings(dict): An optional fixings argument. It is only required if the swap has past dates on which it compounds the coupon.
Returns:
dict: Dictionary of leg-wise PV01 and the Net PV01 for each key rate.
Example:
>>> pv01 = irs.risk(yield_curve, fixings_data)
Tenor Leg1 Leg2 Net
0 1M 0.200487 0.176671 0.377158
1 1Y 7.746666 -6.930656 0.816010
2 5Y 0.000000 0.000000 0.000000
3 10Y 0.000000 0.000000 0.000000
License
MIT License - see LICENSE for details.
Metadata
Release files for linerapy 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| linerapy-0.3.0-cp314-cp314-win_amd64.whl | CPython 3.14 | CPython 3.14 | Windows x86-64 | Details |
| linerapy-0.3.0-cp314-cp314-manylinux_2_39_x86_64.whl | CPython 3.14 | CPython 3.14 | Linux glibc 2.39+ x86-64 | Details |
| linerapy-0.3.0-cp313-cp313-win_amd64.whl | CPython 3.13 | CPython 3.13 | Windows x86-64 | Details |
| linerapy-0.3.0-cp313-cp313-manylinux_2_39_x86_64.whl | CPython 3.13 | CPython 3.13 | Linux glibc 2.39+ x86-64 | Details |
| linerapy-0.3.0-cp312-cp312-win_amd64.whl | CPython 3.12 | CPython 3.12 | Windows x86-64 | Details |
| linerapy-0.3.0-cp312-cp312-manylinux_2_39_x86_64.whl | CPython 3.12 | CPython 3.12 | Linux glibc 2.39+ x86-64 | Details |
Total release size: 1.9 MB
Release files / linerapy-0.3.0-cp314-cp314-win_amd64.whl
| Download URL | linerapy-0.3.0-cp314-cp314-win_amd64.whl |
|---|---|
| Size | 283.4 kB |
| Tags | CPython 3.14 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
c79d9e0b0b3fced0c2f0d4786748dd81bfd1dfe8a6564c242f8bbe9de7a99155
|
|
BLAKE2b-256 checksum How to use checksums |
1ba853acb59373f79871e5d202f7820f0da8996cb49cb865bd8904a70c9dbdf4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.3
|
Release files / linerapy-0.3.0-cp314-cp314-manylinux_2_39_x86_64.whl
| Download URL | linerapy-0.3.0-cp314-cp314-manylinux_2_39_x86_64.whl |
|---|---|
| Size | 355.2 kB |
| Tags | CPython 3.14 Linux glibc 2.39+ x86-64 |
|
SHA-256 checksum How to use checksums |
a285b859d2ed5cbea4b292af4eefc4fba97033c59f118c77a4d2fd36e75e1bc7
|
|
BLAKE2b-256 checksum How to use checksums |
1ba5bb74caaa0f36ace3f1dda8e8000a23bef7bc47da86d2410593aaea55bd75
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.3
|
Release files / linerapy-0.3.0-cp313-cp313-win_amd64.whl
| Download URL | linerapy-0.3.0-cp313-cp313-win_amd64.whl |
|---|---|
| Size | 275.7 kB |
| Tags | CPython 3.13 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
b3f1742e7a9160a1ba8582af08dbeef9ca5eba805ee4303d841e624c5c366d23
|
|
BLAKE2b-256 checksum How to use checksums |
03cf3c67a78443d35f966c5704d44b9f34b0097b116b8ec98c9be8a24f2584a2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.3
|
Release files / linerapy-0.3.0-cp313-cp313-manylinux_2_39_x86_64.whl
| Download URL | linerapy-0.3.0-cp313-cp313-manylinux_2_39_x86_64.whl |
|---|---|
| Size | 355.1 kB |
| Tags | CPython 3.13 Linux glibc 2.39+ x86-64 |
|
SHA-256 checksum How to use checksums |
7fed6acc9f4ab2552d92dd074679b33dd3c33668ed261a26ef907cd539a68fef
|
|
BLAKE2b-256 checksum How to use checksums |
0cd183edd2f467fd009950f547c09d3de933edb3fd5cc04d5c3ee10fd04716f8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.3
|
Release files / linerapy-0.3.0-cp312-cp312-win_amd64.whl
| Download URL | linerapy-0.3.0-cp312-cp312-win_amd64.whl |
|---|---|
| Size | 275.7 kB |
| Tags | CPython 3.12 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
3ec587545dec8089989b5e53b4bbdab8e0747cc7d4dd432f44aea1a66135c4d5
|
|
BLAKE2b-256 checksum How to use checksums |
f9769070eea5f2c19ca9be29ff399418f34cd82318a371e422cacee13f9c7f7f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.3
|
Release files / linerapy-0.3.0-cp312-cp312-manylinux_2_39_x86_64.whl
| Download URL | linerapy-0.3.0-cp312-cp312-manylinux_2_39_x86_64.whl |
|---|---|
| Size | 355.1 kB |
| Tags | CPython 3.12 Linux glibc 2.39+ x86-64 |
|
SHA-256 checksum How to use checksums |
cd7e7bf1b57410adaaa4a0aba9fb48d603b25fbdc32862fd31fd5db01db27068
|
|
BLAKE2b-256 checksum How to use checksums |
3426e2927e7246ae1d29e0924204c6540dfb79b619ae158bc32e8ca7edf56d61
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.3
|
Security for linerapy 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.