use crate::{
core::{
instrument::{AssetClass, Instrument},
trade::{Side, Trade},
},
indices::marketindex::MarketIndex,
rates::interestrate::RateDefinition,
time::date::Date,
};
pub struct RateFutures {
identifier: String,
market_index: MarketIndex,
start_date: Date,
end_date: Date,
futures_price: f64,
contract_size: f64,
rate_definition: RateDefinition,
}
impl RateFutures {
#[must_use]
pub const fn new(
identifier: String,
market_index: MarketIndex,
start_date: Date,
end_date: Date,
futures_price: f64,
contract_size: f64,
rate_definition: RateDefinition,
) -> Self {
Self {
identifier,
market_index,
start_date,
end_date,
futures_price,
contract_size,
rate_definition,
}
}
#[must_use]
pub fn market_index(&self) -> MarketIndex {
self.market_index.clone()
}
#[must_use]
pub const fn start_date(&self) -> Date {
self.start_date
}
#[must_use]
pub const fn end_date(&self) -> Date {
self.end_date
}
#[must_use]
pub const fn futures_price(&self) -> f64 {
self.futures_price
}
#[must_use]
pub fn implied_rate(&self) -> f64 {
(100.0 - self.futures_price) / 100.0
}
#[must_use]
pub const fn contract_size(&self) -> f64 {
self.contract_size
}
#[must_use]
pub const fn rate_definition(&self) -> RateDefinition {
self.rate_definition
}
#[must_use]
pub fn accrual_factor(&self) -> f64 {
self.rate_definition
.day_counter()
.year_fraction(self.start_date, self.end_date)
}
}
impl Instrument for RateFutures {
fn identifier(&self) -> String {
self.identifier.clone()
}
fn asset_class(&self) -> AssetClass {
AssetClass::InterestRate
}
}
pub struct RateFuturesTrade {
instrument: RateFutures,
trade_date: Date,
num_contracts: f64,
side: Side,
}
impl RateFuturesTrade {
#[must_use]
pub const fn new(
instrument: RateFutures,
trade_date: Date,
num_contracts: f64,
side: Side,
) -> Self {
Self {
instrument,
trade_date,
num_contracts,
side,
}
}
#[must_use]
pub const fn num_contracts(&self) -> f64 {
self.num_contracts
}
#[must_use]
pub fn notional(&self) -> f64 {
self.num_contracts * self.instrument.contract_size()
}
}
impl Trade<RateFutures> for RateFuturesTrade {
fn instrument(&self) -> &RateFutures {
&self.instrument
}
fn trade_date(&self) -> Date {
self.trade_date
}
fn side(&self) -> Side {
self.side
}
}