wlwli1

wlwli1

coinpopbit-futures-math - Zero-dependency JS & Python futures math library with shared test vectors

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 estimates
  • positionSizeByRisk / position_size_by_risk — risk-budgeted quantity, notional, and required initial margin from entry and stop-loss
  • averageEntryPrice / 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

Source & test vectors: GitHub - wlwli1/coinpopbit-futures-math: Deterministic zero-dependency futures math library (JS & Python) for liquidation price, breakeven, position sizing, average entry price, and risk-reward estimates. · GitHub

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.

Where Next?

Popular Backend topics Top

New
CommunityNews
Runtime and compiler performance is out of this world. New features include better error handling, a more powerful API, cross-compilation...
New
First poster: bot
Why is it called pie? Because if you pronounce API like “a pie”, then all this consuming and serving of APIs becomes a lot more palatabl...
/go
New
First poster: bot
A set of utility functions for iterators, functions, and dictionaries. See the PyToolz documentation at https://toolz.readthedocs.io ...
New
mudasobwa
Tarearbol provides a handy helper to work with many similar processes under the supervision of Tarearbol.DynamicManager. To build a supe...
New
mudasobwa
Tarearbol library that eases the dealing with tasks got a massive update. use Tarearbol.Pool to create worker pools with no boilerplat...
New
First poster: bot
YOCaml is a static site generator, mostly written in OCaml. The project was started to offer some rather naive examples of how to use the...
New
fi_mihej
I’ve released “InterProcessPyObjects” Python package. It provides high-performance and seamless sharing and modification of Python object...
New
dhoelzgen
I am currently giving Cursor another try to code Elixir apps. Although I am quite happy with how it evolved, I kept getting annoyed by th...
New
wlwli1
I just open-sourced coinpopbit-futures-math (MIT license) — a zero-dependency deterministic math library implemented identically in JavaS...
New

Other popular topics Top

PragmaticBookshelf
Design and develop sophisticated 2D games that are as much fun to make as they are to play. From particle effects and pathfinding to soci...
New
AstonJ
You might be thinking we should just ask who’s not using VSCode :joy: however there are some new additions in the space that might give V...
New
AstonJ
There’s a whole world of custom keycaps out there that I didn’t know existed! Check out all of our Keycaps threads here: https://forum....
New
Exadra37
Oh just spent so much time on this to discover now that RancherOS is in end of life but Rancher is refusing to mark the Github repo as su...
New
AstonJ
If you get Can't find emacs in your PATH when trying to install Doom Emacs on your Mac you… just… need to install Emacs first! :lol: bre...
New
AstonJ
Was just curious to see if any were around, found this one: I got 51/100: Not sure if it was meant to buy I am sure at times the b...
New
New
AstonJ
This is a very quick guide, you just need to: Download LM Studio: https://lmstudio.ai/ Click on search Type DeepSeek, then select the o...
New
PragmaticBookshelf
As digital systems increasingly run the world, mastery of the recurring patterns of software development risk is the key to fast and effe...
New
xiji2646-netizen
Woke up to this today: Claude Code’s complete source code exposed via npm source map. Not a snippet. All 512,000 lines. 1,900 TypeScript ...
New