Skip to content
All strategies

Strategies

TqSdk Stainless Steel–Nickel Kalman Pairs: Faithful Specification, Platform Support Required

Outcome: Abandoned

TqKalmanSsNiPairs

Outcome Summary

TqKalmanSsNiPairs ported TqSdk's Kalman pairs-trading demo, a long-short trade between SHFE stainless steel and nickel futures. The port kept the source's unusual Kalman equations, lot sizing and event order unchanged. The hypothesis itself said a faithful platform run was infeasible because the platform's venue configuration does not support SHFE and lacks the contracts' data, margin and fees. As expected, the run was abandoned in its first iteration with 'SS2209.SHFE: venue not modelled', so it never produced backtest or optimisation results and no performance can be judged.

Hypothesis

A concrete long-short pairs strategy credited to Shinny (TqSdk), supplied under Apache-2.0. The original trades SHFE.ss2209 as Y and SHFE.ni2209 as X using 3600-second kline serials during 2022-07-04 through 2022-08-31. Preserve the supplied implementation exactly, including its unconventional Kalman equations, sizing and event timing. The inspected platform venue configuration does not support SHFE, and the brief establishes neither these contracts' historical data nor their margin and fee schedules. A faithful executable platform hypothesis is therefore infeasible with the established infrastructure. Substituting crypto instruments or completed-bar signals would produce a different experiment.

The user's faithful-source requirement takes precedence over portfolio diversification. Changing this industrial-metals pair to an underrepresented crypto venue would invent a different research question. This is executable trading code in its original environment, rather than a utility or an abstract, but its platform feasibility and fee viability remain unestablished.

SS2209.SHFE: venue not modelled

Implementation

Faithful translation of TqSdk's kalman_filter_pairs_trading. Y = SHFE stainless steel ss2209 (primary), X = SHFE nickel ni2209 (extra leg), on 1-hour bars. A scalar Kalman filter (Q=STATE_VAR, R=OBS_VAR, init mean/var 1.0) runs from the 11th bar and estimates the hedge ratio. The spread is y - beta*x, z-scored over the last 60 spreads with population std. The strategy opens long Y / short X when z < -2 and short Y / long X when z > 2. It closes on |z| < 0.5, on an adverse z move of 3 from entry, or after 10 observed date changes while holding. Y lots = capital*POS_PCT/margin_per_lot and X lots = int(lots*beta*py*mult_y/(px*mult_x)), both as in the source.

The source's Kalman equations, including its non-standard variance update (1-K*x)*P, are kept verbatim, along with its window, thresholds, stop, date-transition timeout and lot formulas. Adaptations forced by the platform: (1) Signals use completed 1-hour bar closes on an aligned Y/X pair. The source fires on each new kline's datetime change, using the forming bar's first price. (2) quote.margin and quote.volume_multiple do not exist here, so they are parameters: MARGIN_RATE_Y=0.12 is an unverified assumption,……Show moreShow less

The source's Kalman equations, including its non-standard variance update (1-K*x)*P, are kept verbatim, along with its window, thresholds, stop, date-transition timeout and lot formulas. Adaptations forced by the platform: (1) Signals use completed 1-hour bar closes on an aligned Y/X pair. The source fires on each new kline's datetime change, using the forming bar's first price. (2) quote.margin and quote.volume_multiple do not exist here, so they are parameters: MARGIN_RATE_Y=0.12 is an unverified assumption, and VOL_MULT_Y=5 / VOL_MULT_X=1 are the SHFE contract sizes. (3) Sizing uses get_account_equity() rather than the fixed INIT_CAP=10M CNY, as the capital-relative rule requires. On a $100K account that gives 0 lots, so a faithful run needs about CNY 10M of equity. (4) Day boundaries are UTC dates, not the SHFE trading-day calendar (night session). BLOCKER: venue_configs.py has no SHFE venue, the catalog has no SS2209/NI2209 data, and no SHFE fee or margin schedule is established. As the hypothesis itself states, this cannot be executed here, and substituting crypto would be a different experiment.

Outcome Summary

Before coding a hypothesis, confirm the platform supports its venue, data and fee and margin schedules; a source that can only run on an unsupported exchange (here SHFE) needs that support added first, because swapping in crypto instruments would make it a different experiment.

It was abandoned in iteration 1 with the reason 'SS2209.SHFE: venue not modelled': the platform has no SHFE venue, no historical data for these contracts and no SHFE margin or fee schedules. The hypothesis itself had already flagged this as infeasible, so backtest review, analyst review and risk review were never reached.

A faithful port of Shinny's (TqSdk, Apache-2.0) Kalman-filter pairs strategy: it estimates a dynamic hedge ratio between SHFE stainless steel (ss2209, Y) and nickel (ni2209, X) on 3600-second bars, then trades the spread's rolling z-score (opens beyond ±2, closes inside ±0.5, plus a stop-spread rule and a maximum-holding-days rule).

No performance data exists. The backtest report is empty, optimisation did not run, and no return, Sharpe or trade-count figures were produced.

Analysis

kalman_filter_pairs_trading

Backtest and paper results are hypothetical. Trading involves risk of loss.