Skip to main content

MarginInterestModel

Trait MarginInterestModel 

Source
pub trait MarginInterestModel:
    Debug
    + Send
    + Sync {
    // Required methods
    fn next_boundary(
        &self,
        asset: &AssetNameExchange,
        after: DateTime<Utc>,
    ) -> Option<DateTime<Utc>>;
    fn charge(
        &self,
        asset: &AssetNameExchange,
        principal: Decimal,
        due: InterestDue,
    ) -> Option<InterestCharge>;
}
Expand description

Charges interest on a simulated margin loan: once when the loan is taken, and at boundaries in time while it stays open.

The simulated venue asks for a charge on each loan its spot margin takes (InterestDue::Borrow, on the amount just lent), and, through next_boundary, at each boundary its clock reaches while the account owes the asset (InterestDue::Boundary, on the principal owed when it falls). Each charge is added to the asset’s loan as interest, which the account repays before principal, and is reported as a CashFlowKind::MarginInterest in the borrowed asset.

Interest is charged on principal only: interest already owed earns none.

§Contract

  • next_boundary must return an instant strictly after after, or None when the model never charges the asset at a boundary. A boundary at or before after would charge one instant forever, so the venue panics on one.
  • A charge’s interest must not be negative: interest is owed, never paid out. The venue panics on a negative one.
  • Both methods must be pure functions of their arguments: the venue may ask for the same boundary more than once, and charges it once.

In return, the venue asks charge only about a positive principal: an order that lends nothing, and an asset that owes nothing, is never charged.

Send + Sync because a venue holds its model behind an Arc, so that one model, and the rate history it carries, can be shared by every run of a backtest sweep without being copied.

Required Methods§

Source

fn next_boundary( &self, asset: &AssetNameExchange, after: DateTime<Utc>, ) -> Option<DateTime<Utc>>

The first boundary strictly after after at which this model charges a loan of asset, or None if it never does.

Source

fn charge( &self, asset: &AssetNameExchange, principal: Decimal, due: InterestDue, ) -> Option<InterestCharge>

What a loan of principal of asset is charged when due, or None for nothing.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§