finance-calculator-pro 1.2.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -11,7 +11,7 @@
11
11
  ![finance-calculator-pro banner](https://raw.githubusercontent.com/boffincoders/finance-calculator/refs/heads/master/.github/assets/finance-calculator-pro.png)
12
12
 
13
13
  > **Zero-dependency financial analysis engine for JavaScript and TypeScript.**
14
- > Calculate 60+ financial metrics — valuation ratios, profitability, liquidity, solvency, efficiency, intrinsic value, composite scoring, technical indicators (SMA, EMA, RSI, MACD, ATR, ADX, Bollinger Bands), and bankruptcy risk scores — from raw financial data. No API calls. No runtime dependencies. Works in Node.js, browsers, and edge runtimes.
14
+ > Calculate 70+ financial metrics — valuation ratios, profitability, liquidity, solvency, efficiency, intrinsic value, composite scoring, TTM aggregation, historical analysis, and bankruptcy risk scores — from raw financial data. No API calls. No runtime dependencies. Works in Node.js, browsers, and edge runtimes.
15
15
 
16
16
  ---
17
17
 
@@ -50,7 +50,7 @@ Building a stock screener, neo-bank, or internal financial analysis tool? [Let's
50
50
 
51
51
  ---
52
52
 
53
- ## Metrics Reference — 60+ Functions Across 12 Categories
53
+ ## Metrics Reference — 70+ Functions Across 11 Categories
54
54
 
55
55
  ### Valuation Ratios
56
56
  | Metric | Function | Formula |
@@ -150,21 +150,7 @@ Building a stock screener, neo-bank, or internal financial analysis tool? [Let's
150
150
  | `computeNYearSum()` | Rolling N-year sum of quarterly data |
151
151
  | `computeHistoricalPoint()` | Value at exactly N quarters back |
152
152
 
153
- ### Technical Indicators *(native — zero dependencies)*
154
- | Function | Description |
155
- |---|---|
156
- | `sma(prices, period)` | Simple Moving Average |
157
- | `ema(prices, period)` | Exponential Moving Average |
158
- | `rsi(prices, period?)` | Relative Strength Index (default 14) |
159
- | `roc(prices, period?)` | Rate of Change (default 14) |
160
- | `macd(prices, fast?, slow?, signal?)` | MACD line, signal line, histogram |
161
- | `atr(highs, lows, closes, period?)` | Average True Range (default 14) |
162
- | `bollingerBands(prices, period?, mult?)` | Upper, Middle, Lower bands + Bandwidth |
163
- | `adx(highs, lows, closes, period?)` | ADX + +DI + −DI (default 14) |
164
- | `mfi(highs, lows, closes, volumes, period?)` | Money Flow Index (default 14) |
165
- | `vwap(highs, lows, closes, volumes)` | Volume-Weighted Average Price |
166
- | `beta(stockReturns, benchmarkReturns)` | Beta vs benchmark |
167
- | `pivotPoints(high, low, close)` | Classic Pivot Points (P, R1–R3, S1–S3) |
153
+
168
154
 
169
155
  ---
170
156
 
@@ -291,14 +277,46 @@ Import any function directly for lightweight single-metric use. Every function r
291
277
 
292
278
  ```typescript
293
279
  import {
280
+ // Valuation
294
281
  pe, pb, ps, peg, evEbitda, evRevenue, evFcf,
295
282
  priceToCashFlow, earningsYield, grahamNumber, calculateDCF,
296
- roa, roe, roic, grossMargin, operatingMargin, netProfitMargin,
283
+ marketCapToDebtCap,
284
+
285
+ // Profitability
286
+ roa, roe, roic, grossMargin, operatingMargin, netProfitMargin, fcfMargin,
287
+
288
+ // Liquidity
297
289
  currentRatio, quickRatio, debtToEquity, interestCoverage,
290
+
291
+ // Solvency
298
292
  netDebt, netDebtToEbitda, debtToAssets,
299
- assetTurnover, receivablesTurnover, daysSalesOutstanding,
293
+
294
+ // Efficiency
295
+ assetTurnover, inventoryTurnover, receivablesTurnover, daysSalesOutstanding,
296
+ payableDays, workingCapitalDays, cashConversionCycle,
297
+
298
+ // Quality
300
299
  payoutRatio, cashConversionRatio,
300
+
301
+ // Risk
301
302
  altmanZScore, piotroski, sharpe, targetUpside,
303
+
304
+ // Intrinsic Valuation
305
+ computeNCVPS, computeGFactor, computeIntrinsicValue,
306
+
307
+ // Composite Scoring
308
+ computeQualityScore, computeGrowthScore, computeValueScore, computeMomentumScore,
309
+
310
+ // Growth
311
+ calculateGrowthRate, yoyGrowth, qoqGrowth, cagr, medianGrowth,
312
+
313
+ // TTM
314
+ computeTTM, computeTTMAvg,
315
+
316
+ // Historical
317
+ computeNYearAverage, computeNYearSum, computeHistoricalPoint,
318
+
319
+ // Insights Engine
302
320
  evaluate,
303
321
  } from 'finance-calculator-pro';
304
322
 
@@ -306,7 +324,8 @@ import {
306
324
  pe(150, 5); // → 30
307
325
  priceToCashFlow(150_000, 7_000); // → 21.43
308
326
  earningsYield(5, 150); // → 0.0333 (3.33%)
309
- grahamNumber(5, 20); // → 47.43 (null if EPS or book ≤ 0)
327
+ grahamNumber(5, 20); // → 47.43
328
+ marketCapToDebtCap(150_000, 20_000); // → 0.882 (88.2% equity financed)
310
329
 
311
330
  // Solvency
312
331
  netDebtToEbitda(20_000, 5_000, 10_000); // → 1.5
@@ -314,9 +333,8 @@ debtToAssets(20_000, 100_000); // → 0.20
314
333
 
315
334
  // Efficiency
316
335
  daysSalesOutstanding(50_000, 6_250); // → 45.6 days
317
-
318
- // Earnings Quality
319
- cashConversionRatio(7_000, 5_000); // → 1.4
336
+ payableDays(30_000, 200_000); // → 54.75 days
337
+ cashConversionCycle(45, 60, 55); // 50 days
320
338
 
321
339
  // Risk
322
340
  altmanZScore(15_000, 20_000, 7_500, 250_000, 50_000, 100_000, 60_000); // → 3.71
@@ -330,6 +348,36 @@ const result = piotroski({
330
348
  result.score; // → 4
331
349
  result.maxScore; // → 5
332
350
 
351
+ // Intrinsic Valuation
352
+ computeNCVPS(500_000, 300_000, 100_000); // → 2.00 (net current value per share)
353
+ computeIntrinsicValue(10, 0.15, 0.25); // → 5-yr EPS projection with 25% safety margin
354
+ computeGFactor(82, 78, 67); // → composite G-Factor score
355
+
356
+ // Composite Scoring
357
+ computeQualityScore({ piotroskiScore: 7, roeVsSector: 1.1,
358
+ marginsImproving: true, pledgeFree: true, promoterStable: true }); // → 82
359
+ computeGrowthScore({ revenueGrowthVsSector: 1.3, profitGrowthRate: 0.20,
360
+ epsGrowthRate: 0.18, cfoPositive: true, revenueAccelerating: true }); // → 78
361
+ computeValueScore({ peVs3yrAvg: 0.8, pbVsSector: 0.75, peg: 0.9,
362
+ historicalPePercentile: 30 }); // → 72
363
+ computeMomentumScore({ priceVsSma200: 1.08, rsi: 58, adx: 28,
364
+ volumeRatio: 1.2, roc125: 0.18 }); // → 67
365
+
366
+ // TTM Aggregation
367
+ const quarters = [2200, 2400, 2600, 2800]; // Q1–Q4 revenue
368
+ computeTTM(quarters); // → 10000 (annualised TTM)
369
+ computeTTMAvg(quarters); // → 2500 (average quarterly)
370
+
371
+ // Historical Analysis
372
+ const qData = [2000, 2200, 2400, 2600, 2800, 3000, 3200, 3400];
373
+ computeNYearAverage(qData, 2); // → 2700 (2-year average)
374
+ computeNYearSum(qData, 1); // → 12400 (last 4 quarters sum)
375
+ computeHistoricalPoint(qData, 4); // → 2600 (same quarter last year)
376
+
377
+ // Growth
378
+ cagr(1000, 2000, 5); // → 0.1487 (14.87%)
379
+ medianGrowth([800, 900, 1100, 1050, 1300]); // → 0.176 (17.6%)
380
+
333
381
  // Pair raw math with the Insights Engine
334
382
  const ratio = pe(150, 5); // → 30
335
383
  evaluate.pe(ratio);
@@ -416,7 +464,7 @@ interface CompanySnapshotInput {
416
464
  | `analyzeProfitability(data, insights?)` | Profitability | ROA, ROE, ROIC, all margins |
417
465
  | `analyzeLiquidity(data, insights?)` | Liquidity | Current, Quick, D/E, Interest Coverage |
418
466
  | `analyzeSolvency(data, insights?)` | Solvency | Net Debt, Net Debt/EBITDA, Debt/Assets |
419
- | `analyzeEfficiency(data, insights?)` | Efficiency | Asset Turnover, Inventory, Receivables, DSO |
467
+ | `analyzeEfficiency(data, insights?)` | Efficiency | Asset Turnover, Inventory, Receivables, DSO, Payable Days, WC Days, CCC |
420
468
  | `analyzeRisk(data, insights?)` | Risk | Altman Z-Score, Sharpe, Piotroski F-Score |
421
469
  | `analyzeQuality(data, insights?)` | Quality | Payout Ratio, Cash Conversion Ratio |
422
470
  | `analyzeBatch(dataArray, insights?)` | Batch | Array of snapshots → array of analyses |
@@ -429,7 +477,7 @@ interface CompanySnapshotInput {
429
477
  | Feature | finance-calculator-pro |
430
478
  |---|---|
431
479
  | Dependencies | **Zero** |
432
- | Bundle size | **< 20 KB** (tree-shakeable) |
480
+ | Bundle size | **< 50 KB** (tree-shakeable) |
433
481
  | TypeScript | **Full types included** |
434
482
  | Return type | `number \| null` (never throws) |
435
483
  | Insights engine | **Built-in** (value + status + insight) |
package/dist/index.d.mts CHANGED
@@ -1252,142 +1252,4 @@ interface MomentumScoreInput {
1252
1252
  */
1253
1253
  declare const computeMomentumScore: (input: MomentumScoreInput) => number;
1254
1254
 
1255
- /**
1256
- * Technical Indicators
1257
- *
1258
- * All indicators are implemented natively with zero external dependencies.
1259
- * Input arrays are expected in chronological order: oldest first, most recent last.
1260
- * Functions return null when insufficient data is provided.
1261
- */
1262
- /**
1263
- * Simple Moving Average (SMA)
1264
- * Returns the average of the last `period` values.
1265
- * Returns null if fewer values than `period` are provided.
1266
- */
1267
- declare const sma: (prices: number[], period: number) => number | null;
1268
- /**
1269
- * Exponential Moving Average (EMA)
1270
- * Uses the standard smoothing factor k = 2 / (period + 1).
1271
- * Seed: SMA of first `period` values, then EMA forward.
1272
- * Returns null if fewer values than `period` are provided.
1273
- */
1274
- declare const ema: (prices: number[], period: number) => number | null;
1275
- /**
1276
- * Relative Strength Index (RSI)
1277
- * Uses Wilder's Smoothed Moving Average (SMMA) — standard RSI formula.
1278
- * Requires at least `period + 1` data points.
1279
- * @param prices Closing prices, oldest first.
1280
- * @param period Default 14.
1281
- * Returns null if insufficient data.
1282
- */
1283
- declare const rsi: (prices: number[], period?: number) => number | null;
1284
- /**
1285
- * Rate of Change (ROC)
1286
- * Formula: ((current - priorN) / priorN) × 100
1287
- * Returns the percentage change over `period` bars.
1288
- * Returns null if fewer than `period + 1` values are provided.
1289
- */
1290
- declare const roc: (prices: number[], period?: number) => number | null;
1291
- interface MACDResult {
1292
- /** MACD line = EMA(fast) - EMA(slow) */
1293
- macdLine: number;
1294
- /** Signal line = EMA(macdLine, signal) */
1295
- signalLine: number;
1296
- /** Histogram = macdLine - signalLine */
1297
- histogram: number;
1298
- }
1299
- /**
1300
- * MACD (Moving Average Convergence/Divergence)
1301
- * Default: fast=12, slow=26, signal=9
1302
- * Returns null if insufficient data.
1303
- */
1304
- declare const macd: (prices: number[], fastPeriod?: number, slowPeriod?: number, signalPeriod?: number) => MACDResult | null;
1305
- /**
1306
- * Average True Range (ATR)
1307
- * Measures volatility by averaging the True Range over `period` bars.
1308
- * True Range = max(high-low, |high-prevClose|, |low-prevClose|)
1309
- * Uses Wilder's smoothing (same as RSI).
1310
- * @param highs Array of high prices, chronological.
1311
- * @param lows Array of low prices, chronological.
1312
- * @param closes Array of close prices, chronological.
1313
- * @param period Default 14.
1314
- */
1315
- declare const atr: (highs: number[], lows: number[], closes: number[], period?: number) => number | null;
1316
- interface BollingerBandsResult {
1317
- upper: number;
1318
- middle: number;
1319
- lower: number;
1320
- /** Bandwidth: (upper - lower) / middle */
1321
- bandwidth: number;
1322
- }
1323
- /**
1324
- * Bollinger Bands
1325
- * Middle = SMA(period), Upper = SMA + (stdDev × multiplier), Lower = SMA - (stdDev × multiplier)
1326
- * @param prices Closing prices, chronological.
1327
- * @param period Default 20.
1328
- * @param multiplier Default 2.
1329
- */
1330
- declare const bollingerBands: (prices: number[], period?: number, multiplier?: number) => BollingerBandsResult | null;
1331
- interface ADXResult {
1332
- /** ADX: trend strength 0–100. > 25 = trending, < 20 = ranging */
1333
- adx: number;
1334
- /** +DI: positive directional indicator */
1335
- plusDI: number;
1336
- /** -DI: negative directional indicator */
1337
- minusDI: number;
1338
- }
1339
- /**
1340
- * ADX (Average Directional Index) with +DI and -DI
1341
- * Uses Wilder's smoothing (same period as ATR).
1342
- * @param period Default 14.
1343
- */
1344
- declare const adx: (highs: number[], lows: number[], closes: number[], period?: number) => ADXResult | null;
1345
- /**
1346
- * Money Flow Index (MFI)
1347
- * Volume-weighted RSI. Uses typical price = (high + low + close) / 3.
1348
- * @param period Default 14.
1349
- */
1350
- declare const mfi: (highs: number[], lows: number[], closes: number[], volumes: number[], period?: number) => number | null;
1351
- /**
1352
- * VWAP (Volume-Weighted Average Price)
1353
- * Typically computed intraday (resets each session), but useful as a rolling
1354
- * VWAP over the provided data window.
1355
- * Formula: sum(typicalPrice × volume) / sum(volume)
1356
- */
1357
- declare const vwap: (highs: number[], lows: number[], closes: number[], volumes: number[]) => number | null;
1358
- /**
1359
- * Beta
1360
- * Measures the stock's return volatility relative to a benchmark (e.g. index).
1361
- * Beta = Covariance(stock, benchmark) / Variance(benchmark)
1362
- * @param stockReturns Array of periodic returns for the stock.
1363
- * @param benchmarkReturns Array of periodic returns for the benchmark.
1364
- * Must be the same length as stockReturns.
1365
- * Returns null if inputs are invalid or benchmark has zero variance.
1366
- */
1367
- declare const beta: (stockReturns: number[], benchmarkReturns: number[]) => number | null;
1368
- interface PivotPointsResult {
1369
- /** Central pivot point */
1370
- pivot: number;
1371
- /** Resistance levels */
1372
- r1: number;
1373
- r2: number;
1374
- r3: number;
1375
- /** Support levels */
1376
- s1: number;
1377
- s2: number;
1378
- s3: number;
1379
- }
1380
- /**
1381
- * Classic Pivot Points
1382
- * Computed from the prior session's high, low, and close.
1383
- * Pivot = (high + low + close) / 3
1384
- * R1 = 2×Pivot − low
1385
- * S1 = 2×Pivot − high
1386
- * R2 = Pivot + (high − low)
1387
- * S2 = Pivot − (high − low)
1388
- * R3 = high + 2×(Pivot − low)
1389
- * S3 = low − 2×(high − Pivot)
1390
- */
1391
- declare const pivotPoints: (high: number, low: number, close: number) => PivotPointsResult;
1392
-
1393
- export { type ADXResult, type BollingerBandsResult, type CompanySnapshotInput, type EvaluatedMetric, type FundamentalTimeseriesInput, type GrowthScoreInput, type MACDResult, type MetricStatus, type MomentumScoreInput, type PiotroskiInput, type PiotroskiResult, type PiotroskiSignals, type PivotPointsResult, type QualityScoreInput, type ValueScoreInput, adx, altmanZScore, analyzeBatch, analyzeCompany, analyzeEfficiency, analyzeFundamentalTrends, analyzeLiquidity, analyzeProfitability, analyzeQuality, analyzeRisk, analyzeSolvency, analyzeValuation, assetTurnover, atr, beta, bollingerBands, cagr, calculateDCF, calculateEnterpriseValue, calculateGrowthRate, cashConversionCycle, cashConversionRatio, computeGFactor, computeGrowthScore, computeHistoricalPoint, computeIntrinsicValue, computeMomentumScore, computeNCVPS, computeNYearAverage, computeNYearSum, computeQualityScore, computeTTM, computeTTMAvg, computeValueScore, currentRatio, daysSalesOutstanding, debtToAssets, debtToEquity, dividendYield, earningsYield, ema, evEbitda, evFcf, evRevenue, evaluate, fcfMargin, grahamNumber, grossMargin, impliedSharePrice, interestCoverage, inventoryTurnover, macd, marketCapToDebtCap, medianGrowth, mfi, netDebt, netDebtToEbitda, netProfitMargin, operatingMargin, payableDays, payoutRatio, pb, pbFromMarketCap, pe, peg, piotroski, pivotPoints, priceToCashFlow, priceToCashFlowPerShare, ps, psFromMarketCap, qoqGrowth, quickRatio, receivablesTurnover, roa, roc, roe, roic, rsi, safeDivide, sharpe, sma, targetUpside, vwap, workingCapitalDays, yoyGrowth };
1255
+ export { type CompanySnapshotInput, type EvaluatedMetric, type FundamentalTimeseriesInput, type GrowthScoreInput, type MetricStatus, type MomentumScoreInput, type PiotroskiInput, type PiotroskiResult, type PiotroskiSignals, type QualityScoreInput, type ValueScoreInput, altmanZScore, analyzeBatch, analyzeCompany, analyzeEfficiency, analyzeFundamentalTrends, analyzeLiquidity, analyzeProfitability, analyzeQuality, analyzeRisk, analyzeSolvency, analyzeValuation, assetTurnover, cagr, calculateDCF, calculateEnterpriseValue, calculateGrowthRate, cashConversionCycle, cashConversionRatio, computeGFactor, computeGrowthScore, computeHistoricalPoint, computeIntrinsicValue, computeMomentumScore, computeNCVPS, computeNYearAverage, computeNYearSum, computeQualityScore, computeTTM, computeTTMAvg, computeValueScore, currentRatio, daysSalesOutstanding, debtToAssets, debtToEquity, dividendYield, earningsYield, evEbitda, evFcf, evRevenue, evaluate, fcfMargin, grahamNumber, grossMargin, impliedSharePrice, interestCoverage, inventoryTurnover, marketCapToDebtCap, medianGrowth, netDebt, netDebtToEbitda, netProfitMargin, operatingMargin, payableDays, payoutRatio, pb, pbFromMarketCap, pe, peg, piotroski, priceToCashFlow, priceToCashFlowPerShare, ps, psFromMarketCap, qoqGrowth, quickRatio, receivablesTurnover, roa, roe, roic, safeDivide, sharpe, targetUpside, workingCapitalDays, yoyGrowth };
package/dist/index.d.ts CHANGED
@@ -1252,142 +1252,4 @@ interface MomentumScoreInput {
1252
1252
  */
1253
1253
  declare const computeMomentumScore: (input: MomentumScoreInput) => number;
1254
1254
 
1255
- /**
1256
- * Technical Indicators
1257
- *
1258
- * All indicators are implemented natively with zero external dependencies.
1259
- * Input arrays are expected in chronological order: oldest first, most recent last.
1260
- * Functions return null when insufficient data is provided.
1261
- */
1262
- /**
1263
- * Simple Moving Average (SMA)
1264
- * Returns the average of the last `period` values.
1265
- * Returns null if fewer values than `period` are provided.
1266
- */
1267
- declare const sma: (prices: number[], period: number) => number | null;
1268
- /**
1269
- * Exponential Moving Average (EMA)
1270
- * Uses the standard smoothing factor k = 2 / (period + 1).
1271
- * Seed: SMA of first `period` values, then EMA forward.
1272
- * Returns null if fewer values than `period` are provided.
1273
- */
1274
- declare const ema: (prices: number[], period: number) => number | null;
1275
- /**
1276
- * Relative Strength Index (RSI)
1277
- * Uses Wilder's Smoothed Moving Average (SMMA) — standard RSI formula.
1278
- * Requires at least `period + 1` data points.
1279
- * @param prices Closing prices, oldest first.
1280
- * @param period Default 14.
1281
- * Returns null if insufficient data.
1282
- */
1283
- declare const rsi: (prices: number[], period?: number) => number | null;
1284
- /**
1285
- * Rate of Change (ROC)
1286
- * Formula: ((current - priorN) / priorN) × 100
1287
- * Returns the percentage change over `period` bars.
1288
- * Returns null if fewer than `period + 1` values are provided.
1289
- */
1290
- declare const roc: (prices: number[], period?: number) => number | null;
1291
- interface MACDResult {
1292
- /** MACD line = EMA(fast) - EMA(slow) */
1293
- macdLine: number;
1294
- /** Signal line = EMA(macdLine, signal) */
1295
- signalLine: number;
1296
- /** Histogram = macdLine - signalLine */
1297
- histogram: number;
1298
- }
1299
- /**
1300
- * MACD (Moving Average Convergence/Divergence)
1301
- * Default: fast=12, slow=26, signal=9
1302
- * Returns null if insufficient data.
1303
- */
1304
- declare const macd: (prices: number[], fastPeriod?: number, slowPeriod?: number, signalPeriod?: number) => MACDResult | null;
1305
- /**
1306
- * Average True Range (ATR)
1307
- * Measures volatility by averaging the True Range over `period` bars.
1308
- * True Range = max(high-low, |high-prevClose|, |low-prevClose|)
1309
- * Uses Wilder's smoothing (same as RSI).
1310
- * @param highs Array of high prices, chronological.
1311
- * @param lows Array of low prices, chronological.
1312
- * @param closes Array of close prices, chronological.
1313
- * @param period Default 14.
1314
- */
1315
- declare const atr: (highs: number[], lows: number[], closes: number[], period?: number) => number | null;
1316
- interface BollingerBandsResult {
1317
- upper: number;
1318
- middle: number;
1319
- lower: number;
1320
- /** Bandwidth: (upper - lower) / middle */
1321
- bandwidth: number;
1322
- }
1323
- /**
1324
- * Bollinger Bands
1325
- * Middle = SMA(period), Upper = SMA + (stdDev × multiplier), Lower = SMA - (stdDev × multiplier)
1326
- * @param prices Closing prices, chronological.
1327
- * @param period Default 20.
1328
- * @param multiplier Default 2.
1329
- */
1330
- declare const bollingerBands: (prices: number[], period?: number, multiplier?: number) => BollingerBandsResult | null;
1331
- interface ADXResult {
1332
- /** ADX: trend strength 0–100. > 25 = trending, < 20 = ranging */
1333
- adx: number;
1334
- /** +DI: positive directional indicator */
1335
- plusDI: number;
1336
- /** -DI: negative directional indicator */
1337
- minusDI: number;
1338
- }
1339
- /**
1340
- * ADX (Average Directional Index) with +DI and -DI
1341
- * Uses Wilder's smoothing (same period as ATR).
1342
- * @param period Default 14.
1343
- */
1344
- declare const adx: (highs: number[], lows: number[], closes: number[], period?: number) => ADXResult | null;
1345
- /**
1346
- * Money Flow Index (MFI)
1347
- * Volume-weighted RSI. Uses typical price = (high + low + close) / 3.
1348
- * @param period Default 14.
1349
- */
1350
- declare const mfi: (highs: number[], lows: number[], closes: number[], volumes: number[], period?: number) => number | null;
1351
- /**
1352
- * VWAP (Volume-Weighted Average Price)
1353
- * Typically computed intraday (resets each session), but useful as a rolling
1354
- * VWAP over the provided data window.
1355
- * Formula: sum(typicalPrice × volume) / sum(volume)
1356
- */
1357
- declare const vwap: (highs: number[], lows: number[], closes: number[], volumes: number[]) => number | null;
1358
- /**
1359
- * Beta
1360
- * Measures the stock's return volatility relative to a benchmark (e.g. index).
1361
- * Beta = Covariance(stock, benchmark) / Variance(benchmark)
1362
- * @param stockReturns Array of periodic returns for the stock.
1363
- * @param benchmarkReturns Array of periodic returns for the benchmark.
1364
- * Must be the same length as stockReturns.
1365
- * Returns null if inputs are invalid or benchmark has zero variance.
1366
- */
1367
- declare const beta: (stockReturns: number[], benchmarkReturns: number[]) => number | null;
1368
- interface PivotPointsResult {
1369
- /** Central pivot point */
1370
- pivot: number;
1371
- /** Resistance levels */
1372
- r1: number;
1373
- r2: number;
1374
- r3: number;
1375
- /** Support levels */
1376
- s1: number;
1377
- s2: number;
1378
- s3: number;
1379
- }
1380
- /**
1381
- * Classic Pivot Points
1382
- * Computed from the prior session's high, low, and close.
1383
- * Pivot = (high + low + close) / 3
1384
- * R1 = 2×Pivot − low
1385
- * S1 = 2×Pivot − high
1386
- * R2 = Pivot + (high − low)
1387
- * S2 = Pivot − (high − low)
1388
- * R3 = high + 2×(Pivot − low)
1389
- * S3 = low − 2×(high − Pivot)
1390
- */
1391
- declare const pivotPoints: (high: number, low: number, close: number) => PivotPointsResult;
1392
-
1393
- export { type ADXResult, type BollingerBandsResult, type CompanySnapshotInput, type EvaluatedMetric, type FundamentalTimeseriesInput, type GrowthScoreInput, type MACDResult, type MetricStatus, type MomentumScoreInput, type PiotroskiInput, type PiotroskiResult, type PiotroskiSignals, type PivotPointsResult, type QualityScoreInput, type ValueScoreInput, adx, altmanZScore, analyzeBatch, analyzeCompany, analyzeEfficiency, analyzeFundamentalTrends, analyzeLiquidity, analyzeProfitability, analyzeQuality, analyzeRisk, analyzeSolvency, analyzeValuation, assetTurnover, atr, beta, bollingerBands, cagr, calculateDCF, calculateEnterpriseValue, calculateGrowthRate, cashConversionCycle, cashConversionRatio, computeGFactor, computeGrowthScore, computeHistoricalPoint, computeIntrinsicValue, computeMomentumScore, computeNCVPS, computeNYearAverage, computeNYearSum, computeQualityScore, computeTTM, computeTTMAvg, computeValueScore, currentRatio, daysSalesOutstanding, debtToAssets, debtToEquity, dividendYield, earningsYield, ema, evEbitda, evFcf, evRevenue, evaluate, fcfMargin, grahamNumber, grossMargin, impliedSharePrice, interestCoverage, inventoryTurnover, macd, marketCapToDebtCap, medianGrowth, mfi, netDebt, netDebtToEbitda, netProfitMargin, operatingMargin, payableDays, payoutRatio, pb, pbFromMarketCap, pe, peg, piotroski, pivotPoints, priceToCashFlow, priceToCashFlowPerShare, ps, psFromMarketCap, qoqGrowth, quickRatio, receivablesTurnover, roa, roc, roe, roic, rsi, safeDivide, sharpe, sma, targetUpside, vwap, workingCapitalDays, yoyGrowth };
1255
+ export { type CompanySnapshotInput, type EvaluatedMetric, type FundamentalTimeseriesInput, type GrowthScoreInput, type MetricStatus, type MomentumScoreInput, type PiotroskiInput, type PiotroskiResult, type PiotroskiSignals, type QualityScoreInput, type ValueScoreInput, altmanZScore, analyzeBatch, analyzeCompany, analyzeEfficiency, analyzeFundamentalTrends, analyzeLiquidity, analyzeProfitability, analyzeQuality, analyzeRisk, analyzeSolvency, analyzeValuation, assetTurnover, cagr, calculateDCF, calculateEnterpriseValue, calculateGrowthRate, cashConversionCycle, cashConversionRatio, computeGFactor, computeGrowthScore, computeHistoricalPoint, computeIntrinsicValue, computeMomentumScore, computeNCVPS, computeNYearAverage, computeNYearSum, computeQualityScore, computeTTM, computeTTMAvg, computeValueScore, currentRatio, daysSalesOutstanding, debtToAssets, debtToEquity, dividendYield, earningsYield, evEbitda, evFcf, evRevenue, evaluate, fcfMargin, grahamNumber, grossMargin, impliedSharePrice, interestCoverage, inventoryTurnover, marketCapToDebtCap, medianGrowth, netDebt, netDebtToEbitda, netProfitMargin, operatingMargin, payableDays, payoutRatio, pb, pbFromMarketCap, pe, peg, piotroski, priceToCashFlow, priceToCashFlowPerShare, ps, psFromMarketCap, qoqGrowth, quickRatio, receivablesTurnover, roa, roe, roic, safeDivide, sharpe, targetUpside, workingCapitalDays, yoyGrowth };
package/dist/index.js CHANGED
@@ -19,7 +19,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  // src/index.ts
20
20
  var index_exports = {};
21
21
  __export(index_exports, {
22
- adx: () => adx,
23
22
  altmanZScore: () => altmanZScore,
24
23
  analyzeBatch: () => analyzeBatch,
25
24
  analyzeCompany: () => analyzeCompany,
@@ -32,9 +31,6 @@ __export(index_exports, {
32
31
  analyzeSolvency: () => analyzeSolvency,
33
32
  analyzeValuation: () => analyzeValuation,
34
33
  assetTurnover: () => assetTurnover,
35
- atr: () => atr,
36
- beta: () => beta,
37
- bollingerBands: () => bollingerBands,
38
34
  cagr: () => cagr,
39
35
  calculateDCF: () => calculateDCF,
40
36
  calculateEnterpriseValue: () => calculateEnterpriseValue,
@@ -59,7 +55,6 @@ __export(index_exports, {
59
55
  debtToEquity: () => debtToEquity,
60
56
  dividendYield: () => dividendYield,
61
57
  earningsYield: () => earningsYield,
62
- ema: () => ema,
63
58
  evEbitda: () => evEbitda,
64
59
  evFcf: () => evFcf,
65
60
  evRevenue: () => evRevenue,
@@ -70,10 +65,8 @@ __export(index_exports, {
70
65
  impliedSharePrice: () => impliedSharePrice,
71
66
  interestCoverage: () => interestCoverage,
72
67
  inventoryTurnover: () => inventoryTurnover,
73
- macd: () => macd,
74
68
  marketCapToDebtCap: () => marketCapToDebtCap,
75
69
  medianGrowth: () => medianGrowth,
76
- mfi: () => mfi,
77
70
  netDebt: () => netDebt,
78
71
  netDebtToEbitda: () => netDebtToEbitda,
79
72
  netProfitMargin: () => netProfitMargin,
@@ -85,7 +78,6 @@ __export(index_exports, {
85
78
  pe: () => pe,
86
79
  peg: () => peg,
87
80
  piotroski: () => piotroski,
88
- pivotPoints: () => pivotPoints,
89
81
  priceToCashFlow: () => priceToCashFlow,
90
82
  priceToCashFlowPerShare: () => priceToCashFlowPerShare,
91
83
  ps: () => ps,
@@ -94,15 +86,11 @@ __export(index_exports, {
94
86
  quickRatio: () => quickRatio,
95
87
  receivablesTurnover: () => receivablesTurnover,
96
88
  roa: () => roa,
97
- roc: () => roc,
98
89
  roe: () => roe,
99
90
  roic: () => roic,
100
- rsi: () => rsi,
101
91
  safeDivide: () => safeDivide,
102
92
  sharpe: () => sharpe,
103
- sma: () => sma,
104
93
  targetUpside: () => targetUpside,
105
- vwap: () => vwap,
106
94
  workingCapitalDays: () => workingCapitalDays,
107
95
  yoyGrowth: () => yoyGrowth
108
96
  });
@@ -934,224 +922,16 @@ var computeValueScore = (input) => {
934
922
  return peAvgScore * 0.3 + pbScore * 0.25 + pegScore * 0.25 + histScore * 0.2;
935
923
  };
936
924
  var computeMomentumScore = (input) => {
937
- const { priceVsSma200, rsi: rsi2, adx: adx2, volumeRatio, roc125 } = input;
925
+ const { priceVsSma200, rsi, adx, volumeRatio, roc125 } = input;
938
926
  const smaScore = Math.min(Math.max((priceVsSma200 - 0.9) / 0.2 * 100, 0), 100);
939
- const rsiScore = rsi2 <= 0 || rsi2 >= 100 ? 0 : Math.max(0, 100 - Math.abs(rsi2 - 57.5) * 2.5);
940
- const adxScore = Math.min(Math.max(adx2 / 30 * 100, 0), 100);
927
+ const rsiScore = rsi <= 0 || rsi >= 100 ? 0 : Math.max(0, 100 - Math.abs(rsi - 57.5) * 2.5);
928
+ const adxScore = Math.min(Math.max(adx / 30 * 100, 0), 100);
941
929
  const volScore = Math.min(Math.max((volumeRatio - 0.5) / 1 * 100, 0), 100);
942
930
  const rocScore = Math.min(Math.max(roc125 / 0.4 * 100, 0), 100);
943
931
  return smaScore * 0.25 + rsiScore * 0.2 + adxScore * 0.2 + volScore * 0.2 + rocScore * 0.15;
944
932
  };
945
-
946
- // src/technicals/index.ts
947
- var sma = (prices, period) => {
948
- if (!prices || prices.length < period || period <= 0) return null;
949
- const slice = prices.slice(-period);
950
- return slice.reduce((sum, p) => sum + p, 0) / period;
951
- };
952
- var ema = (prices, period) => {
953
- if (!prices || prices.length < period || period <= 0) return null;
954
- const k = 2 / (period + 1);
955
- let currentEma = prices.slice(0, period).reduce((s, p) => s + p, 0) / period;
956
- for (let i = period; i < prices.length; i++) {
957
- currentEma = prices[i] * k + currentEma * (1 - k);
958
- }
959
- return currentEma;
960
- };
961
- var emaSeries = (prices, period) => {
962
- if (!prices || prices.length < period || period <= 0) return [];
963
- const k = 2 / (period + 1);
964
- let currentEma = prices.slice(0, period).reduce((s, p) => s + p, 0) / period;
965
- const result = [currentEma];
966
- for (let i = period; i < prices.length; i++) {
967
- currentEma = prices[i] * k + currentEma * (1 - k);
968
- result.push(currentEma);
969
- }
970
- return result;
971
- };
972
- var rsi = (prices, period = 14) => {
973
- if (!prices || prices.length < period + 1) return null;
974
- const changes = prices.slice(1).map((p, i) => p - prices[i]);
975
- const gains = changes.map((c) => Math.max(c, 0));
976
- const losses = changes.map((c) => Math.max(-c, 0));
977
- let avgGain = gains.slice(0, period).reduce((s, v) => s + v, 0) / period;
978
- let avgLoss = losses.slice(0, period).reduce((s, v) => s + v, 0) / period;
979
- for (let i = period; i < changes.length; i++) {
980
- avgGain = (avgGain * (period - 1) + gains[i]) / period;
981
- avgLoss = (avgLoss * (period - 1) + losses[i]) / period;
982
- }
983
- if (avgLoss === 0) return 100;
984
- const rs = avgGain / avgLoss;
985
- return 100 - 100 / (1 + rs);
986
- };
987
- var roc = (prices, period = 14) => {
988
- if (!prices || prices.length < period + 1 || period <= 0) return null;
989
- const current = prices[prices.length - 1];
990
- const prior = prices[prices.length - 1 - period];
991
- if (prior === 0) return null;
992
- return (current - prior) / prior * 100;
993
- };
994
- var macd = (prices, fastPeriod = 12, slowPeriod = 26, signalPeriod = 9) => {
995
- if (!prices || prices.length < slowPeriod + signalPeriod) return null;
996
- const fastSeries = emaSeries(prices, fastPeriod);
997
- const slowSeries = emaSeries(prices, slowPeriod);
998
- const offset = fastSeries.length - slowSeries.length;
999
- const macdSeries = slowSeries.map((slow, i) => fastSeries[i + offset] - slow);
1000
- if (macdSeries.length < signalPeriod) return null;
1001
- const sigSeries = emaSeries(macdSeries, signalPeriod);
1002
- if (sigSeries.length === 0) return null;
1003
- const macdLine = macdSeries[macdSeries.length - 1];
1004
- const signalLine = sigSeries[sigSeries.length - 1];
1005
- return {
1006
- macdLine,
1007
- signalLine,
1008
- histogram: macdLine - signalLine
1009
- };
1010
- };
1011
- var atr = (highs, lows, closes, period = 14) => {
1012
- if (!highs || !lows || !closes || highs.length < period + 1 || highs.length !== lows.length || highs.length !== closes.length) return null;
1013
- const trueRanges = [];
1014
- for (let i = 1; i < closes.length; i++) {
1015
- const hl = highs[i] - lows[i];
1016
- const hc = Math.abs(highs[i] - closes[i - 1]);
1017
- const lc = Math.abs(lows[i] - closes[i - 1]);
1018
- trueRanges.push(Math.max(hl, hc, lc));
1019
- }
1020
- let currentAtr = trueRanges.slice(0, period).reduce((s, v) => s + v, 0) / period;
1021
- for (let i = period; i < trueRanges.length; i++) {
1022
- currentAtr = (currentAtr * (period - 1) + trueRanges[i]) / period;
1023
- }
1024
- return currentAtr;
1025
- };
1026
- var bollingerBands = (prices, period = 20, multiplier = 2) => {
1027
- if (!prices || prices.length < period || period <= 0) return null;
1028
- const slice = prices.slice(-period);
1029
- const middle = slice.reduce((s, p) => s + p, 0) / period;
1030
- const variance = slice.reduce((s, p) => s + Math.pow(p - middle, 2), 0) / period;
1031
- const stdDev = Math.sqrt(variance);
1032
- const upper = middle + multiplier * stdDev;
1033
- const lower = middle - multiplier * stdDev;
1034
- return {
1035
- upper,
1036
- middle,
1037
- lower,
1038
- bandwidth: middle !== 0 ? (upper - lower) / middle : 0
1039
- };
1040
- };
1041
- var adx = (highs, lows, closes, period = 14) => {
1042
- if (!highs || highs.length < period * 2 + 1 || highs.length !== lows.length || highs.length !== closes.length) return null;
1043
- const plusDMs = [];
1044
- const minusDMs = [];
1045
- const trs = [];
1046
- for (let i = 1; i < closes.length; i++) {
1047
- const upMove = highs[i] - highs[i - 1];
1048
- const downMove = lows[i - 1] - lows[i];
1049
- plusDMs.push(upMove > downMove && upMove > 0 ? upMove : 0);
1050
- minusDMs.push(downMove > upMove && downMove > 0 ? downMove : 0);
1051
- const tr = Math.max(
1052
- highs[i] - lows[i],
1053
- Math.abs(highs[i] - closes[i - 1]),
1054
- Math.abs(lows[i] - closes[i - 1])
1055
- );
1056
- trs.push(tr);
1057
- }
1058
- const wilderSmooth = (arr, p) => {
1059
- let val = arr.slice(0, p).reduce((s, v) => s + v, 0);
1060
- const out = [val];
1061
- for (let i = p; i < arr.length; i++) {
1062
- val = val - val / p + arr[i];
1063
- out.push(val);
1064
- }
1065
- return out;
1066
- };
1067
- const smoothedTR = wilderSmooth(trs, period);
1068
- const smoothedPlusDM = wilderSmooth(plusDMs, period);
1069
- const smoothedMinusDM = wilderSmooth(minusDMs, period);
1070
- const dxValues = [];
1071
- for (let i = 0; i < smoothedTR.length; i++) {
1072
- const tr = smoothedTR[i];
1073
- if (tr === 0) {
1074
- dxValues.push(0);
1075
- continue;
1076
- }
1077
- const pdi = smoothedPlusDM[i] / tr * 100;
1078
- const mdi = smoothedMinusDM[i] / tr * 100;
1079
- const diSum = pdi + mdi;
1080
- const dx = diSum === 0 ? 0 : Math.abs(pdi - mdi) / diSum * 100;
1081
- dxValues.push(dx);
1082
- }
1083
- let adxVal = dxValues.slice(0, period).reduce((s, v) => s + v, 0) / period;
1084
- for (let i = period; i < dxValues.length; i++) {
1085
- adxVal = (adxVal * (period - 1) + dxValues[i]) / period;
1086
- }
1087
- const last = smoothedTR.length - 1;
1088
- const finalTR = smoothedTR[last];
1089
- const plusDI = finalTR !== 0 ? smoothedPlusDM[last] / finalTR * 100 : 0;
1090
- const minusDI = finalTR !== 0 ? smoothedMinusDM[last] / finalTR * 100 : 0;
1091
- return { adx: adxVal, plusDI, minusDI };
1092
- };
1093
- var mfi = (highs, lows, closes, volumes, period = 14) => {
1094
- if (!highs || highs.length < period + 1 || highs.length !== lows.length || highs.length !== closes.length || highs.length !== volumes.length) return null;
1095
- const typicalPrices = highs.map((h, i) => (h + lows[i] + closes[i]) / 3);
1096
- const moneyFlows = typicalPrices.map((tp, i) => tp * volumes[i]);
1097
- const slice = typicalPrices.slice(-period - 1);
1098
- const mfSlice = moneyFlows.slice(-period - 1);
1099
- let posFlow = 0;
1100
- let negFlow = 0;
1101
- for (let i = 1; i <= period; i++) {
1102
- if (slice[i] > slice[i - 1]) {
1103
- posFlow += mfSlice[i];
1104
- } else {
1105
- negFlow += mfSlice[i];
1106
- }
1107
- }
1108
- if (negFlow === 0) return 100;
1109
- const mfr = posFlow / negFlow;
1110
- return 100 - 100 / (1 + mfr);
1111
- };
1112
- var vwap = (highs, lows, closes, volumes) => {
1113
- if (!highs || highs.length === 0 || highs.length !== lows.length || highs.length !== closes.length || highs.length !== volumes.length) return null;
1114
- let tpvSum = 0;
1115
- let volSum = 0;
1116
- for (let i = 0; i < highs.length; i++) {
1117
- const tp = (highs[i] + lows[i] + closes[i]) / 3;
1118
- tpvSum += tp * volumes[i];
1119
- volSum += volumes[i];
1120
- }
1121
- return volSum === 0 ? null : tpvSum / volSum;
1122
- };
1123
- var beta = (stockReturns, benchmarkReturns) => {
1124
- if (!stockReturns || !benchmarkReturns || stockReturns.length < 2 || stockReturns.length !== benchmarkReturns.length) return null;
1125
- const n = stockReturns.length;
1126
- const avgS = stockReturns.reduce((s, v) => s + v, 0) / n;
1127
- const avgB = benchmarkReturns.reduce((s, v) => s + v, 0) / n;
1128
- let covar = 0;
1129
- let varB = 0;
1130
- for (let i = 0; i < n; i++) {
1131
- const ds = stockReturns[i] - avgS;
1132
- const db = benchmarkReturns[i] - avgB;
1133
- covar += ds * db;
1134
- varB += db * db;
1135
- }
1136
- if (varB === 0) return null;
1137
- return covar / varB;
1138
- };
1139
- var pivotPoints = (high, low, close) => {
1140
- const pivot = (high + low + close) / 3;
1141
- const range = high - low;
1142
- return {
1143
- pivot,
1144
- r1: 2 * pivot - low,
1145
- r2: pivot + range,
1146
- r3: high + 2 * (pivot - low),
1147
- s1: 2 * pivot - high,
1148
- s2: pivot - range,
1149
- s3: low - 2 * (high - pivot)
1150
- };
1151
- };
1152
933
  // Annotate the CommonJS export names for ESM import in node:
1153
934
  0 && (module.exports = {
1154
- adx,
1155
935
  altmanZScore,
1156
936
  analyzeBatch,
1157
937
  analyzeCompany,
@@ -1164,9 +944,6 @@ var pivotPoints = (high, low, close) => {
1164
944
  analyzeSolvency,
1165
945
  analyzeValuation,
1166
946
  assetTurnover,
1167
- atr,
1168
- beta,
1169
- bollingerBands,
1170
947
  cagr,
1171
948
  calculateDCF,
1172
949
  calculateEnterpriseValue,
@@ -1191,7 +968,6 @@ var pivotPoints = (high, low, close) => {
1191
968
  debtToEquity,
1192
969
  dividendYield,
1193
970
  earningsYield,
1194
- ema,
1195
971
  evEbitda,
1196
972
  evFcf,
1197
973
  evRevenue,
@@ -1202,10 +978,8 @@ var pivotPoints = (high, low, close) => {
1202
978
  impliedSharePrice,
1203
979
  interestCoverage,
1204
980
  inventoryTurnover,
1205
- macd,
1206
981
  marketCapToDebtCap,
1207
982
  medianGrowth,
1208
- mfi,
1209
983
  netDebt,
1210
984
  netDebtToEbitda,
1211
985
  netProfitMargin,
@@ -1217,7 +991,6 @@ var pivotPoints = (high, low, close) => {
1217
991
  pe,
1218
992
  peg,
1219
993
  piotroski,
1220
- pivotPoints,
1221
994
  priceToCashFlow,
1222
995
  priceToCashFlowPerShare,
1223
996
  ps,
@@ -1226,15 +999,11 @@ var pivotPoints = (high, low, close) => {
1226
999
  quickRatio,
1227
1000
  receivablesTurnover,
1228
1001
  roa,
1229
- roc,
1230
1002
  roe,
1231
1003
  roic,
1232
- rsi,
1233
1004
  safeDivide,
1234
1005
  sharpe,
1235
- sma,
1236
1006
  targetUpside,
1237
- vwap,
1238
1007
  workingCapitalDays,
1239
1008
  yoyGrowth
1240
1009
  });
package/dist/index.mjs CHANGED
@@ -824,223 +824,15 @@ var computeValueScore = (input) => {
824
824
  return peAvgScore * 0.3 + pbScore * 0.25 + pegScore * 0.25 + histScore * 0.2;
825
825
  };
826
826
  var computeMomentumScore = (input) => {
827
- const { priceVsSma200, rsi: rsi2, adx: adx2, volumeRatio, roc125 } = input;
827
+ const { priceVsSma200, rsi, adx, volumeRatio, roc125 } = input;
828
828
  const smaScore = Math.min(Math.max((priceVsSma200 - 0.9) / 0.2 * 100, 0), 100);
829
- const rsiScore = rsi2 <= 0 || rsi2 >= 100 ? 0 : Math.max(0, 100 - Math.abs(rsi2 - 57.5) * 2.5);
830
- const adxScore = Math.min(Math.max(adx2 / 30 * 100, 0), 100);
829
+ const rsiScore = rsi <= 0 || rsi >= 100 ? 0 : Math.max(0, 100 - Math.abs(rsi - 57.5) * 2.5);
830
+ const adxScore = Math.min(Math.max(adx / 30 * 100, 0), 100);
831
831
  const volScore = Math.min(Math.max((volumeRatio - 0.5) / 1 * 100, 0), 100);
832
832
  const rocScore = Math.min(Math.max(roc125 / 0.4 * 100, 0), 100);
833
833
  return smaScore * 0.25 + rsiScore * 0.2 + adxScore * 0.2 + volScore * 0.2 + rocScore * 0.15;
834
834
  };
835
-
836
- // src/technicals/index.ts
837
- var sma = (prices, period) => {
838
- if (!prices || prices.length < period || period <= 0) return null;
839
- const slice = prices.slice(-period);
840
- return slice.reduce((sum, p) => sum + p, 0) / period;
841
- };
842
- var ema = (prices, period) => {
843
- if (!prices || prices.length < period || period <= 0) return null;
844
- const k = 2 / (period + 1);
845
- let currentEma = prices.slice(0, period).reduce((s, p) => s + p, 0) / period;
846
- for (let i = period; i < prices.length; i++) {
847
- currentEma = prices[i] * k + currentEma * (1 - k);
848
- }
849
- return currentEma;
850
- };
851
- var emaSeries = (prices, period) => {
852
- if (!prices || prices.length < period || period <= 0) return [];
853
- const k = 2 / (period + 1);
854
- let currentEma = prices.slice(0, period).reduce((s, p) => s + p, 0) / period;
855
- const result = [currentEma];
856
- for (let i = period; i < prices.length; i++) {
857
- currentEma = prices[i] * k + currentEma * (1 - k);
858
- result.push(currentEma);
859
- }
860
- return result;
861
- };
862
- var rsi = (prices, period = 14) => {
863
- if (!prices || prices.length < period + 1) return null;
864
- const changes = prices.slice(1).map((p, i) => p - prices[i]);
865
- const gains = changes.map((c) => Math.max(c, 0));
866
- const losses = changes.map((c) => Math.max(-c, 0));
867
- let avgGain = gains.slice(0, period).reduce((s, v) => s + v, 0) / period;
868
- let avgLoss = losses.slice(0, period).reduce((s, v) => s + v, 0) / period;
869
- for (let i = period; i < changes.length; i++) {
870
- avgGain = (avgGain * (period - 1) + gains[i]) / period;
871
- avgLoss = (avgLoss * (period - 1) + losses[i]) / period;
872
- }
873
- if (avgLoss === 0) return 100;
874
- const rs = avgGain / avgLoss;
875
- return 100 - 100 / (1 + rs);
876
- };
877
- var roc = (prices, period = 14) => {
878
- if (!prices || prices.length < period + 1 || period <= 0) return null;
879
- const current = prices[prices.length - 1];
880
- const prior = prices[prices.length - 1 - period];
881
- if (prior === 0) return null;
882
- return (current - prior) / prior * 100;
883
- };
884
- var macd = (prices, fastPeriod = 12, slowPeriod = 26, signalPeriod = 9) => {
885
- if (!prices || prices.length < slowPeriod + signalPeriod) return null;
886
- const fastSeries = emaSeries(prices, fastPeriod);
887
- const slowSeries = emaSeries(prices, slowPeriod);
888
- const offset = fastSeries.length - slowSeries.length;
889
- const macdSeries = slowSeries.map((slow, i) => fastSeries[i + offset] - slow);
890
- if (macdSeries.length < signalPeriod) return null;
891
- const sigSeries = emaSeries(macdSeries, signalPeriod);
892
- if (sigSeries.length === 0) return null;
893
- const macdLine = macdSeries[macdSeries.length - 1];
894
- const signalLine = sigSeries[sigSeries.length - 1];
895
- return {
896
- macdLine,
897
- signalLine,
898
- histogram: macdLine - signalLine
899
- };
900
- };
901
- var atr = (highs, lows, closes, period = 14) => {
902
- if (!highs || !lows || !closes || highs.length < period + 1 || highs.length !== lows.length || highs.length !== closes.length) return null;
903
- const trueRanges = [];
904
- for (let i = 1; i < closes.length; i++) {
905
- const hl = highs[i] - lows[i];
906
- const hc = Math.abs(highs[i] - closes[i - 1]);
907
- const lc = Math.abs(lows[i] - closes[i - 1]);
908
- trueRanges.push(Math.max(hl, hc, lc));
909
- }
910
- let currentAtr = trueRanges.slice(0, period).reduce((s, v) => s + v, 0) / period;
911
- for (let i = period; i < trueRanges.length; i++) {
912
- currentAtr = (currentAtr * (period - 1) + trueRanges[i]) / period;
913
- }
914
- return currentAtr;
915
- };
916
- var bollingerBands = (prices, period = 20, multiplier = 2) => {
917
- if (!prices || prices.length < period || period <= 0) return null;
918
- const slice = prices.slice(-period);
919
- const middle = slice.reduce((s, p) => s + p, 0) / period;
920
- const variance = slice.reduce((s, p) => s + Math.pow(p - middle, 2), 0) / period;
921
- const stdDev = Math.sqrt(variance);
922
- const upper = middle + multiplier * stdDev;
923
- const lower = middle - multiplier * stdDev;
924
- return {
925
- upper,
926
- middle,
927
- lower,
928
- bandwidth: middle !== 0 ? (upper - lower) / middle : 0
929
- };
930
- };
931
- var adx = (highs, lows, closes, period = 14) => {
932
- if (!highs || highs.length < period * 2 + 1 || highs.length !== lows.length || highs.length !== closes.length) return null;
933
- const plusDMs = [];
934
- const minusDMs = [];
935
- const trs = [];
936
- for (let i = 1; i < closes.length; i++) {
937
- const upMove = highs[i] - highs[i - 1];
938
- const downMove = lows[i - 1] - lows[i];
939
- plusDMs.push(upMove > downMove && upMove > 0 ? upMove : 0);
940
- minusDMs.push(downMove > upMove && downMove > 0 ? downMove : 0);
941
- const tr = Math.max(
942
- highs[i] - lows[i],
943
- Math.abs(highs[i] - closes[i - 1]),
944
- Math.abs(lows[i] - closes[i - 1])
945
- );
946
- trs.push(tr);
947
- }
948
- const wilderSmooth = (arr, p) => {
949
- let val = arr.slice(0, p).reduce((s, v) => s + v, 0);
950
- const out = [val];
951
- for (let i = p; i < arr.length; i++) {
952
- val = val - val / p + arr[i];
953
- out.push(val);
954
- }
955
- return out;
956
- };
957
- const smoothedTR = wilderSmooth(trs, period);
958
- const smoothedPlusDM = wilderSmooth(plusDMs, period);
959
- const smoothedMinusDM = wilderSmooth(minusDMs, period);
960
- const dxValues = [];
961
- for (let i = 0; i < smoothedTR.length; i++) {
962
- const tr = smoothedTR[i];
963
- if (tr === 0) {
964
- dxValues.push(0);
965
- continue;
966
- }
967
- const pdi = smoothedPlusDM[i] / tr * 100;
968
- const mdi = smoothedMinusDM[i] / tr * 100;
969
- const diSum = pdi + mdi;
970
- const dx = diSum === 0 ? 0 : Math.abs(pdi - mdi) / diSum * 100;
971
- dxValues.push(dx);
972
- }
973
- let adxVal = dxValues.slice(0, period).reduce((s, v) => s + v, 0) / period;
974
- for (let i = period; i < dxValues.length; i++) {
975
- adxVal = (adxVal * (period - 1) + dxValues[i]) / period;
976
- }
977
- const last = smoothedTR.length - 1;
978
- const finalTR = smoothedTR[last];
979
- const plusDI = finalTR !== 0 ? smoothedPlusDM[last] / finalTR * 100 : 0;
980
- const minusDI = finalTR !== 0 ? smoothedMinusDM[last] / finalTR * 100 : 0;
981
- return { adx: adxVal, plusDI, minusDI };
982
- };
983
- var mfi = (highs, lows, closes, volumes, period = 14) => {
984
- if (!highs || highs.length < period + 1 || highs.length !== lows.length || highs.length !== closes.length || highs.length !== volumes.length) return null;
985
- const typicalPrices = highs.map((h, i) => (h + lows[i] + closes[i]) / 3);
986
- const moneyFlows = typicalPrices.map((tp, i) => tp * volumes[i]);
987
- const slice = typicalPrices.slice(-period - 1);
988
- const mfSlice = moneyFlows.slice(-period - 1);
989
- let posFlow = 0;
990
- let negFlow = 0;
991
- for (let i = 1; i <= period; i++) {
992
- if (slice[i] > slice[i - 1]) {
993
- posFlow += mfSlice[i];
994
- } else {
995
- negFlow += mfSlice[i];
996
- }
997
- }
998
- if (negFlow === 0) return 100;
999
- const mfr = posFlow / negFlow;
1000
- return 100 - 100 / (1 + mfr);
1001
- };
1002
- var vwap = (highs, lows, closes, volumes) => {
1003
- if (!highs || highs.length === 0 || highs.length !== lows.length || highs.length !== closes.length || highs.length !== volumes.length) return null;
1004
- let tpvSum = 0;
1005
- let volSum = 0;
1006
- for (let i = 0; i < highs.length; i++) {
1007
- const tp = (highs[i] + lows[i] + closes[i]) / 3;
1008
- tpvSum += tp * volumes[i];
1009
- volSum += volumes[i];
1010
- }
1011
- return volSum === 0 ? null : tpvSum / volSum;
1012
- };
1013
- var beta = (stockReturns, benchmarkReturns) => {
1014
- if (!stockReturns || !benchmarkReturns || stockReturns.length < 2 || stockReturns.length !== benchmarkReturns.length) return null;
1015
- const n = stockReturns.length;
1016
- const avgS = stockReturns.reduce((s, v) => s + v, 0) / n;
1017
- const avgB = benchmarkReturns.reduce((s, v) => s + v, 0) / n;
1018
- let covar = 0;
1019
- let varB = 0;
1020
- for (let i = 0; i < n; i++) {
1021
- const ds = stockReturns[i] - avgS;
1022
- const db = benchmarkReturns[i] - avgB;
1023
- covar += ds * db;
1024
- varB += db * db;
1025
- }
1026
- if (varB === 0) return null;
1027
- return covar / varB;
1028
- };
1029
- var pivotPoints = (high, low, close) => {
1030
- const pivot = (high + low + close) / 3;
1031
- const range = high - low;
1032
- return {
1033
- pivot,
1034
- r1: 2 * pivot - low,
1035
- r2: pivot + range,
1036
- r3: high + 2 * (pivot - low),
1037
- s1: 2 * pivot - high,
1038
- s2: pivot - range,
1039
- s3: low - 2 * (high - pivot)
1040
- };
1041
- };
1042
835
  export {
1043
- adx,
1044
836
  altmanZScore,
1045
837
  analyzeBatch,
1046
838
  analyzeCompany,
@@ -1053,9 +845,6 @@ export {
1053
845
  analyzeSolvency,
1054
846
  analyzeValuation,
1055
847
  assetTurnover,
1056
- atr,
1057
- beta,
1058
- bollingerBands,
1059
848
  cagr,
1060
849
  calculateDCF,
1061
850
  calculateEnterpriseValue,
@@ -1080,7 +869,6 @@ export {
1080
869
  debtToEquity,
1081
870
  dividendYield,
1082
871
  earningsYield,
1083
- ema,
1084
872
  evEbitda,
1085
873
  evFcf,
1086
874
  evRevenue,
@@ -1091,10 +879,8 @@ export {
1091
879
  impliedSharePrice,
1092
880
  interestCoverage,
1093
881
  inventoryTurnover,
1094
- macd,
1095
882
  marketCapToDebtCap,
1096
883
  medianGrowth,
1097
- mfi,
1098
884
  netDebt,
1099
885
  netDebtToEbitda,
1100
886
  netProfitMargin,
@@ -1106,7 +892,6 @@ export {
1106
892
  pe,
1107
893
  peg,
1108
894
  piotroski,
1109
- pivotPoints,
1110
895
  priceToCashFlow,
1111
896
  priceToCashFlowPerShare,
1112
897
  ps,
@@ -1115,15 +900,11 @@ export {
1115
900
  quickRatio,
1116
901
  receivablesTurnover,
1117
902
  roa,
1118
- roc,
1119
903
  roe,
1120
904
  roic,
1121
- rsi,
1122
905
  safeDivide,
1123
906
  sharpe,
1124
- sma,
1125
907
  targetUpside,
1126
- vwap,
1127
908
  workingCapitalDays,
1128
909
  yoyGrowth
1129
910
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "finance-calculator-pro",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "author": "boffincoders",
5
5
  "repository": {
6
6
  "type": "git",