Skip to main content

Linear Rates Quantitative Library package for Python

Project description

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 IRS is either spot or forward starting.

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)

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)

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.

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)

Values the IRS using the yield curve.

Parameters:

  • yc (YieldCurve): An optional yield curve argument.

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}

License

MIT License - see LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

linerapy-0.1.2-cp314-cp314-win_amd64.whl (244.4 kB view details)

Uploaded CPython 3.14Windows x86-64

linerapy-0.1.2-cp314-cp314-manylinux_2_39_x86_64.whl (315.4 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.39+ x86-64

linerapy-0.1.2-cp313-cp313-win_amd64.whl (238.3 kB view details)

Uploaded CPython 3.13Windows x86-64

linerapy-0.1.2-cp313-cp313-manylinux_2_39_x86_64.whl (315.3 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.39+ x86-64

linerapy-0.1.2-cp312-cp312-win_amd64.whl (238.3 kB view details)

Uploaded CPython 3.12Windows x86-64

linerapy-0.1.2-cp312-cp312-manylinux_2_39_x86_64.whl (315.3 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.39+ x86-64

File details

Details for the file linerapy-0.1.2-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: linerapy-0.1.2-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 244.4 kB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for linerapy-0.1.2-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 01fc0b4c647ab674d73e674657747aafd8c84f2169b5fdf1d6701d0b14794b7c
MD5 50473965994b1076dd474b7dad6bf1ad
BLAKE2b-256 8617fe8f26ee73ee50db65b9bbd5663d8f84a3b7d70f08ee130e2085a329a58a

See more details on using hashes here.

File details

Details for the file linerapy-0.1.2-cp314-cp314-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for linerapy-0.1.2-cp314-cp314-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 c1b03d6db8aa1addb3789d0095347595e0f82abf8e1dc7d808feafb6967ed318
MD5 ec4b25fc23b89304c6caf168b5d28bd1
BLAKE2b-256 2875cb6380b409e87bb755cbfa76585c4997b3d989c30ec788121826b5793095

See more details on using hashes here.

File details

Details for the file linerapy-0.1.2-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: linerapy-0.1.2-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 238.3 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for linerapy-0.1.2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 02535f565d313839bc4304bf492b816e6c2cd44ba06b13f3ba2840f4a12ce8f1
MD5 996ab0ebb8e337be26e08cbb662288d2
BLAKE2b-256 3e83229499f5d13fdffa5a8ff790fd2d0e53cf5630b85611fd94f5f8214e7f6a

See more details on using hashes here.

File details

Details for the file linerapy-0.1.2-cp313-cp313-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for linerapy-0.1.2-cp313-cp313-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 adf194464ff949f2b4be2dac0f80c8e82140ef683cc312495d20ec7d5b07977e
MD5 5d96c199a4f98516a117b9bed2a1c2dc
BLAKE2b-256 a12880dc1cbea77879902cb076698f2ea336d0c373c8c844838e546297f73904

See more details on using hashes here.

File details

Details for the file linerapy-0.1.2-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: linerapy-0.1.2-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 238.3 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for linerapy-0.1.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 20ab1bb91204c0359b9b391a1cbcc7c04259deff58cf1bad9ec96490c797f119
MD5 04fbc79442677b843b75c5f92b85b388
BLAKE2b-256 cecbd9012cc9dda1933ab0af4f7dbca702449ef649ef02ca7048b78518d7d0de

See more details on using hashes here.

File details

Details for the file linerapy-0.1.2-cp312-cp312-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for linerapy-0.1.2-cp312-cp312-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 319e07593032cba4590f8a8dad743d532ebab22c1e8e2dbcd483f940e4886801
MD5 7aa8a89d21bd9381e37e4d2ded7ec9b4
BLAKE2b-256 51ba5e14d72664870d3c32b04147789f83f1d147cc864a0af9630f162d5006fd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page