I just open-sourced coinpopbit-futures-math (MIT license) — a zero-dependency deterministic math library implemented identically in JavaScript (ESM + TypeScript declarations) and Python (3.9+ standard library).
Why I built it
We maintain free client-side crypto derivatives calculators at https://coinpopbit.com/, and wanted to pull the core formulas out into a small, auditable, standalone package that works identically across Node.js/browser frontends and Python research scripts without pulling in third-party runtime dependencies.
Included functions
liquidationPrice/liquidation_price— isolated linear and inverse liquidation price estimates (optional extra margin and maintenance margin rate)breakevenPrice/breakeven_price— round-trip entry/exit fee and cumulative funding breakeven estimatespositionSizeByRisk/position_size_by_risk— risk-budgeted quantity, notional, and required initial margin from entry and stop-lossaverageEntryPrice/average_entry_price— weighted average entry price across multiple fills (linear and inverse)riskRewardRatio/risk_reward_ratio— raw and fee-adjusted risk-reward ratios
Cross-language verification
Both implementations run against the same 41 shared test vectors (tests/vectors.json, 1e-9 tolerance) in GitHub Actions across Node 20 and Python 3.10/3.12.
npm install coinpopbit-futures-math
pip install coinpopbit-futures-math
Note: All outputs are formula estimates only — actual exchange liquidation engines, tiered maintenance margin schedules, and funding intervals vary by venue and contract.
Feedback on edge-case validation, inverse contract conventions, or TypeScript/Python typing ergonomics is very welcome.