use chrono::TimeDelta;
use crate::gym::trading::state::{Closed, Trade};
impl Trade<Closed> {
pub fn duration(&self) -> TimeDelta {
self.state.exit_ts - self.state.entry_ts
}
pub fn roi(&self) -> f64 {
let cost_basis = self.state.entry_price.0 * self.quantity.0;
if cost_basis.abs() < f64::EPSILON {
0.0
} else {
self.state.realized_pnl / cost_basis
}
}
}