Package Exports
- @uedfx/financial-calculators
- @uedfx/financial-calculators/cap-rate
- @uedfx/financial-calculators/irr
- @uedfx/financial-calculators/lbo
- @uedfx/financial-calculators/safe
- @uedfx/financial-calculators/valuation
Readme
@dfx/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 @dfx/financial-calculatorsQuick Start
import {
calculateIRR,
calculateCapRate,
calculateSAFEConversion,
calculateLBO,
calculateDCF
} from '@dfx/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 (@dfx/financial-calculators/irr)
import { calculateIRR, calculateNPV, calculateMIRR, calculateXIRR } from '@dfx/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 (@dfx/financial-calculators/cap-rate)
import {
calculateCapRate,
calculatePropertyValue,
getMarketBenchmark,
assessCapRate,
generateCapRateScenarios,
MARKET_BENCHMARKS
} from '@dfx/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 (@dfx/financial-calculators/safe)
import {
calculateSAFEConversion,
calculateSAFEOwnership,
compareSAFEScenarios,
type SAFEInstrument
} from '@dfx/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 (@dfx/financial-calculators/lbo)
import {
calculateLBO,
runSensitivity,
type LBOInputs
} from '@dfx/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 (@dfx/financial-calculators/valuation)
import {
calculateDCF,
analyzeComparables,
calculateRuleOf40,
calculateSaaSValuation,
calculateVentureValuation,
calculateWACC,
type DCFInputs
} from '@dfx/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 '@dfx/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
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.