Skip to content

Commit 3dab488

Browse files
avhzavhz
authored andcommitted
#303 - refactored Calendar trait to struct
1 parent 59988f6 commit 3dab488

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+3423
-6352
lines changed

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ license = "MIT OR Apache-2.0"
2626

2727
[workspace]
2828
resolver = "2"
29-
members = ["crates/*", "examples"]
29+
members = [ "crates/*", "examples"]
3030

3131
[workspace.lints.rust]
3232
missing_docs = "forbid"
@@ -72,8 +72,10 @@ RustQuant_error = { version = "0.4.0", path = "crates/RustQuant_error" }
7272
RustQuant_instruments = { version = "0.4.0", path = "crates/RustQuant_instruments" }
7373
RustQuant_iso = { version = "0.4.0", path = "crates/RustQuant_iso" }
7474
RustQuant_math = { version = "0.4.0", path = "crates/RustQuant_math" }
75+
RustQuant_models = { version = "0.4.0", path = "crates/RustQuant_models" }
7576
RustQuant_ml = { version = "0.4.0", path = "crates/RustQuant_ml" }
7677
RustQuant_portfolios = { version = "0.4.0", path = "crates/RustQuant_portfolios" }
78+
RustQuant_pricing = { version = "0.4.0", path = "crates/RustQuant_pricing" }
7779
RustQuant_stochastics = { version = "0.4.0", path = "crates/RustQuant_stochastics" }
7880
RustQuant_time = { version = "0.4.0", path = "crates/RustQuant_time" }
7981
RustQuant_trading = { version = "0.4.0", path = "crates/RustQuant_trading" }

crates/RustQuant_data/src/context_data.rs

Lines changed: 0 additions & 57 deletions
This file was deleted.

crates/RustQuant_data/src/curves.rs

Lines changed: 12 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -270,20 +270,6 @@ impl_curve!(time::Time);
270270
impl_curve!(time::OffsetDateTime);
271271
impl_curve!(time::PrimitiveDateTime);
272272

273-
// Implement the Curve for unsigned integer types.
274-
// impl_curve!(u64);
275-
// impl_curve!(u32);
276-
// impl_curve!(u16);
277-
// impl_curve!(u8);
278-
// impl_curve!(usize);
279-
280-
// Implement the Curve for signed integer types.
281-
// impl_curve!(i64);
282-
// impl_curve!(i32);
283-
// impl_curve!(i16);
284-
// impl_curve!(i8);
285-
// impl_curve!(isize);
286-
287273
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
288274
// CURVE RELATED CONSTANTS
289275
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -296,7 +282,7 @@ const CURVE_OPTIM_SWARM_SIZE: usize = 1000;
296282
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
297283

298284
/// Generic trait for curves.
299-
pub trait Curves<C> {
285+
pub trait Curves {
300286
/// Create a new curve from a set of `Date`s and rates (`f64`s).
301287
fn new(dates: &[Date], rates: &[f64]) -> Self;
302288

@@ -324,10 +310,7 @@ pub trait Curves<C> {
324310

325311
macro_rules! impl_specific_curve_cost_function {
326312
($curve:ident, $curve_function:ident) => {
327-
impl<C> CostFunction for &$curve<Date, C>
328-
where
329-
C: Calendar,
330-
{
313+
impl CostFunction for &$curve<Date> {
331314
type Param = Vec<f64>;
332315
type Output = f64;
333316

@@ -359,9 +342,7 @@ macro_rules! impl_specific_curve_cost_function {
359342

360343
macro_rules! impl_specific_curve {
361344
($curve:ident, $curve_function:ident) => {
362-
impl<C> Curves<C> for $curve<Date, C>
363-
where
364-
C: Calendar + Clone,
345+
impl Curves for $curve<Date>
365346
{
366347
#[doc = concat!("Fit the ", stringify!($curve))]
367348
fn fit(&mut self) -> Result<(), argmin::core::Error> {
@@ -529,16 +510,15 @@ macro_rules! impl_specific_curve {
529510

530511
/// Discount curve data structure.
531512
#[derive(Builder, Clone, Debug)]
532-
pub struct DiscountCurve<I, C>
513+
pub struct DiscountCurve<I>
533514
where
534515
I: CurveIndex,
535-
C: Calendar,
536516
{
537517
/// Map of dates and rates.
538518
pub curve: Curve<I>,
539519

540520
/// Calendar.
541-
pub calendar: Option<C>,
521+
pub calendar: Option<Calendar>,
542522

543523
/// Day count convention.
544524
pub day_count_convention: Option<DayCountConvention>,
@@ -569,16 +549,15 @@ impl_specific_curve!(DiscountCurve, discount_factor);
569549

570550
/// Spot curve data structure.
571551
#[derive(Builder, Clone, Debug)]
572-
pub struct SpotCurve<I, C>
552+
pub struct SpotCurve<I>
573553
where
574554
I: CurveIndex,
575-
C: Calendar,
576555
{
577556
/// Map of dates and rates.
578557
pub curve: Curve<I>,
579558

580559
/// Calendar.
581-
pub calendar: Option<C>,
560+
pub calendar: Option<Calendar>,
582561

583562
/// Day count convention.
584563
pub day_count_convention: Option<DayCountConvention>,
@@ -609,16 +588,15 @@ impl_specific_curve!(SpotCurve, spot_rate);
609588

610589
/// Forward curve data structure.
611590
#[derive(Builder, Clone, Debug)]
612-
pub struct ForwardCurve<I, C>
591+
pub struct ForwardCurve<I>
613592
where
614593
I: CurveIndex,
615-
C: Calendar,
616594
{
617595
/// Map of dates and rates.
618596
pub curve: Curve<I>,
619597

620598
/// Calendar.
621-
pub calendar: Option<C>,
599+
pub calendar: Option<Calendar>,
622600

623601
/// Day count convention.
624602
pub day_count_convention: Option<DayCountConvention>,
@@ -649,15 +627,12 @@ impl_specific_curve!(ForwardCurve, forward_rate);
649627

650628
/// Flat curve data structure.
651629
#[derive(Builder, Clone, Debug)]
652-
pub struct FlatCurve<C>
653-
where
654-
C: Calendar,
655-
{
630+
pub struct FlatCurve {
656631
/// Rate of the curve.
657632
pub rate: f64,
658633

659634
/// Calendar.
660-
pub calendar: Option<C>,
635+
pub calendar: Option<Calendar>,
661636

662637
/// Day count convention.
663638
pub day_count_convention: Option<DayCountConvention>,
@@ -666,10 +641,7 @@ where
666641
pub date_rolling_convention: Option<DateRollingConvention>,
667642
}
668643

669-
impl<C> FlatCurve<C>
670-
where
671-
C: Calendar,
672-
{
644+
impl FlatCurve {
673645
/// Create a new flat curve.
674646
pub fn new_flat_curve(rate: f64) -> Self {
675647
Self {

0 commit comments

Comments
 (0)