npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@omnifolio/trading-calc

v1.0.0

Published

Trading position calculators for Forex, Crypto, Options & Futures — pip values, margin, liquidation prices, Black-Scholes, Kelly criterion, and risk management.

Readme

@omnifolio/trading-calc

Zero-dependency trading position calculators for Forex, Crypto, Options & Futures.

Built by the OmniFolio team. Battle-tested in production.

Install

npm install @omnifolio/trading-calc

Quick Start

import {
  calculateForexPosition,
  calculateCryptoPosition,
  blackScholesCall,
  kellyCalculator,
} from '@omnifolio/trading-calc';

// Forex: How many lots can I trade with 1% risk?
const forex = calculateForexPosition({
  accountBalance: 10_000,
  riskPercentage: 1,
  stopLossPips: 50,
  pair: 'EURUSD',
  leverage: 100,
});
console.log(forex.lotSize);       // 0.2
console.log(forex.potentialLoss); // ~$100

// Crypto: Leveraged BTC position with liquidation price
const crypto = calculateCryptoPosition({
  accountBalance: 5_000,
  riskPercentage: 2,
  entryPrice: 65_000,
  stopLossPrice: 63_000,
  leverage: 10,
  marginType: 'isolated',
});
console.log(crypto.liquidationPrice); // ~$58,760
console.log(crypto.quantity);         // BTC quantity to buy

// Options: Black-Scholes call pricing
const callPrice = blackScholesCall(100, 100, 1, 0.05, 0.20);
console.log(callPrice); // ~$10.45

// Risk: Kelly criterion position sizing
const kellyPct = kellyCalculator(0.55, 200, 100);
console.log(kellyPct); // recommended % of capital to risk

API

Forex

| Function | Description | |---|---| | calculatePipValue(pair, lotSize, currency?, rate?) | Pip value in account currency | | calculateForexPosition(params) | Full position sizing with risk/reward | | calculateForexMargin(lotSize, leverage, rate?) | Margin requirement | | convertLotSize(lots, from, to) | Convert between standard/mini/micro |

Crypto

| Function | Description | |---|---| | calculateCryptoPosition(params) | Position sizing with liquidation price (isolated & cross margin) | | calculateFundingRate(notional, rate, hours) | Perpetual futures funding cost |

Options

| Function | Description | |---|---| | calculateOptionsPosition(params) | Cost, breakeven, max profit/loss | | blackScholesCall(S, K, T, r, σ) | European call option pricing |

Futures

| Function | Description | |---|---| | calculateFuturesPosition(params) | Contract sizing with margin and risk/reward |

Risk Management

| Function | Description | |---|---| | calculateRiskMetrics(params) | Comprehensive risk analysis for any position | | kellyCalculator(winRate, avgWin, avgLoss) | Kelly criterion optimal bet size (capped at 25%) | | fixedRatioPositionSize(balance, delta, profits, contracts) | Ryan Jones fixed-ratio method | | volatilityBasedPositionSize(balance, risk%, atr, price) | ATR-based position sizing | | calculateSharpeRatio(returns, riskFreeRate?) | Risk-adjusted return metric |

Utilities

| Function | Description | |---|---| | calculatePnL(params) | Profit/loss for long or short with optional leverage | | calculateROI(initial, current) | Return on investment percentage | | formatCurrency(amount, currency?, decimals?) | Currency string formatting |

Types

All interfaces and types are fully exported:

import type {
  AccountCurrency,    // 'USD' | 'EUR' | 'GBP' | 'JPY' | 'AUD' | 'CAD' | 'CHF'
  MarginType,         // 'isolated' | 'cross'
  PositionSide,       // 'long' | 'short'
  ForexCalculation,
  CryptoCalculation,
  OptionsCalculation,
  FuturesCalculation,
  RiskManagement,
} from '@omnifolio/trading-calc';

License

MIT — built by OmniFolio