Skip to content

Box Spread

Family: Stat-arb

What it computes

Emits BoxSpreadTick ticks carrying r_box, box_width off chain.

Available on the live, historical, and replay drives.

Methodology

4-leg synthetic funding rate (Boyarchenko / Eisenbach).

See the methodology overview for the citation index.

Inputs

Chain.

Key outputs

R_box, box_width. The full field set is in the tick table below.

Output schema (BoxSpreadTick)

The field / type / description table below is regenerated from the BoxSpreadTick Rust source by docs-site/scripts/inject-doc-tables.ts on every npm run docs:build. Do not hand-edit between the sentinels.

FieldTypeDescription
rootArc<str>Underlying symbol (e.g. "SPX").
datei32Trading session date (YYYYMMDD).
ms_of_dayi32Milliseconds since midnight at emission time.
expirationi32Box-expiration date (YYYYMMDD).
dtei32Calendar days from date to expiration.
k_lowerf64Lower strike leg (long call + short put).
k_upperf64Upper strike leg (short call + long put).
box_widthf64Box width — k_upper - k_lower. Equals the guaranteed payoff at expiry.
box_pricef64Net debit / credit to enter the box: (C_low - C_high) + (P_high - P_low). Discounted at r_box reproduces box_width.
r_boxf64Implied risk-free rate: -ln(box_price / box_width) / t_years (annualised continuous compounding). f64::NAN when the position is not a valid debit / the log term is undefined.
t_yearsf64Year-fraction time-to-expiry used in r_box.

Configuration (BoxSpreadParams)

Regenerated from the BoxSpreadParams Rust source — see the note above.

FieldTypeDescription
contractsSecurityFilterContracts the subscription tracks.
rateArc<dyn RateService>Risk-free rate provider. Kept on the spec for symmetry with sibling chain analytics (implied_spot, iv_term_structure, …) — the box arithmetic itself reads the implied rate out of the four-leg position rather than consuming this input.
venuesExchangeFilterExchange / venue admission policy.
emitEmitPolicyEmission policy. Defaults to [EmitPolicy::OnExchangeInterval] at one row per second per (symbol, expiration): the box rate is a property of the whole chain snapshot, so the per-second event-time cadence carries the full signal without paying a chain sweep per inbound quote. OnEveryTick fires per admitted Quote; OnClose accumulates and fires on watermark.
spot_cacheSpotPriceCacheShared spot price cache. Not consumed by the box arithmetic itself (the box payoff is spot-independent) but kept on the spec so the analytic shares the engine-level cache with sibling chain analytics on the same subscription.
calendarArc<dyn MarketCalendar>Market calendar provider.

Example

Python

python
import kairos_thetadata as kt

client = kt.Client.connect(kt.Credentials.from_env())

def on_event(row):
    print(row)

sub = client.live().box_spread(["SPX"]).on_event(on_event)
sub.wait(timeout_seconds=60.0)

TypeScript

typescript
import { Client, Credentials } from "kairos-thetadata";

const client = await Client.connect(Credentials.fromEnv());

await client
  .live()
  .boxSpread(["SPX"])
  .onEvent((tick) => {
    console.log(tick);
  });

Rust

rust
// Cargo.toml:
//   kairos = "0.1"

use kairos::{Client, BoxSpreadRow};

# fn run() -> Result<(), Box<dyn std::error::Error>> {
let client = Client::connect(("me@example.com", "secret"))?;

let sub = client
    .live()
    .box_spread(["SPX"])
    .on_event(|row: &BoxSpreadRow| {
        println!("box_price={} r_box={}", row.box_price, row.r_box)
    })?;
// ... later ...
sub.unsubscribe();
# Ok(())
# }

Proprietary. All rights reserved.