position-sizing-data
Reference data and arithmetic for risk-based position sizing across forex, stocks and crypto futures.
The same tables are published as a citable dataset: doi:10.5281/zenodo.22840538, and used by the web calculator at https://positionsizetool.com/. Source repository: https://github.com/tk25719/position-sizing-data.
Install
pip install position-sizing-data
What is in it
| Function | Returns |
|---|---|
contract_specifications() |
Pip size, contract size and minimum unit step for 131 instruments, across forex pairs, metals, energies, indices, crypto futures, stocks and ETFs. |
pip_values() |
Pip value and the loss on a 20 pip move for standard, mini, micro and nano lots. |
losing_streak_equity() |
Equity remaining after 1 to 20 consecutive losses at 0.5%, 1% and 2% risk per trade. |
drawdown_recovery() |
Gain required on the reduced balance to return to the original balance, for drawdowns from 5% to 90%. |
position_size(...) |
The risk-to-units calculation itself. |
Read the tables:
from position_sizing_data import contract_specifications
rows = contract_specifications()
print(rows[0])
Compute a size:
from position_sizing_data import position_size
result = position_size(
balance=10000.0,
risk_percent=1.0,
entry=1.1000,
stop=1.0980,
unit_step=1000.0, # 0.01 lot
)
print(result)
# {'risk_budget': 100.0, 'units': 50000.0, 'tradable_units': 50000.0, 'worst_case_loss': 100.0}
The formula
units = (risk_budget - commission) / ((|entry - stop| + spread) x quote_rate)
The tradable size is that number rounded down to unit_step. position_size returns the worst-case loss recomputed from the rounded size, which is what the account actually loses when the stop is hit.
Where the numbers come from
The rows in contract_specifications() are typical retail contract specifications, not exchange-published official values. Verify the contract size and unit step against your own broker before placing an order. The other three tables are closed-form arithmetic:
- losing streak:
remaining = (1 - risk)^n - drawdown recovery:
gain_required = 1 / (1 - drawdown) - 1 - pip value:
pip_value = units x pip_size
Licence
MIT for the code. Data files are CC0 1.0 Universal, to the extent applicable. This is not investment advice.
Release files for position-sizing-data 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| position_sizing_data-0.1.0.tar.gz | 7.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| position_sizing_data-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size:14.4 kB
Release files / position_sizing_data-0.1.0.tar.gz
| Download URL | position_sizing_data-0.1.0.tar.gz |
|---|---|
| Size | 7.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e95e647e688c99d0662d5946449e0c0b828c2e65d7e8e00f0a7c2ed82abdef63
|
|
BLAKE2b-256 checksum How to use checksums |
daa3abb3658eb8ad8690345db5ea9ed18040270af88757589368f12ce3abb350
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 19, 2026.
Transparency logRelease files / position_sizing_data-0.1.0-py3-none-any.whl
| Download URL | position_sizing_data-0.1.0-py3-none-any.whl |
|---|---|
| Size | 7.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
25edd2347a490cdb790cea5ae47e383c7a7a28ec3f41692f6afba7714021285b
|
|
BLAKE2b-256 checksum How to use checksums |
3d43041077727b292650d40d5dd84e3eaeffd688755f6eb382ca459299ea2474
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 19, 2026.
Transparency log