diff --git a/src/instruments/instrument.rs b/src/instruments/instrument.rs new file mode 100644 index 0000000..09d64b2 --- /dev/null +++ b/src/instruments/instrument.rs @@ -0,0 +1,10 @@ +use crate::money::{Currency, Money}; + +pub trait Instrument +where + C: Currency, +{ + fn npv(&self) -> Money; + + // TODO:set_pricing_engine(Rc) +} diff --git a/src/instruments/mod.rs b/src/instruments/mod.rs index 4835d72..a0c6540 100644 --- a/src/instruments/mod.rs +++ b/src/instruments/mod.rs @@ -1,3 +1,6 @@ +pub mod instrument; +pub use instrument::Instrument; + pub mod options; pub mod exercises; diff --git a/src/instruments/options/european_option.rs b/src/instruments/options/european_option.rs index 95ad365..9dafc20 100644 --- a/src/instruments/options/european_option.rs +++ b/src/instruments/options/european_option.rs @@ -86,6 +86,7 @@ mod tests { assert_eq!(call.to_string(), "2024/07/27 $ 30.00 C (E)"); assert_eq!(put.to_string(), "2024/07/27 $ 30.00 P (E)"); + assert_eq!(call.get_strike(), strike_price); assert_eq!(call.get_payoff().to_string(), "$ 30.00 CALL"); assert_eq!( call.get_exercise().get_dates(), diff --git a/src/lib.rs b/src/lib.rs index 7468297..673d329 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,18 +1,25 @@ #![warn(clippy::all)] pub mod instruments; + pub mod money; +// pub use money::{currency, Currency, ExchangeRate, Money}; #[macro_use] pub(crate) mod macros; pub mod interest_rate; +pub use interest_rate::{implied_rate_from_compound_factor, InterestRate}; + pub mod term_structures; pub mod compounding; +pub use compounding::Compounding; + pub mod time; pub mod types; +pub use types::{CompoundFactor, DiscountFactor, MonetaryNumber, Percentage, Strike, Volatility}; pub mod math; diff --git a/src/math/interpolation/linear_interpolator.rs b/src/math/interpolation/linear_interpolator.rs index 63d6c70..d2ec831 100644 --- a/src/math/interpolation/linear_interpolator.rs +++ b/src/math/interpolation/linear_interpolator.rs @@ -159,6 +159,17 @@ mod tests { #[test] fn test_linear_interpolator() { + let interpolator: LinearInterpolator, OrderedFloat> = + LinearInterpolator::new(); + assert_eq!( + interpolator.interpolate(OrderedFloat(1.0)), + InterpolationResult::NoPoints + ); + + let interpolator: LinearInterpolator, OrderedFloat> = + LinearInterpolator::default(); + assert_eq!(interpolator.range(), None); + let data: Vec<(OrderedFloat, OrderedFloat)> = vec![ (OrderedFloat(1.0), OrderedFloat(10.0)), (OrderedFloat(2.0), OrderedFloat(20.0)),