1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//! This is the documentation for rateslib-rs
//!
//! <div class="warning">This library is in development. Only parts of *rateslib (Python)* have been ported
//! successfully, completely and with sound documentation to Rust.</div>

#![doc(html_favicon_url = "https://rateslib.readthedocs.io/en/stable/_static/favicon.ico")]
// #![doc(html_logo_url = "https://rateslib.readthedocs.io/en/stable/_static/rateslib_logo2a.png")]

#[cfg(test)]
mod tests;

pub mod json;
use crate::json::json_py::from_json_py;

// type GenericError = Box<dyn std::error::Error + Send + Sync + 'static>;
// type GenericResult<T> = Result<T, GenericError>;

use pyo3::prelude::*;

pub mod dual;
use dual::linalg_py::{dsolve1_py, dsolve2_py, fdsolve1_py, fdsolve2_py};
use dual::{ADOrder, Dual, Dual2};

pub mod splines;
use splines::spline_py::{
    bspldnev_single, bsplev_single, PPSplineDual, PPSplineDual2, PPSplineF64,
};

pub mod curves;
use curves::curve_py::Curve;
use curves::interpolation::interpolation_py::index_left_f64;
use curves::{
    FlatBackwardInterpolator, FlatForwardInterpolator, LinearInterpolator,
    LinearZeroRateInterpolator, LogLinearInterpolator, NullInterpolator,
};

pub mod calendars;
use calendars::calendar_py::get_calendar_by_name_py;
use calendars::{
    Cal, Convention, Modifier, NamedCal, RollDay, UnionCal, _get_convention_str, _get_modifier_str,
};

pub mod fx;
use fx::rates::ccy::Ccy;
use fx::rates::{FXRate, FXRates};

#[pymodule]
fn rs(m: &Bound<'_, PyModule>) -> PyResult<()> {
    // JSON
    m.add_function(wrap_pyfunction!(from_json_py, m)?)?;

    // Automatic Differentiation
    m.add_class::<Dual>()?;
    m.add_class::<Dual2>()?;
    m.add_class::<ADOrder>()?;
    m.add_function(wrap_pyfunction!(dsolve1_py, m)?)?;
    m.add_function(wrap_pyfunction!(dsolve2_py, m)?)?;
    m.add_function(wrap_pyfunction!(fdsolve1_py, m)?)?;
    m.add_function(wrap_pyfunction!(fdsolve2_py, m)?)?;

    // Splines
    m.add_class::<PPSplineF64>()?;
    m.add_class::<PPSplineDual>()?;
    m.add_class::<PPSplineDual2>()?;
    m.add_function(wrap_pyfunction!(bsplev_single, m)?)?;
    m.add_function(wrap_pyfunction!(bspldnev_single, m)?)?;

    // Curves
    m.add_class::<Curve>()?;
    m.add_function(wrap_pyfunction!(index_left_f64, m)?)?;
    m.add_class::<FlatBackwardInterpolator>()?;
    m.add_class::<FlatForwardInterpolator>()?;
    m.add_class::<LinearInterpolator>()?;
    m.add_class::<LogLinearInterpolator>()?;
    m.add_class::<LinearZeroRateInterpolator>()?;
    m.add_class::<NullInterpolator>()?;

    // Calendars
    m.add_class::<Cal>()?;
    m.add_class::<UnionCal>()?;
    m.add_class::<NamedCal>()?;
    m.add_class::<Modifier>()?;
    m.add_class::<RollDay>()?;
    m.add_class::<Convention>()?;
    m.add_function(wrap_pyfunction!(get_calendar_by_name_py, m)?)?;
    m.add_function(wrap_pyfunction!(_get_convention_str, m)?)?;
    m.add_function(wrap_pyfunction!(_get_modifier_str, m)?)?;

    // FX
    m.add_class::<Ccy>()?;
    m.add_class::<FXRate>()?;
    m.add_class::<FXRates>()?;

    Ok(())
}