etf_trick
Subject
Section titled “Subject”Position Sizing and Trade Construction
Why This Module Exists
Section titled “Why This Module Exists”Backtests must include financing, carry, and contract-roll mechanics to avoid optimistic bias.
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
Implementation Notes
Section titled “Implementation Notes”- 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.