Skip to main content

Module holding_cost

Module holding_cost 

Source
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§

BorrowFeeModel
The fee for borrowing what a short sold: at each daily cutoff, a short pays notional × rate × days / basis. A long is not charged.
DailyAccrual
When a daily charge falls and what fraction of a year it covers.
FinancingModel
A CFD’s overnight financing: at each daily cutoff, the position pays notional × rate × days / basis at the rate for its side, and receives it when that rate is negative.
FinancingRates
The annualised rates a FinancingModel charges one instrument: one for a long, one for a short.
FundingModel
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.
HeldPosition
A position as a HoldingCostModel sees it at one boundary.
HoldingCharge
One charge a HoldingCostModel makes at one boundary.
HolidayCalendar
A calendar whose business days are Monday to Friday, less the holidays it is given.
RateSeries
A rate as a step function of time: each point’s rate applies from its instant until the next point’s.
RateSeriesUnsorted
A RateSeries was given instants that are not strictly ascending.
WeekendsOnly
A calendar whose business days are Monday to Friday, with no holidays.

Enums§

AccrualDays
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§

HoldingCostModel
Charges a simulated position for holding it across boundaries in time.
SettlementCalendar
Which dates a market settles on.