Skip to content

Commit

Permalink
Add coverage + minor fix
Browse files Browse the repository at this point in the history
  • Loading branch information
MeetThePatel committed Aug 14, 2024
1 parent 16ff157 commit fe497bb
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/instruments/instrument.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use crate::money::{Currency, Money};

pub trait Instrument<C>
where
C: Currency,
{
fn npv(&self) -> Money<C>;

// TODO:set_pricing_engine(Rc<PricingEngine>)
}
3 changes: 3 additions & 0 deletions src/instruments/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
pub mod instrument;
pub use instrument::Instrument;

pub mod options;

pub mod exercises;
Expand Down
1 change: 1 addition & 0 deletions src/instruments/options/european_option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
7 changes: 7 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
11 changes: 11 additions & 0 deletions src/math/interpolation/linear_interpolator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,17 @@ mod tests {

#[test]
fn test_linear_interpolator() {
let interpolator: LinearInterpolator<OrderedFloat<f64>, OrderedFloat<f64>> =
LinearInterpolator::new();
assert_eq!(
interpolator.interpolate(OrderedFloat(1.0)),
InterpolationResult::NoPoints
);

let interpolator: LinearInterpolator<OrderedFloat<f64>, OrderedFloat<f64>> =
LinearInterpolator::default();
assert_eq!(interpolator.range(), None);

let data: Vec<(OrderedFloat<f64>, OrderedFloat<f64>)> = vec![
(OrderedFloat(1.0), OrderedFloat(10.0)),
(OrderedFloat(2.0), OrderedFloat(20.0)),
Expand Down

0 comments on commit fe497bb

Please sign in to comment.