Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into refactor-splines
Browse files Browse the repository at this point in the history
  • Loading branch information
attack68 committed Jan 13, 2025
2 parents df80e88 + 1fc05a9 commit 3e88975
Show file tree
Hide file tree
Showing 59 changed files with 4,927 additions and 4,226 deletions.
4 changes: 2 additions & 2 deletions benchmarks/benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ def time_composite_curve_value_getting(self):
self.compcurve[_]

def clear_caches(self):
self.curve.clear_cache()
self.curve2.clear_cache()
self.curve._clear_cache()
self.curve2._clear_cache()

def time_curve_value_getting_no_cache(self):
with default_context("curve_caching", False):
Expand Down
6 changes: 0 additions & 6 deletions docs/source/c_fx_smile.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@
FX Vol Surfaces
*********************************

.. warning::

FX volatility products in *rateslib* are not in stable status. Their API and/or object
interactions *may* incur breaking changes in upcoming releases as they mature and other
classes or pricing models may be added.

The ``rateslib.fx_volatility`` module includes classes for *Smiles* and *Surfaces*
which can be used to price *FX Options* and *FX Option Strategies*.

Expand Down
15 changes: 10 additions & 5 deletions docs/source/i_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ Defaults
:skip: datetime
:skip: Enum
:skip: read_csv
:skip: get_named_calendar
:skip: Cal
:skip: NamedCal
:skip: Series
:skip: UnionCal
:skip: Callable
:skip: ParamSpec
:skip: TypeVar

Calendars
==========
Expand Down Expand Up @@ -159,10 +161,11 @@ FX Volatility
.. automodapi:: rateslib.fx_volatility
:no-heading:
:no-inheritance-diagram:
:skip: Any
:skip: Variable
:skip: set_order_convert
:skip: dual_exp
:skip: dual_inv_norm_cdf
:skip: DualTypes
:skip: Dual
:skip: Dual2
:skip: dual_norm_cdf
Expand All @@ -188,10 +191,11 @@ Link to the :ref:`Periods<periods-doc>` section in the user guide.

.. automodapi:: rateslib.periods
:no-heading:
:skip: Any
:skip: Sequence
:skip: Index
:skip: NoInput
:skip: ABCMeta
:skip: IndexCurve
:skip: Variable
:skip: MultiIndex
:skip: Curve
Expand All @@ -200,8 +204,6 @@ Link to the :ref:`Periods<periods-doc>` section in the user guide.
:skip: Dual2
:skip: FXRates
:skip: FXForwards
:skip: LineCurve
:skip: CompositeCurve
:skip: Series
:skip: datetime
:skip: comb
Expand Down Expand Up @@ -236,6 +238,9 @@ Solver

.. automodapi:: rateslib.solver
:no-heading:
:skip: Callable
:skip: Curve
:skip: ParamSpec
:skip: MultiCsaCurve
:skip: NoInput
:skip: FXRates
Expand Down
2 changes: 1 addition & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ ticket in Bloomberg for reference point.
ust = FixedRateBond(
effective=dt(2023, 8, 15), termination=dt(2033, 8, 15),
fixed_rate=3.875, spec="ust"
fixed_rate=3.875, spec="us_gb"
) # Create a US-Treasury bond
ust.price(ytm=4.0, settlement=dt(2025, 2, 14))
ust.duration(ytm=4.0, settlement=dt(2025, 2, 14), metric="risk")
Expand Down
4 changes: 4 additions & 0 deletions docs/source/u_dual.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ Methods
rateslib.dual.dual_norm_cdf
rateslib.dual.dual_inv_norm_cdf
rateslib.dual.dual_solve
rateslib.dual.newton_1dim
rateslib.dual.newton_ndim
rateslib.dual.quadratic_eqn


Example
*******
Expand Down
25 changes: 18 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ docstring-code-format = false

