Skip to content
GeneratedAssembled automatically from moduleDocs.ts. No human has reviewed this page.

etf_trick

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.

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.

NAVt=NAVt1(1+rtct)NAV_t=NAV_{t-1}(1+r_t-c_t)

rtroll=FtnearFtfarFtfarr^{roll}_t=\frac{F^{near}_t-F^{far}_t}{F^{far}_t}

use openquant::etf_trick::{EtfTrick, Table};
// Load open/close/allocation/cost tables from CSV
let etf = EtfTrick::from_csv(
"open.csv", "close.csv", "alloc.csv", "costs.csv", Some("rates.csv"),
).unwrap();
// Generate synthetic ETF NAV series
let series = etf.get_etf_series(252).unwrap();
// Returns Vec<(date_string, nav_value)>
use openquant::etf_trick::{get_futures_roll_series, FuturesRollRow};
let rows: Vec<FuturesRollRow> = vec![/* ... */];
let adjusted = get_futures_roll_series(&rows, "backward", true).unwrap();
  • EtfTrick
  • EtfTrick::from_tables
  • EtfTrick::from_csv
  • EtfTrick::get_etf_series
  • get_futures_roll_series
  • FuturesRollRow
  • Table
  • 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.