Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions .github/workflows/ubuntu-latest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Ubuntu latest

on:
push:
branches: [ "dev" ]
pull_request:
branches: [ "dev" ]

jobs:
build:

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.14"]

steps:
- uses: actions/checkout@v4
- name: Set up Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Rust linting checks
run: |
cargo fmt --check
- name: Rust library tests
run: |
cargo test --lib
- name: Rust doc tests
run: |
cargo test --doc
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install .[dev] -v
- name: Python Ruff linting
run: |
ruff check
- name: Python Ruff formatting
run: |
ruff format --check
- name: Python typing with Mypy
run: |
mypy --config-file pyproject.toml
- name: Test with pytest and display Coverage
run: |
coverage run -m --source=rateslib pytest
coverage report -m
36 changes: 36 additions & 0 deletions .github/workflows/ubuntu-minimum.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Ubuntu minimum

on:
push:
branches: [ "dev" ]
pull_request:
branches: [ "dev" ]

jobs:
build:

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.10"]

steps:
- uses: actions/checkout@v4
- name: Set up Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements-minimum.txt
pip install . -v
- name: Test with pytest
run: |
pytest
37 changes: 37 additions & 0 deletions .github/workflows/windows-latest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Windows latest

on:
push:
branches: [ "dev" ]
pull_request:
branches: [ "dev" ]

jobs:
build:

runs-on: windows-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.14"]
env:
MPLBACKEND: Agg # https://github.com/orgs/community/discussions/26434

steps:
- uses: actions/checkout@v4
- name: Set up Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install .[dev] -v
- name: Test with pytest
run: |
pytest
38 changes: 38 additions & 0 deletions .github/workflows/windows-minimum.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Windows minimum

on:
push:
branches: [ "dev" ]
pull_request:
branches: [ "dev" ]

jobs:
build:

runs-on: windows-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.10"]
env:
MPLBACKEND: Agg # https://github.com/orgs/community/discussions/26434

steps:
- uses: actions/checkout@v4
- name: Set up Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements-minimum.txt
pip install . -v
- name: Test with pytest
run: |
pytest
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ version = "2.5.dev0"
description = "A fixed income library for trading interest rates"
readme = "README.md"
authors = [{ name = "J H M Darbyshire"}]
license = { file = "LICENSE" }
license-files = ["LICEN[CS]E"]
keywords = ["interest rate", "derivatives", "swaps", "bonds", "fixed income"]
dependencies = [
"numpy>=1.21.5,<3.0",
Expand Down
17 changes: 11 additions & 6 deletions python/rateslib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def __exit__(self, *args) -> None: # type: ignore[no-untyped-def]
index_left,
index_value,
)
from rateslib.data.fixings import FXFixing, IBORFixing, IBORStubFixing, IndexFixing, RFRFixing
from rateslib.dual import ADOrder, Dual, Dual2, Variable, dual_exp, dual_log, dual_solve, gradient
from rateslib.enums.generics import NoInput
from rateslib.fx import FXForwards, FXRates
Expand Down Expand Up @@ -116,6 +117,8 @@ def __exit__(self, *args) -> None: # type: ignore[no-untyped-def]
FloatPeriod,
FXCallPeriod,
FXPutPeriod,
ZeroFixedPeriod,
ZeroFloatPeriod,
)
from rateslib.scheduling import (
Adjuster,
Expand Down Expand Up @@ -201,12 +204,12 @@ def __exit__(self, *args) -> None: # type: ignore[no-untyped-def]
"ProxyCurve",
"index_left",
"index_value",
# # analytic_fixings.py cannot load due to circular import
# "FXFixing",
# "IBORFixing",
# "IBORStubFixing",
# "IndexFixing",
# "RFRFixing",
# fixings.py
"FXFixing",
"IBORFixing",
"IBORStubFixing",
"IndexFixing",
"RFRFixing",
# fx_volatility.py
"FXDeltaVolSmile",
"FXDeltaVolSurface",
Expand All @@ -220,6 +223,8 @@ def __exit__(self, *args) -> None: # type: ignore[no-untyped-def]
# periods.py,
"FixedPeriod",
"FloatPeriod",
"ZeroFixedPeriod",
"ZeroFloatPeriod",
"Cashflow",
"FXCallPeriod",
"FXPutPeriod",
Expand Down
2 changes: 1 addition & 1 deletion python/rateslib/_spec_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def _get_kwargs(spec: str) -> dict[str, Any]:
d["roll"] = _map_str_int(d["roll"])
if "leg2_roll" in d:
d["leg2_roll"] = _map_str_int(d["leg2_roll"])
return d # type: ignore[return-value] # this is [Hashable, Any] not [str, Any]
return d # type: ignore[return-value]

INSTRUMENT_SPECS = {k: _get_kwargs(k) for k in df.columns[4:]}

Expand Down
5 changes: 5 additions & 0 deletions python/rateslib/curves/curves.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,11 @@ def index_value(
2.375% and the RFR index for that date was 100.73350964. Below we calculate
the value that was published for the RFR index on 7th Sep 2021 by the Riksbank.

.. ipython:: python
:suppress:

from rateslib import Curve, dt

.. ipython:: python

index_curve = Curve(
Expand Down
56 changes: 53 additions & 3 deletions python/rateslib/data/fixings.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
Result,
_BaseCurve_,
datetime_,
int_,
str_,
)

Expand Down Expand Up @@ -85,17 +86,53 @@ def __init__(
self._state = 0
self._date = date

def reset(self) -> None:
def reset(self, state: int_ = NoInput(0)) -> None:
"""
Sets the ``value`` attribute to :class:`rateslib.enums.generics.NoInput`, which allows it
to be redetermined from a timeseries.

.. rubric:: Examples

.. ipython:: python
:suppress:

from rateslib import fixings, dt, NoInput, FXFixing
from pandas import Series

.. ipython:: python

fx_fixing1 = FXFixing(date=dt(2021, 1, 1), pair="eurusd", identifier="A")
fx_fixing2 = FXFixing(date=dt(2021, 1, 1), pair="gbpusd", identifier="B")
fixings.add("A_eurusd", Series(index=[dt(2021, 1, 1)], data=[1.1]), state=100)
fixings.add("B_gbpusd", Series(index=[dt(2021, 1, 1)], data=[1.4]), state=200)

# data is populated from the available Series
fx_fixing1.value
fx_fixing2.value

# fixings are reset according to the data state
fx_fixing1.reset(state=100)
fx_fixing2.reset(state=100)

# only the private data for fixing1 is removed because of its link to the data state
fx_fixing1._value
fx_fixing2._value

.. role:: green

Parameters
----------
state: int, :green:`optional`
If given only fixings whose state matches this value will be reset. If no state is
given then the value will be reset.

Returns
-------
None
"""
self._value = NoInput(0)
self._state = 0
if isinstance(state, NoInput) or self._state == state:
self._value = NoInput(0)
self._state = 0

@property
def value(self) -> DualTypes_:
Expand Down Expand Up @@ -796,6 +833,13 @@ def value(self) -> DualTypes_:
)
return self._value

def reset(self, state: int_ = NoInput(0)) -> None:
if not isinstance(self._fixing1, NoInput):
self._fixing1.reset(state=state)
if not isinstance(self._fixing2, NoInput):
self._fixing2.reset(state=state)
self._value = NoInput(0)

@cached_property
def weights(self) -> tuple[float, float]:
"""Scalar multiplier to apply to each tenor fixing for the interpolation."""
Expand Down Expand Up @@ -1019,6 +1063,12 @@ def __init__(
self._method_param = method_param
self._populated = Series(index=[], data=[], dtype=float) # type: ignore[assignment]

def reset(self, state: int_ = NoInput(0)) -> None:
if isinstance(state, NoInput) or self._state == state:
self._populated = Series(index=[], data=[], dtype=float) # type: ignore[assignment]
self._value = NoInput(0)
self._state = 0

@property
def fixing_method(self) -> FloatFixingMethod:
"""The :class:`FloatFixingMethod` object used to combine multiple RFR fixings."""
Expand Down
Loading