Expand description
What a simulated position costs to hold over time: perpetual funding, borrow fees and overnight financing.
A FeeModel prices a fill, at the instant it happens. A
HoldingCostModel prices holding the position afterwards, at boundaries in time: a funding
time, a daily cutoff. The simulated venue asks each configured model for its next boundary,
charges the position it holds across that boundary, and reports each charge as the same
CashFlow a live venue sends, so a backtest and a live run reach
the engine’s Position::carry by one path.
The built-in models cover the three costs a backtest of a short or leveraged strategy most often leaves out:
FundingModel: a perpetual’s funding, every fixed interval, from a replayed rate.BorrowFeeModel: the fee for borrowing what a short sold, daily, from an annualised rate.FinancingModel: a CFD’s overnight financing, daily, at separate long and short rates.
Every rate is a RateSeries, a step function of time, so a constant rate and a replayed
history are one type. A daily charge is timed and sized by a DailyAccrual: the cutoff, its
time zone, which days have one (AccrualDays) and the year basis (DayCount).
§Where the models run
Configured on a venue through SimVenueOptions in rustrade, which drives the venue to each
boundary as it falls. A SimulatedVenue built
directly takes them through
with_holding_costs, and charges
a boundary when its driver next moves its clock past it. MockExchange charges none.
Structs§
- Borrow
FeeModel - The fee for borrowing what a short sold: at each daily cutoff, a short pays
notional × rate × days / basis. A long is not charged. - Daily
Accrual - When a daily charge falls and what fraction of a year it covers.
- Financing
Model - A CFD’s overnight financing: at each daily cutoff, the position pays
notional × rate × days / basisat the rate for its side, and receives it when that rate is negative. - Financing
Rates - The annualised rates a
FinancingModelcharges one instrument: one for a long, one for a short. - Funding
Model - A perpetual’s funding: at every fixed interval, the position pays
quantity × contract_size × price × rate, signed so that a long pays a positive rate and a short receives it. - Held
Position - A position as a
HoldingCostModelsees it at one boundary. - Holding
Charge - One charge a
HoldingCostModelmakes at one boundary. - Holiday
Calendar - A calendar whose business days are Monday to Friday, less the holidays it is given.
- Rate
Series - A rate as a step function of time: each point’s rate applies from its instant until the next point’s.
- Rate
Series Unsorted - A
RateSerieswas given instants that are not strictly ascending. - Weekends
Only - A calendar whose business days are Monday to Friday, with no holidays.
Enums§
- Accrual
Days - Which dates a daily charge falls on, and how many days each one covers.
- DayCount
- The year basis an annualised rate is divided by: the number of days a full year’s rate is charged over.
Traits§
- Holding
Cost Model - Charges a simulated position for holding it across boundaries in time.
- Settlement
Calendar - Which dates a market settles on.