etf_trick
Concept Overview
Section titled “Concept Overview”The ETF trick turns a series of futures contracts — each with its own roll, financing cost and carry — into one continuous, reinvestable price series that a backtest can treat like a tradable instrument. EtfTrick consumes aligned open, close, allocation and cost tables plus optional financing rates and produces a NAV series; get_futures_roll_series applies backward or forward roll adjustment to a single contract chain. Both exist because naively concatenating contract prices manufactures a return at every roll.
When to Use
Section titled “When to Use”Use it whenever a backtest spans a contract roll, or whenever the traded object is a basket whose weights change over time. Suspiciously smooth PnL around roll dates is the symptom of skipping it. Costs and financing rates must come from the same clock as the price data, and the contract calendar assumptions are worth verifying against the exchange rather than inferring from the data. This module is Rust-only — no Python bindings are exposed.
Mathematical Foundations
Section titled “Mathematical Foundations”ETF NAV Update
Section titled “ETF NAV Update”
Roll Return
Section titled “Roll Return”
Usage Examples
Section titled “Usage Examples”Construct synthetic ETF series
Section titled “Construct synthetic ETF series”use openquant::etf_trick::{EtfTrick, Table};
// Load open/close/allocation/cost tables from CSVlet etf = EtfTrick::from_csv( "open.csv", "close.csv", "alloc.csv", "costs.csv", Some("rates.csv"),).unwrap();
// Generate synthetic ETF NAV serieslet series = etf.get_etf_series(252).unwrap();// Returns Vec<(date_string, nav_value)>Compute futures roll-adjusted series
Section titled “Compute futures roll-adjusted series”use openquant::etf_trick::{get_futures_roll_series, FuturesRollRow};
let rows: Vec<FuturesRollRow> = vec![/* ... */];let adjusted = get_futures_roll_series(&rows, "backward", true).unwrap();API Reference
Section titled “API Reference”Rust API
Section titled “Rust API”EtfTrickEtfTrick::from_tablesEtfTrick::from_csvEtfTrick::get_etf_seriesget_futures_roll_seriesFuturesRollRowTable
Risk Notes and Caveats
Section titled “Risk Notes and Caveats”- Verify contract calendar assumptions.
- Costs and rates should come from the same clock as price data.
- This module is Rust-only — no Python bindings are currently exposed.