Package Exports
- @uedfx/financial-calculators
- @uedfx/financial-calculators/1031-exchange
- @uedfx/financial-calculators/cap-rate
- @uedfx/financial-calculators/irr
- @uedfx/financial-calculators/lbo
- @uedfx/financial-calculators/loan
- @uedfx/financial-calculators/performance
- @uedfx/financial-calculators/safe
- @uedfx/financial-calculators/valuation
Readme
@uedfx/financial-calculators
Professional-grade financial calculators for startups, real estate investors, private equity, and venture capital professionals.
Features
- IRR & NPV - Internal Rate of Return with Newton-Raphson, NPV, MIRR, XIRR/XNPV
- Cap Rate - Real estate cap rate with market benchmarks by property type and class
- SAFE & Convertibles - SAFE and convertible note conversion modeling
- LBO Modeling - Full leveraged buyout model with debt schedules and IRR/MOIC
- Business Valuation - DCF, comparable analysis, Rule of 40, SaaS metrics
Zero dependencies. Tree-shakeable. TypeScript-first with full type definitions.
Installation
npm install @uedfx/financial-calculatorsQuick Start
import {
calculateIRR,
calculateCapRate,
calculateSAFEConversion,
calculateLBO,
calculateDCF
} from '@uedfx/financial-calculators';
// IRR Calculation
const cashFlows = [-100000, 30000, 40000, 50000, 60000];
const irr = calculateIRR(cashFlows);
console.log(irr); // 0.2354 (23.54%)
// Cap Rate
const capRate = calculateCapRate(500000, 10000000);
console.log(capRate); // 5.0 (5.0%)
// Property Value from Target Cap Rate
const propertyValue = calculatePropertyValue(500000, 5.5);
console.log(propertyValue); // $9,090,909Modules
IRR & NPV (@uedfx/financial-calculators/irr)
import { calculateIRR, calculateNPV, calculateMIRR, calculateXIRR } from '@uedfx/financial-calculators/irr';
// Basic IRR
const irr = calculateIRR([-100000, 30000, 40000, 50000, 60000]);
// NPV at 10% discount rate
const npv = calculateNPV([-100000, 30000, 40000, 50000, 60000], 0.10);
// MIRR with different financing and reinvestment rates
const mirr = calculateMIRR(cashFlows, 0.08, 0.12); // 8% financing, 12% reinvestment
// XIRR with irregular dates
const xirr = calculateXIRR(
[-100000, 30000, 45000, 60000],
[new Date('2024-01-01'), new Date('2024-06-15'), new Date('2025-01-01'), new Date('2025-09-30')]
);Cap Rate (@uedfx/financial-calculators/cap-rate)
import {
calculateCapRate,
calculatePropertyValue,
getMarketBenchmark,
assessCapRate,
generateCapRateScenarios,
MARKET_BENCHMARKS
} from '@uedfx/financial-calculators/cap-rate';
// Basic cap rate
const capRate = calculateCapRate(500000, 10000000); // NOI / Price
// Reverse: value from cap rate
const value = calculatePropertyValue(500000, 5.5);
// Market benchmarks
const benchmark = getMarketBenchmark('MULTIFAMILY', 'classA');
console.log(benchmark); // { low: 4.25, mid: 4.75, high: 5.25 }
// Assess a property
const assessment = assessCapRate(5.5, 'MULTIFAMILY');
console.log(assessment); // { class: 'classB', label: 'Class B', description: 'Value-add opportunity' }
// Sensitivity analysis
const scenarios = generateCapRateScenarios(500000, 10000000);
// Returns array of price impacts at different cap rate changesSupported Property Types:
MULTIFAMILY- Apartment buildingsOFFICE- Office buildingsRETAIL- Shopping centers, strip mallsINDUSTRIAL- Warehouses, distribution centersSELF_STORAGE- Storage facilitiesHOSPITALITY- Hotels, motels
SAFE & Convertibles (@uedfx/financial-calculators/safe)
import {
calculateSAFEConversion,
calculateSAFEOwnership,
compareSAFEScenarios,
type SAFEInstrument
} from '@uedfx/financial-calculators/safe';
const instruments: SAFEInstrument[] = [
{
id: 'safe-1',
name: 'YC SAFE',
type: 'safe_post',
principal: 500000,
valuationCap: 10000000,
},
{
id: 'safe-2',
name: 'Angel SAFE',
type: 'safe_post',
principal: 250000,
valuationCap: 8000000,
discount: 0.20,
},
{
id: 'note-1',
name: 'Convertible Note',
type: 'convertible_note',
principal: 100000,
valuationCap: 12000000,
discount: 0.15,
interestRate: 0.06,
termMonths: 18,
}
];
const result = calculateSAFEConversion({
instruments,
preMoneyValuation: 15000000,
newInvestmentAmount: 3000000,
foundersShares: 10000000,
optionPoolPercent: 0.10,
optionPoolOnPreMoney: true,
});
console.log(result.pricePerShare);
console.log(result.postMoneyValuation);
console.log(result.founderDilution); // 0.45 (45%)
console.log(result.capTable);
console.log(result.conversionDetails);
console.log(result.warnings);Instrument Types:
safe_post- Post-money SAFE (YC standard)safe_pre- Pre-money SAFEconvertible_note- Convertible note with interest
LBO Modeling (@uedfx/financial-calculators/lbo)
import {
calculateLBO,
runSensitivity,
type LBOInputs
} from '@uedfx/financial-calculators/lbo';
const inputs: LBOInputs = {
enterpriseValue: 100000000,
entryEbitda: 12500000,
holdPeriodYears: 5,
operatingAssumptions: {
revenueGrowthRates: [0.10, 0.08, 0.06, 0.05, 0.04],
ebitdaMargins: [0.20, 0.21, 0.22, 0.23, 0.24],
capexPercentRevenue: 0.02,
nwcPercentRevenue: 0.10,
taxRate: 0.25,
},
exitMultiple: 9.0,
capitalStructure: {
seniorDebt: { name: 'Term Loan', amount: 60000000, interestRate: 0.07, amortizationYears: 7 },
equityContribution: 40000000,
},
};
const result = calculateLBO(inputs);
console.log(result.returns.irr); // 0.25 (25% IRR)
console.log(result.returns.moic); // 2.8x MOIC
console.log(result.exitMetrics); // Exit metrics
console.log(result.yearlyProjections); // Year-by-year financials
console.log(result.debtSchedules); // Debt paydown schedulesBusiness Valuation (@uedfx/financial-calculators/valuation)
import {
calculateDCF,
analyzeComparables,
calculateRuleOf40,
calculateSaaSValuation,
calculateVentureValuation,
calculateWACC,
type DCFInputs
} from '@uedfx/financial-calculators/valuation';
// DCF Valuation
const dcfResult = calculateDCF({
projectedCashFlows: [1000000, 1100000, 1210000, 1331000, 1464100],
discountRate: 0.12,
terminalGrowthRate: 0.03,
netDebt: 2000000,
});
console.log(dcfResult.enterpriseValue);
console.log(dcfResult.equityValue);
console.log(dcfResult.pvTerminalValue);
console.log(dcfResult.impliedTerminalMultiple);
// Comparable Company Analysis
const compResult = analyzeComparables(
[
{ name: 'Comp A', value: 500000000, ebitda: 50000000, revenue: 200000000 },
{ name: 'Comp B', value: 400000000, ebitda: 40000000, revenue: 180000000 },
{ name: 'Comp C', value: 600000000, ebitda: 55000000, revenue: 250000000 },
],
{ ebitda: 45000000, revenue: 190000000 }
);
console.log(compResult.medianEVEBITDA);
console.log(compResult.impliedValuations);
// SaaS Valuation
const saasResult = calculateSaaSValuation(
5000000, // ARR
0.80, // 80% growth
1.20, // 120% NRR
0.75 // 75% gross margin
);
console.log(saasResult.adjustedMultiple);
console.log(saasResult.valuation);
console.log(saasResult.factors);
// Rule of 40
const rule40 = calculateRuleOf40({ revenueGrowth: 0.50, profitMargin: -0.05 });
console.log(rule40.score); // 45
console.log(rule40.passing); // true
console.log(rule40.assessment);
// Venture Valuation
const ventureResult = calculateVentureValuation(0.20, 2000000);
console.log(ventureResult.postMoneyValuation); // $10M
console.log(ventureResult.preMoneyValuation); // $8M
// WACC
const wacc = calculateWACC(
80000000, // Equity value
20000000, // Debt value
0.12, // Cost of equity
0.06, // Cost of debt
0.25 // Tax rate
);Utility Functions
import { formatCurrency, formatPercent, formatMultiple } from '@uedfx/financial-calculators';
formatCurrency(1500000); // "$1.50M"
formatCurrency(2500000000); // "$2.50B"
formatPercent(0.2354); // "23.54%"
formatMultiple(2.8); // "2.80x"Interactive Calculators
Try these calculators with a visual interface at uedfx.com/tools:
About DFX
This package is extracted from DFX - The Private Capital Operating System. DFX helps investors, founders, and dealmakers discover opportunities, manage portfolios, and close deals faster.
Features:
- Deal discovery and investor matching
- AI-powered due diligence
- Cap table management
- Fundraising pipeline tracking
- Real estate portfolio analytics
Mathematical Methodology
This package implements industry-standard financial formulas with high numerical precision. All calculations are verified against CFA exam reference materials and tested to ensure NPV at computed IRR equals zero.
IRR (Internal Rate of Return)
Formula: Find r such that NPV = 0
NPV = Σ(CF_t / (1+r)^t) = 0 for t = 0 to nImplementation: Newton-Raphson iterative method with:
- Maximum 100 iterations (configurable)
- Convergence tolerance: 1e-10
- Automatic fallback to bisection for non-convergent cases
- Multiple starting guesses for robust convergence
Mathematical Verification:
const irr = calculateIRR(cashFlows);
const npv = calculateNPV(cashFlows, irr);
// npv is guaranteed to be < $1 (machine precision)XIRR (IRR with Irregular Dates)
Formula: Find r such that XNPV = 0
XNPV = Σ(CF_i / (1+r)^((d_i - d_0) / 365)) = 0Where d_i is the number of days since the first cash flow.
Edge Cases Handled:
- Same-day cash flows (aggregated)
- Dates spanning multiple years
- Sub-annual cash flow periods
- Leap years (365.25 day year option available)
NPV (Net Present Value)
Formula:
NPV = Σ(CF_t / (1+r)^t) for t = 0 to nNote: Unlike Excel's NPV() function which starts discounting from period 1, our implementation uses the standard financial definition where t=0 is not discounted.
MIRR (Modified Internal Rate of Return)
Formula:
MIRR = (FV_positives / |PV_negatives|)^(1/n) - 1Where:
FV_positives= Future value of positive cash flows at reinvestment ratePV_negatives= Present value of negative cash flows at financing raten= Number of periods
Use Case: More realistic than IRR when:
- Reinvestment rate differs from IRR
- Multiple sign changes in cash flows
Cap Rate Calculation
Formula:
Cap Rate = NOI / Property Value × 100Reverse:
Property Value = NOI / (Cap Rate / 100)Market Benchmarks: Based on NCREIF and Real Capital Analytics data for institutional-quality assets across property types and classes.
LBO Returns
IRR Calculation:
- Uses XIRR methodology for actual investment/exit dates
- Incorporates all cash flows: equity contribution, dividends, exit proceeds
- Accounts for management fees and carried interest
MOIC (Multiple on Invested Capital):
MOIC = Total Distributions / Total ContributionsNumerical Precision
All calculations are performed with JavaScript's IEEE 754 double precision (15-17 significant digits). For financial applications:
| Metric | Precision |
|---|---|
| IRR | ±0.01% (1 basis point) |
| NPV | ±$1 (machine precision at IRR) |
| Cap Rate | ±0.01% |
| MOIC | ±0.001x |
Test Coverage
This package maintains 100% test coverage with:
- 227+ test cases covering all functions
- CFA exam-style problems verified against textbook solutions
- Edge cases: Negative returns, near-zero IRR, billion-dollar deals, floating-point precision
- Mathematical proofs: NPV at computed IRR equals zero within tolerance
Contributing
Contributions are welcome! Please read our Contributing Guide for details.
License
MIT License - see LICENSE for details.
Built with precision by the DFX team.