Skip to main content

FundingModel

Enum FundingModel 

Source
pub enum FundingModel {
    None,
    Constant {
        rate: f64,
        interval_ms: i64,
    },
    Series(Vec<(i64, f64)>),
}
Expand description

Pluggable perp funding-rate schedule. Defaults to Self::None.

Rates are fractions of notional per settlement (0.0001 = 1 bp), the same convention exchanges publish. Timestamps are epoch milliseconds — the same unit as Candle::time.

§Example

use rustrade_backtest::{FundingModel, EIGHT_HOURS_MS};

// Historical series: (settlement timestamp ms, rate).
let series = FundingModel::Series(vec![
    (EIGHT_HOURS_MS, 0.0001),
    (2 * EIGHT_HOURS_MS, -0.0002),
]);
assert_eq!(series.settlements_between(0, 2 * EIGHT_HOURS_MS).len(), 2);

// Constant fallback when no series exists: 1 bp every 8 h.
let constant = FundingModel::Constant { rate: 0.0001, interval_ms: EIGHT_HOURS_MS };
let s = constant.settlements_between(0, 24 * 3_600_000);
assert_eq!(s, vec![
    (EIGHT_HOURS_MS, 0.0001),
    (2 * EIGHT_HOURS_MS, 0.0001),
    (3 * EIGHT_HOURS_MS, 0.0001),
]);

Variants§

§

None

No funding cashflows — spot backtests and every pre-existing consumer. The default.

§

Constant

Constant rate applied at every multiple of interval_ms on the epoch-aligned grid — the fallback when no historical series exists. interval_ms = EIGHT_HOURS_MS reproduces the KuCoin / Binance 8 h UTC settlement grid.

Fields

§rate: f64

Rate per settlement as a fraction of notional (0.0001 = 1 bp). Positive = longs pay, shorts receive.

§interval_ms: i64

Milliseconds between settlements. Must be > 0.

§

Series(Vec<(i64, f64)>)

Historical settlement series: (timestamp_ms, rate) pairs. BacktestConfigBuilder::build sorts the series by timestamp and rejects non-finite rates and duplicate timestamps (a duplicate would double-book a settlement).

Implementations§

Source§

impl FundingModel

Source

pub fn settlements_between(&self, after: i64, until: i64) -> Vec<(i64, f64)>

The settlements in the half-open window (after, until], ascending by timestamp. This is the live paper ledger’s accrual window: a settlement exactly at after is excluded, one exactly at until is included.

For Self::Series the series is assumed ascending by timestamp (the config builder sorts it, and Backtest::run re-validates the schedule so a series assigned directly to BacktestConfig.funding cannot reach the engine unsorted); results on an unsorted series are unspecified.

Trait Implementations§

Source§

impl Clone for FundingModel

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FundingModel

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for FundingModel

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for FundingModel

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for FundingModel

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for FundingModel

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for FundingModel

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more