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
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
impl FundingModel
Sourcepub fn settlements_between(&self, after: i64, until: i64) -> Vec<(i64, f64)>
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
impl Clone for FundingModel
Source§fn clone(&self) -> FundingModel
fn clone(&self) -> FundingModel
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more