meridianalgo-js
Version:
Advanced algorithmic trading library for Node.js & TypeScript with 100+ technical indicators, pattern recognition, and risk management tools.
263 lines • 10.6 kB
TypeScript
/**
* @fileoverview Technical Indicators Module for MeridianAlgo
* @description Comprehensive collection of technical analysis indicators for quantitative finance
* @author MeridianAlgo
* @version 1.0.0
* @license MIT
*/
/**
* Custom error class for indicator-related errors
* @class IndicatorError
* @extends Error
* @description Thrown when indicator calculations encounter invalid inputs or conditions
* @example
* ```typescript
* try {
* Indicators.sma([], 5);
* } catch (error) {
* if (error instanceof IndicatorError) {
* console.log('Indicator error:', error.message);
* }
* }
* ```
*/
export declare class IndicatorError extends Error {
constructor(message: string);
}
/**
* Type for moving average calculation methods
* @typedef {('sma' | 'ema' | 'wma' | 'dema' | 'tema' | 'kama' | 't3')} MovingAverageType
*/
type MovingAverageType = 'sma' | 'ema' | 'wma' | 'dema' | 'tema' | 'kama' | 't3';
/**
* Collection of technical analysis indicators with robust error handling and multiple calculation methods.
*
* This class provides a comprehensive suite of technical analysis indicators commonly used in quantitative finance.
* All methods include input validation, error handling, and return consistent data structures.
*
* @class Indicators
* @description Main class containing all technical analysis indicators
* @example
* ```typescript
* import { Indicators } from 'meridianalgo-js';
*
* const prices = [100, 102, 101, 103, 105, 104, 106, 108, 107, 109];
*
* // Calculate Simple Moving Average
* const sma = Indicators.sma(prices, 5);
* console.log('SMA:', sma);
*
* // Calculate RSI
* const rsi = Indicators.rsi(prices, 14);
* console.log('RSI:', rsi);
*
* // Calculate MACD
* const macd = Indicators.macd(prices, 12, 26, 9);
* console.log('MACD:', macd);
* ```
*/
export declare class Indicators {
/**
* Validates input parameters for indicator functions
* @private
*/
private static _validateInput;
/**
* Calculate Simple Moving Average (SMA)
*
* The Simple Moving Average is the average of a security's price over a given time period.
* It's one of the most widely used technical indicators and helps smooth out price data
* to identify trends and potential reversal points.
*
* @param data - Array of price data (typically closing prices)
* @param period - Number of periods to use for calculation (must be positive integer)
* @returns Array of SMA values with same length as input data (padded with NaN for insufficient data)
*
* @throws {IndicatorError} When data is invalid or period is invalid
*
* @example
* ```typescript
* const prices = [100, 102, 101, 103, 105, 104, 106, 108, 107, 109];
* const sma5 = Indicators.sma(prices, 5);
* console.log('5-period SMA:', sma5);
* // Output: [NaN, NaN, NaN, NaN, 102.2, 103, 103.8, 104.6, 105.4, 106.2]
* ```
*
* @see {@link https://www.investopedia.com/terms/s/sma.asp} Simple Moving Average definition
*/
static sma(data: number[], period: number): number[];
/**
* Calculate Exponential Moving Average (EMA)
* @param data - Array of price data
* @param period - Number of periods to use for calculation
* @returns Array of EMA values
*/
static ema(data: number[], period: number): number[];
/**
* Calculate Weighted Moving Average (WMA)
* @param data - Array of price data
* @param period - Number of periods to use for calculation
* @returns Array of WMA values
*/
static wma(data: number[], period: number): number[];
/**
* Calculate Double Exponential Moving Average (DEMA)
* @param data - Array of price data
* @param period - Number of periods to use for calculation
* @returns Array of DEMA values
*/
static dema(data: number[], period: number): number[];
/**
* Calculate Triple Exponential Moving Average (TEMA)
* @param data - Array of price data
* @param period - Number of periods to use for calculation
* @returns Array of TEMA values
*/
static tema(data: number[], period: number): number[];
/**
* Calculate Kaufman's Adaptive Moving Average (KAMA)
* @param data - Array of price data
* @param period - Number of periods to use for calculation
* @param fast - Fast EMA period (default: 2)
* @param slow - Slow EMA period (default: 30)
* @returns Array of KAMA values
*/
static kama(data: number[], period: number, fast?: number, slow?: number): number[];
/**
* Calculate T3 Moving Average
* @param data - Array of price data
* @param period - Number of periods to use for calculation
* @param volumeFactor - Volume factor (default: 0.7)
* @returns Array of T3 values
*/
static t3(data: number[], period: number, volumeFactor?: number): number[];
/**
* Generic moving average function that supports multiple types
* @param type - Type of moving average ('sma', 'ema', 'wma', 'dema', 'tema', 'kama', 't3')
* @param data - Array of price data
* @param period - Number of periods to use for calculation
* @param args - Additional arguments specific to the moving average type
* @returns Array of moving average values
*/
static movingAverage(type: MovingAverageType, data: number[], period: number, ...args: any[]): number[];
/**
* Calculate Relative Strength Index (RSI)
* @param data - Array of price data
* @param period - Number of periods to use for calculation (default: 14)
* @param maType - Type of moving average to use ('sma', 'ema', etc.)
* @returns Array of RSI values
*/
static rsi(data: number[], period?: number, maType?: MovingAverageType): number[];
/**
* Calculate MACD (Moving Average Convergence Divergence)
* @param data - Array of price data
* @param fast - Fast EMA period (default: 12)
* @param slow - Slow EMA period (default: 26)
* @param signal - Signal line period (default: 9)
* @param maType - Type of moving average to use ('ema' or 'sma')
* @returns Object containing MACD line, signal line, and histogram
*/
static macd(data: number[], fast?: number, slow?: number, signal?: number, maType?: MovingAverageType): {
macd: number[];
signal: number[];
histogram: number[];
};
/**
* Calculate Bollinger Bands
* @param data - Array of price data
* @param period - Number of periods to use for calculation (default: 20)
* @param stdDev - Number of standard deviations for the bands (default: 2)
* @param maType - Type of moving average to use for the middle band
* @returns Object containing upper, middle, and lower band values
*/
static bollingerBands(data: number[], period?: number, stdDev?: number, maType?: MovingAverageType): {
upper: number[];
middle: number[];
lower: number[];
};
/**
* Calculate Stochastic Oscillator
* @param high - Array of high prices
* @param low - Array of low prices
* @param close - Array of closing prices
* @param kPeriod - %K period (default: 14)
* @param dPeriod - %D period (default: 3)
* @param smooth - Smoothing period for %K (default: 1)
* @returns Object containing %K and %D values
*/
static stochastic(high: number[], low: number[], close: number[], kPeriod?: number, dPeriod?: number, smooth?: number): {
k: number[];
d: number[];
};
/**
* Calculate Average True Range (ATR)
* @param high - Array of high prices
* @param low - Array of low prices
* @param close - Array of closing prices
* @param period - Number of periods to use for calculation (default: 14)
* @param maType - Type of moving average to use (default: 'sma')
* @returns Array of ATR values
*/
static atr(high: number[], low: number[], close: number[], period?: number, maType?: MovingAverageType): number[];
/**
* Calculate Volume Moving Average
* @param volume - Array of volume values
* @param period - Number of periods to use for calculation (default: 20)
* @param maType - Type of moving average to use (default: 'sma')
* @returns Array of volume moving average values
*/
static volumeMA(volume: number[], period?: number, maType?: MovingAverageType): number[];
/**
* Calculate On-Balance Volume (OBV)
* @param close - Array of closing prices
* @param volume - Array of volume values
* @returns Array of OBV values
*/
static obv(close: number[], volume: number[]): number[];
/**
* Calculate Donchian Channels (Price Channels)
* @param high - Array of high prices
* @param low - Array of low prices
* @param period - Number of periods to use for calculation (default: 20)
* @returns Object containing upper, middle, and lower channel values
*/
static donchianChannels(high: number[], low: number[], period?: number): {
upper: number[];
middle: number[];
lower: number[];
};
static priceChannels: typeof Indicators.donchianChannels;
/**
* Calculate Williams %R
* @param high - Array of high prices
* @param low - Array of low prices
* @param close - Array of closing prices
* @param period - Number of periods to use for calculation (default: 14)
* @returns Array of Williams %R values
*/
static williamsR(high: number[], low: number[], close: number[], period?: number): number[];
/**
* Calculate Commodity Channel Index (CCI)
* @param high - Array of high prices
* @param low - Array of low prices
* @param close - Array of closing prices
* @param period - Number of periods to use for calculation (default: 20)
* @returns Array of CCI values
*/
static cci(high: number[], low: number[], close: number[], period?: number): number[];
/**
* Calculate Average Directional Index (ADX)
* @param high - Array of high prices
* @param low - Array of low prices
* @param close - Array of closing prices
* @param period - Number of periods to use for calculation (default: 14)
* @returns Object containing ADX, +DI, and -DI values
*/
static adx(high: number[], low: number[], close: number[], period?: number): {
adx: number[];
plusDI: number[];
minusDI: number[];
};
}
export {};
//# sourceMappingURL=indicators.d.ts.map