[tool.ruff.lint]
select = [
# "ANN", # flake8-annotations -- Superceded by the use of mypy
# "COM", # flake8-commas -- conflicts with ruff format
"E", # pycodestyle
"W",
"F", # Pyflakes
Expand All @@ -110,17 +112,17 @@ select = [
"C4", # flake8-comprehensions
"S", # flake8-bandit
"PIE", # flake8-pie
# "ANN", # flake8-annotations -- Requires work
# "A", # flake8-builtins -- Requires work
# "COM", # flake8-commas -- conflicts with ruff format
"A", # flake8-builtins
"Q", # flake8-quotes
"PT", # flake8-pytest-style
# "C90", # mccabe complexity -- Requires work
"C90", # mccabe complexity -- Requires work
"I", # isort
"N", # pep8 naming
# "RUF", # -- Requires work
# "D", Pydocs -- requires work
]
ignore = [
"A005", # json and typing module name shadowing is allowed
"PT011", # -- Requires work inputting match statements
"PIE790", # unnecessary pass
"C408", # unnecessary dict call
Expand All @@ -135,15 +137,24 @@ ignore = [

[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["E402", "N801"]
"python/tests/*" = ["F401", "B", "N", "S", "ANN"]
"typing.py" = ["E501"]
"python/tests/*" = ["F401", "B", "N", "S", "ANN", "D"]
"rust/*" = ["D"]

[tool.ruff.lint.mccabe]
# Flag errors (`C901`) whenever the complexity level exceeds 5.
max-complexity = 14

[tool.mypy]
packages = [
"rateslib"
]
exclude = [
"/instruments",
"fx_volatility.py",
"/instruments/bonds/securities.py",
"/instruments/fx_volatility.py",
"/instruments/generics.py",
"/instruments/rates/inflation.py",
"/instruments/rates/multi_currency.py",
"solver.py",
]
strict = true
Expand Down
2 changes: 1 addition & 1 deletion python/rateslib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def __exit__(self, *args) -> None: # type: ignore[no-untyped-def]
It aims to be the fundamental high-level building block for practical analysis of
fixed income securities, derivatives, FX representation and curve construction
in Python.
"""
""" # noqa: A001

# Use __all__ to let type checkers know what is part of the public API.
# Rateslib is not (yet) a py.typed library: the public API is determined
Expand Down
15 changes: 11 additions & 4 deletions python/rateslib/calendars/__init__.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
from __future__ import annotations

import calendar as calendar_mod
from collections.abc import Callable
from datetime import datetime
from typing import TYPE_CHECKING

from rateslib.calendars.dcfs import _DCF
from rateslib.calendars.rs import (
CalInput,
CalTypes,
_get_modifier,
_get_rollday,
get_calendar,
)
from rateslib.default import NoInput, _drb
from rateslib.rs import Cal, Modifier, NamedCal, RollDay, UnionCal

if TYPE_CHECKING:
from rateslib.typing import CalInput

# Licence: Creative Commons - Attribution-NonCommercial-NoDerivatives 4.0 International
# Commercial use of this code, and/or copying and redistribution is prohibited.
# Contact rateslib at gmail.com if this code is observed outside its intended sphere.
Expand Down Expand Up @@ -584,11 +587,15 @@ def _get_fx_expiry_and_delivery(
return expiry_, delivery_


_IS_ROLL: dict[str, Callable[..., bool]] = {
"eom": _is_eom,
"som": _is_som,
"imm": _is_imm,
}

__all__ = (
"add_tenor",
"Cal",
"CalInput",
"CalTypes",
"create_calendar",
"dcf",
"Modifier",
Expand Down
27 changes: 15 additions & 12 deletions python/rateslib/calendars/dcfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

import calendar as calendar_mod
import warnings
from collections.abc import Callable
from datetime import datetime
from typing import TYPE_CHECKING

from rateslib.calendars.rs import CalInput, _get_modifier, _get_rollday, get_calendar
from rateslib.calendars.rs import _get_modifier, _get_rollday, get_calendar
from rateslib.default import NoInput
from rateslib.rs import Convention

if TYPE_CHECKING:
from rateslib.typing import Any, CalInput, Callable

CONVENTIONS_MAP: dict[str, Convention] = {
"ACT365F": Convention.Act365F,
"ACT365F+": Convention.Act365FPlus,
Expand Down Expand Up @@ -38,11 +41,11 @@ def _get_convention(convention: str) -> Convention:
raise ValueError(f"`convention`: {convention}, is not valid.")


def _dcf_act365f(start: datetime, end: datetime, *args) -> float: # type: ignore[no-untyped-def]
def _dcf_act365f(start: datetime, end: datetime, *args: Any) -> float:
return (end - start).days / 365.0


def _dcf_act365fplus(start: datetime, end: datetime, *args) -> float: # type: ignore[no-untyped-def]
def _dcf_act365fplus(start: datetime, end: datetime, *args: Any) -> float:
"""count the number of the years and then add a fractional ACT365F period."""
if end <= datetime(start.year + 1, start.month, start.day):
return _dcf_act365f(start, end)
Expand All @@ -53,28 +56,28 @@ def _dcf_act365fplus(start: datetime, end: datetime, *args) -> float: # type: i
return years + _dcf_act365f(datetime(end.year - 1, start.month, start.day), end)


def _dcf_act360(start: datetime, end: datetime, *args) -> float: # type: ignore[no-untyped-def]
def _dcf_act360(start: datetime, end: datetime, *args: Any) -> float:
return (end - start).days / 360.0


def _dcf_30360(start: datetime, end: datetime, *args) -> float: # type: ignore[no-untyped-def]
def _dcf_30360(start: datetime, end: datetime, *args: Any) -> float:
ds = min(30, start.day)
de = min(ds, end.day) if ds == 30 else end.day
y, m = end.year - start.year, (end.month - start.month) / 12.0
return y + m + (de - ds) / 360.0


def _dcf_30e360(start: datetime, end: datetime, *args) -> float: # type: ignore[no-untyped-def]
def _dcf_30e360(start: datetime, end: datetime, *args: Any) -> float:
ds, de = min(30, start.day), min(30, end.day)
y, m = end.year - start.year, (end.month - start.month) / 12.0
return y + m + (de - ds) / 360.0


def _dcf_30e360isda( # type: ignore[no-untyped-def]
def _dcf_30e360isda(
start: datetime,
end: datetime,
termination: datetime | NoInput,
*args,
*args: Any,
) -> float:
if isinstance(termination, NoInput):
raise ValueError("`termination` must be supplied with specified `convention`.")
Expand All @@ -91,7 +94,7 @@ def _is_end_feb(date: datetime) -> bool:
return y + m + (de - ds) / 360.0


def _dcf_actactisda(start: datetime, end: datetime, *args) -> float: # type: ignore[no-untyped-def]
def _dcf_actactisda(start: datetime, end: datetime, *args: Any) -> float:
if start == end:
return 0.0

Expand Down Expand Up @@ -240,11 +243,11 @@ def _dcf_actacticma_stub365f(
return d_


def _dcf_1(*args) -> float: # type: ignore[no-untyped-def]
def _dcf_1(*args: Any) -> float:
return 1.0


def _dcf_1plus(start: datetime, end: datetime, *args) -> float: # type: ignore[no-untyped-def]
def _dcf_1plus(start: datetime, end: datetime, *args: Any) -> float:
return end.year - start.year + (end.month - start.month) / 12.0


Expand Down
Loading

0 comments on commit 3e88975

Please sign in to comment.