UNPKG

quant-zero

Version:

Node-Quant is a powerful Node.js package for developing and testing quantitative trading strategies in cryptocurrency markets, offering tools for backtesting and performance analysis.

39 lines (31 loc) 955 B
import { Indicator } from '@/lib/Indicator' import ta from 'technicalindicators' import { BollingerBandsOutput } from 'technicalindicators/declarations/volatility/BollingerBands' export class BB extends Indicator { public period: number = 9 public stdDev: number = 1 constructor(key: string, options: BBOptions) { super({ name: 'Bollinger Bands', key: key, description: 'Boillinger Bands.', }) if (options.period) this.period = options.period if (options.stdDev) this.stdDev = options.stdDev } generate(): BollingerBandsOutput[] { const values = this.data .map((update) => update[4]) .filter((value): value is number => value !== undefined) const bb = ta.BollingerBands.calculate({ values, period: this.period, stdDev: this.stdDev, }) return bb } } export interface BBOptions { period?: number stdDev?: number }