Skip to content

Commit 5ac9bd2

Browse files
authored
Merge branch 'main' into cubic-spline
2 parents 6063837 + 1f9e8a2 commit 5ac9bd2

18 files changed

Lines changed: 99 additions & 275 deletions

File tree

Cargo.toml

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ rustdoc-args = ["--html-in-header", "katex.html", "--cfg", "docsrs"]
6868
RustQuant_autodiff = { version = "0.4.0", path = "crates/RustQuant_autodiff" }
6969
RustQuant_cashflows = { version = "0.4.0", path = "crates/RustQuant_cashflows" }
7070
RustQuant_data = { version = "0.4.0", path = "crates/RustQuant_data" }
71+
RustQuant_enums = { version = "0.4.0", path = "crates/RustQuant_enums" }
7172
RustQuant_error = { version = "0.4.0", path = "crates/RustQuant_error" }
7273
RustQuant_instruments = { version = "0.4.0", path = "crates/RustQuant_instruments" }
7374
RustQuant_iso = { version = "0.4.0", path = "crates/RustQuant_iso" }
@@ -117,17 +118,4 @@ polars = { version = "0.44.0", features = ["docs-selection"] }
117118
serde = { version = "1.0.213", features = ["derive"] }
118119

119120
# https://docs.rs/crate/pyo3/latest
120-
pyo3 = {version = "0.26.0", features = ["extension-module", "time"]}
121-
122-
## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
123-
## PYTHON BINDINGS
124-
## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
125-
126-
# [lib]
127-
# name = "RustQuant"
128-
# crate-type = ["cdylib"]
129-
130-
# [dependencies.pyo3]
131-
# version = "0.22.0"
132-
# features = ["extension-module"]
133-
# features = ["abi3-py37", "extension-module"]
121+
pyo3 = {version = "0.26.0", features = ["time"] }

bindings/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@ name = "RustQuant_pyo3"
33
version = "0.1.0"
44
edition = "2021"
55

6-
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
76
[lib]
87
name = "RustQuant"
98
crate-type = ["cdylib"]
109
path = "rust/lib.rs"
1110

1211
[dependencies]
1312
RustQuant = {path = "../crates/RustQuant"}
14-
pyo3 = {workspace = true}
15-
time = { workspace = true }
13+
pyo3 = { workspace = true }
14+
time = { workspace = true }

bindings/pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ build-backend = "maturin"
44

55
[project]
66
name = "RustQuant"
7+
dynamic = ["version"]
78
requires-python = ">=3.8"
89
classifiers = [
910
"Programming Language :: Rust",
1011
"Programming Language :: Python :: Implementation :: CPython",
1112
"Programming Language :: Python :: Implementation :: PyPy",
1213
]
13-
dynamic = ["version"]
14+
1415
[tool.maturin]
15-
features = ["pyo3/extension-module"]
1616
python-source = "python"
17+
features = ["pyo3/extension-module"]

bindings/testing.py

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
11
from pprint import pprint as print
22
from datetime import date
3+
34
from RustQuant.data import (
4-
SpotCurve,
5-
PyCurve,
5+
Curve,
66
CurveType,
77
InterpolationMethod,
88
)
99
from RustQuant.time import (
1010
Calendar,
1111
Market,
1212
)
13-
import RustQuant.data
14-
import RustQuant
1513

16-
RustQuant.data.SpotCurve.new()
17-
RustQuant.__dir__()
18-
RustQuant.data.__dir__()
1914

2015
dates = [
2116
date(2026, 1, 1),
@@ -32,7 +27,7 @@
3227
0.013,
3328
]
3429

35-
crv = PyCurve(dates, rates, CurveType.Spot, InterpolationMethod.Linear)
30+
crv = Curve(dates, rates, CurveType.Spot, InterpolationMethod.Linear)
3631
print(crv.get_rate(date(2026, 6, 1)))
3732

3833

@@ -44,14 +39,6 @@
4439
date(2026, 6, 5),
4540
]
4641

47-
curve = SpotCurve(dates, rates)
48-
print(curve.__dir__())
49-
50-
curve.plot()
51-
curve.get_rates(new_dates)
52-
53-
curve.fit()
54-
5542
cal = Calendar(Market.Australia)
5643
print(cal.__dir__())
5744
cal.market()

crates/RustQuant/Cargo.toml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@
77
## - LICENSE-MIT.md
88
## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
99

10-
## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11-
## GENERAL CONFIGURATION
12-
## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
13-
1410
[package]
1511
name = "RustQuant"
1612

