
Security News
RubyGems Adds Cooldown Feature to Bundler for Newly Published Gems
RubyGems and Bundler 4.0.13 introduced an opt-in cooldown feature that delays newly published gems during dependency resolution.
@bndamm/finance-toolkit
Advanced tools
Production-ready finance library for portfolio construction, risk analytics, and quantitative metrics
A comprehensive TypeScript library for portfolio management and risk analytics.
@railpath/finance-toolkit provides a complete collection of financial metrics with focus on modularity, type-safety, and performance.
Part of the Railpath open source ecosystem – building financial infrastructure that belongs to everyone.
npm install @railpath/finance-toolkit
import {
calculateTimeWeightedReturn,
calculateMoneyWeightedReturn
} from '@railpath/finance-toolkit';
// Time-Weighted Return (TWR)
const twr = calculateTimeWeightedReturn({
portfolioValues: [1000, 1100, 1200, 1150],
cashFlows: [0, 100, 0, -50],
annualizationFactor: 252
});
// Money-Weighted Return (MWR) - IRR
const mwr = calculateMoneyWeightedReturn({
cashFlows: [1000, 100, -50],
dates: [new Date('2023-01-01'), new Date('2023-06-01'), new Date('2023-12-01')],
finalValue: 1150,
initialValue: 0
});
import {
calculateVaR,
calculateSharpeRatio,
calculateMaxDrawdown
} from '@railpath/finance-toolkit';
// Value at Risk (95% Confidence)
const var95 = calculateVaR({
returns: [0.01, 0.02, -0.01, 0.03, -0.02],
confidenceLevel: 0.95,
method: 'historical'
});
// Sharpe Ratio
const sharpe = calculateSharpeRatio({
returns: [0.01, 0.02, -0.01, 0.03],
riskFreeRate: 0.02,
annualizationFactor: 252
});
// Maximum Drawdown
const maxDD = calculateMaxDrawdown({
portfolioValues: [1000, 1100, 1050, 1200, 1150]
});
import {
calculateCorrelationMatrix,
calculatePortfolioVolatility
} from '@railpath/finance-toolkit';
// Asset Correlation Matrix
const correlation = calculateCorrelationMatrix({
assetReturns: [
[0.01, 0.02, -0.01], // Asset 1
[0.015, 0.025, -0.005] // Asset 2
]
});
// Portfolio Volatility
const portfolioVol = calculatePortfolioVolatility({
weights: [0.6, 0.4],
covarianceMatrix: [[0.04, 0.02], [0.02, 0.09]]
});
All functions are fully typed with Zod validation:
import type {
TimeWeightedReturnOptions,
TimeWeightedReturnResult,
MoneyWeightedReturnOptions,
MoneyWeightedReturnResult
} from '@railpath/finance-toolkit';
// Type-safe Options
const options: TimeWeightedReturnOptions = {
portfolioValues: [1000, 1100, 1200],
cashFlows: [0, 100, 0],
annualizationFactor: 252
};
// Type-safe Results
const result: TimeWeightedReturnResult = calculateTimeWeightedReturn(options);
console.log(result.twr); // number
console.log(result.annualizedTWR); // number
console.log(result.periodReturns); // number[]
| Function | Description | Input | Output |
|---|---|---|---|
calculateTimeWeightedReturn | TWR Performance | Portfolio Values, Cash Flows | TWR, Annualized TWR, Period Returns |
calculateMoneyWeightedReturn | MWR Performance (IRR) | Cash Flows, Dates, Final Value | MWR, Annualized MWR, NPV, Iterations |
calculatePortfolioMetrics | Comprehensive Analysis | Portfolio Values, Risk-Free Rate | CAGR, Sharpe, Sortino, VaR, ES, Volatility |
calculatePerformanceAttribution | Factor Analysis | Returns, Factor Returns | Factor Contributions, Active Return |
calculatePortfolioOptimization | Mean-Variance Optimization | Expected Returns, Covariance Matrix | Optimal Weights, Risk-Return |
calculatePortfolioRebalancing | Rebalancing Strategies | Current Weights, Target Weights | New Weights, Trade Amounts |
calculateEqualWeightPortfolio | Equal Weight Allocation | Asset Count | Equal Weights, Portfolio Metrics |
calculateReturns | Return Calculations | Prices, Dates | Various Return Types |
calculateRiskMetrics | Portfolio Risk Analysis | Returns, Risk-Free Rate | Risk Metrics, VaR, ES |
calculateInformationRatio | Active Return Analysis | Portfolio Returns, Benchmark Returns | Information Ratio, Active Return |
calculateTrackingError | Benchmark Deviation | Portfolio Returns, Benchmark Returns | Tracking Error, Active Risk |
| Function | Description | Methods |
|---|---|---|
calculateVaR | Value at Risk | Historical, Parametric, Monte Carlo |
calculateVaR95 | VaR 95% Confidence | Historical, Parametric, Monte Carlo |
calculateVaR99 | VaR 99% Confidence | Historical, Parametric, Monte Carlo |
calculateExpectedShortfall | Conditional VaR | Historical, Parametric |
calculateHistoricalVaR | Historical VaR | Historical Method |
calculateParametricVaR | Parametric VaR | Normal Distribution |
calculateMonteCarloVaR | Monte Carlo VaR | Simulation Method |
calculateHistoricalExpectedShortfall | Historical ES | Historical Method |
calculateParametricExpectedShortfall | Parametric ES | Normal Distribution |
calculateSharpeRatio | Risk-Adjusted Returns | Standard, Annualized |
calculateSortinoRatio | Downside Risk-Adjusted | Standard, Annualized |
calculateCalmarRatio | Return vs. Drawdown | Calmar Ratio |
calculateAlpha | CAPM Alpha | Asset vs. Benchmark |
calculateBeta | CAPM Beta | Asset vs. Benchmark |
calculateMaxDrawdown | Maximum Loss | Peak-to-Trough Analysis |
calculateStandardDeviation | Standard Deviation | Classical Measure |
| Function | Description | Input |
|---|---|---|
calculateVolatility | Standard Deviation | Returns Array |
calculateEWMAVolatility | Exponentially Weighted | Returns, Lambda |
calculateParkinsonVolatility | High-Low Range | High, Low Prices |
calculateGarmanKlassVolatility | OHLC-based | Open, High, Low, Close |
calculateStandardDeviation | Classical Measure | Returns Array |
| Function | Description | Input |
|---|---|---|
calculateCorrelationMatrix | Asset Correlations | Asset Returns Matrix |
calculateCovarianceMatrix | Asset Covariances | Asset Returns Matrix |
calculatePortfolioVolatility | Portfolio Risk | Weights, Covariance Matrix |
# Run all tests
npm test
# Run tests in watch mode
npm run test:watch
# Run tests with coverage
npm run test:coverage
Test Coverage: 829 Tests across 34 test files
# Build for production
npm run build
# Development with watch mode
npm run dev
Output: TypeScript declarations and optimized JavaScript modules
MIT License - see LICENSE for details.
FAQs
Production-ready finance library for portfolio construction, risk analytics, and quantitative metrics
We found that @bndamm/finance-toolkit demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
RubyGems and Bundler 4.0.13 introduced an opt-in cooldown feature that delays newly published gems during dependency resolution.

Security News
pnpm 11.5 now recognizes npm staged publish approvals in release metadata, preventing those releases from being mistaken for lower-trust package publishes.

Security News
Federal audit finds NIST lacked a plan to clear the NVD backlog, wasted funds on duplicate work, and delayed use of CISA data.