Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

PipSync Risk Math

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.

Install

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.tgz

After a registry release exists, npm install @pipsync/risk-math will be the shorter installation command.

Example

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.

API

  • lossBudget converts equity and a risk percentage into a loss budget.
  • positionSize sizes from loss budget and stop distance, rounding down to a caller-provided step.
  • pipValue values a pip from explicit pip size, units, and conversion rate.
  • marginRequired computes simple notional/leverage margin.
  • drawdownRecoveryPercent shows the gain needed to recover a percentage drawdown.
  • portfolioHeat totals caller-provided open-risk amounts.
  • slippageCost values 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.

Development

npm test
npm run check

Security

This library is intentionally pure and offline. Please report vulnerabilities according to SECURITY.md.

Try the calculators

Prefer a browser tool instead of code? PipSync provides free trading calculators that run without signup and explain every required input.

License

Apache-2.0.

About

Deterministic, dependency-free trading risk calculations.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages