use super::{define_signed_value_type, Fee, ParamKind, Pnl};
define_signed_value_type!(
CashFlow,
ParamKind::CashFlow
);
impl CashFlow {
pub fn from_pnl(pnl: Pnl) -> Self {
Self::new(pnl.to_decimal())
}
pub fn from_fee(fee: Fee) -> Self {
Self::new(-fee.to_decimal())
}
}
#[cfg(test)]
mod tests {
use super::CashFlow;
use crate::param::{Fee, Pnl};
use rust_decimal::Decimal;
fn d(value: &str) -> Decimal {
value
.parse()
.expect("decimal literal in tests must be valid")
}
#[test]
fn converts_from_pnl_and_fee() {
assert_eq!(
CashFlow::from_pnl(Pnl::new(d("1.25"))).to_decimal(),
d("1.25")
);
assert_eq!(
CashFlow::from_fee(Fee::new(d("1.25"))).to_decimal(),
d("-1.25")
);
}
}