@@ -35,12 +31,14 @@ workspace = true
3531
RustQuant_autodiff = { workspace = true }
3632
RustQuant_cashflows = { workspace = true }
3733
RustQuant_data = { workspace = true }
34+
RustQuant_enums = { workspace = true }
3835
RustQuant_error = { workspace = true }
3936
RustQuant_instruments = { workspace = true }
4037
RustQuant_iso = { workspace = true }
4138
RustQuant_math = { workspace = true }
4239
RustQuant_ml = { workspace = true }
4340
RustQuant_portfolios = { workspace = true }
41+
RustQuant_pricing = { workspace = true }
4442
RustQuant_stochastics = { workspace = true }
4543
RustQuant_time = { workspace = true }
4644
RustQuant_trading = { workspace = true }

crates/RustQuant_data/src/curves.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,31 @@ impl Curve {
182182
}
183183
}
184184

185+
/// Get a rate, and simultaneously add it to the nodes.
186+
pub fn get_rate_and_insert(&mut self, date: Date) -> Option<f64> {
187+
match self.nodes.get(&date) {
188+
Some(rate) => Some(*rate),
189+
None => {
190+
let rate = self.interpolator.interpolate(date).ok()?;
191+
self.nodes.insert(date, rate);
192+
Some(rate)
193+
}
194+
}
195+
}
196+
185197
/// Get multiple rates from the curve.
186198
pub fn get_rates(&self, dates: Vec<f64>) -> Vec<Option<f64>> {
187199
dates.iter().map(|date| self.get_rate(*date)).collect()
188200
}
189201

202+
/// Get multiple rates from the curve, and simultaneously add them to the nodes.
203+
pub fn get_rates_and_insert(&mut self, dates: Vec<Date>) -> Vec<Option<f64>> {
204+
dates
205+
.iter()
206+
.map(|date| self.get_rate_and_insert(*date))
207+
.collect()
208+
}
209+
190210
/// Set a rate in the curve.
191211
pub fn set_rate(&mut self, date: f64, rate: f64) {
192212
self.nodes.insert(OrderedFloat(date), rate);

crates/RustQuant_enums/Cargo.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[package]
2+
name = "RustQuant_enums"
3+
authors.workspace = true
4+
description.workspace = true
5+
version.workspace = true
6+
edition.workspace = true
7+
readme.workspace = true
8+
repository.workspace = true
9+
keywords.workspace = true
10+
categories.workspace = true
11+
license.workspace = true
12+
metadata.workspace = true
13+
14+
[dependencies]
15+
16+
[lints]
17+
workspace = true

crates/RustQuant_enums/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
//! RustQuant_enums crate.
2+
//!
3+
//! This crate is used solely to avoid circular dependencies
4+
//! between other crates in the RustQuant workspace.

crates/RustQuant_error/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ workspace = true
1717
[dependencies]
1818
thiserror = { workspace = true }
1919
rand_distr = { workspace = true }
20-
pyo3 = {workspace = true}
20+
pyo3 = { workspace = true }
21+
2122

2223
## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2324
## RUSTDOC CONFIGURATION

crates/RustQuant_instruments/src/fx/exchange.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ impl Exchange {
6767
///
6868
/// # Example
6969
/// ```
70-
/// use RustQuant::instruments::*;
71-
/// use RustQuant::iso::*;
70+
/// use RustQuant_instruments::*;
71+
/// use RustQuant_iso::*;
7272
///
7373
/// let mut exchange = Exchange::new();
7474
///
@@ -128,7 +128,7 @@ impl Exchange {
128128
///
129129
/// # Example
130130
/// ```
131-
/// use RustQuant::instruments::*;
131+
/// use RustQuant_instruments::*;
132132
///
133133
/// let mut exchange = Exchange::new();
134134
///
@@ -174,9 +174,8 @@ impl ExchangeRate {
174174
///
175175
/// # Example
176176
/// ```
177-
/// use RustQuant::instruments::*;
178-
/// use RustQuant::utils::assert_approx_equal;
179-
///
177+
/// # use RustQuant_instruments::*;
178+
/// # use RustQuant_utils::assert_approx_equal;
180179
/// // Use USD and EUR currency constants from the money module.
181180
/// let usd = Money::new(USD, 100.0);
182181
/// let eur_usd = ExchangeRate::new(USD, EUR, 0.9186955); // 1 USD = 0.9186955 EUR

0 commit comments

Comments
 (0)