Small, deterministic trading-risk calculations with explicit inputs and no runtime dependencies.
This package does not fetch market data, connect to a broker, store credentials, recommend trades, or place orders. It is designed for calculators, paper simulations, tests, and transparent explanations of risk arithmetic.
Until the first npm registry release, clone the repository and import
src/index.js directly, or build the audited tarball locally:
npm pack
npm install /path/to/pipsync-risk-math/pipsync-risk-math-0.1.0.tgzAfter a registry release exists, npm install @pipsync/risk-math will be the
shorter installation command.
import { positionSize } from "@pipsync/risk-math";
const result = positionSize({
equity: 10_000,
riskPercent: 1,
entryPrice: 1.085,
stopPrice: 1.082,
contractMultiplier: 100_000,
quoteToAccountRate: 1,
sizeStep: 0.01,
});
console.log(result.size);The caller must supply the correct contract multiplier, price conversion, account currency, size step, and broker limits. PipSync deliberately does not guess instrument metadata.
lossBudgetconverts equity and a risk percentage into a loss budget.positionSizesizes from loss budget and stop distance, rounding down to a caller-provided step.pipValuevalues a pip from explicit pip size, units, and conversion rate.marginRequiredcomputes simple notional/leverage margin.drawdownRecoveryPercentshows the gain needed to recover a percentage drawdown.portfolioHeattotals caller-provided open-risk amounts.slippageCostvalues a caller-provided price delta.
All functions reject non-finite inputs and fail closed when calculations cannot be represented safely. Portfolio totals use exact decimal aggregation and round upward to the nearest finite JavaScript number when needed, so input order or small positive amounts cannot understate heat. Step rounding uses canonical decimal input representations and guarantees that the returned size is never greater than the supplied value. Results are calculations, not trading advice or broker guarantees.
npm test
npm run checkThis library is intentionally pure and offline. Please report vulnerabilities according to SECURITY.md.
Prefer a browser tool instead of code? PipSync provides free trading calculators that run without signup and explain every required input.
Apache-2.0.