Pro Feature. Requires a Pro or Ultra subscription. Get started at api.mathematicalcompany.com
Full Code
How It Works
cointegration_test()verifies the two price series share a long-run equilibriumStatArbConfigsets entry/exit z-score thresholds and the hedge ratiostat_arb()monitors the spread z-score each cycle:
- When z >
entry_z: short the spread (sell A, buy B) - When z <
-entry_z: long the spread (buy A, sell B) - When |z| <
exit_z: close the position
- The hedge ratio scales the B-side size to maintain dollar-neutrality
Spread Z-Score
You can also compute the z-score manually for custom logic:Run It
Simpler Alternative
For a lighter approach without cointegration testing, usespread_convergence():