@d3fc/d3fc-technical-indicator

中文文档
8.1.1发布于 2024/06/13MITTypeScriptESM + CJS近 30 天下载 6.7万

Components for calculating technical indicators on data series

原始使用文档
文档目录11 节
  1. Installing
  2. API Reference
  3. Bollinger Bands
  4. Elder-Ray
  5. Envelope
  6. Moving Average
  7. Exponential Moving Average
  8. Force Index
  9. MACD
  10. Relative Strength Index
  11. Stochastic Oscillator

d3fc-technical-indicator

Components for calculating technical indicators on data series.

Main D3FC package

Installing

npm install @d3fc/d3fc-technical-indicator

API Reference

Technical indicator calculators operate on an ordered input array of data, transforming it into a new array containing the indicator output values. The length of the output array is the same as the input array.

Calculators expose a value accessor property (or a number of accessors if required) used to extract values from the source array. For calculators that only depend on a single value for their input, the value accessor defaults to the identity function.

Technical indicator parameters can be configured individually for each calculator instance. A default value is used if a parameter is not configured.

If an indicator calculator needs to create undefined values in the output (for example, the leading values of a moving average result), they will have the same structure as the other output objects, but will have primitive undefined property values.

Input values retrieved by the value accessor for which value == null is true will produce undefined values in the output. Undefined inputs are best avoided — a single undefined input value will produce undefined output for all output values that depend on it.


import { indicatorBollingerBands } from '@d3fc/d3fc-technical-indicator';

const bollinger = indicatorBollingerBands()
    .period(3);

bollinger([5, 6, 7, 6, 5, 4]);
// [
//   { upper: undefined, average: undefined, lower: undefined },
//   { upper: undefined, average: undefined, lower: undefined },
//   { upper: 8, average: 6, lower: 4 },
//   { upper: 7.4880338717125845, average: 6.333333333333333, lower: 5.178632794954082 },
//   { upper: 8, average: 6, lower: 4 },
//   { upper: 7, average: 5, lower: 3 }
// ]

Bollinger Bands

# fc.indicatorBollingerBands()

Constructs a new Bollinger band calculator with the default settings.

# indicatorBollingerBands(data)

Computes the Bollinger bands for the given data array. Returns an array of objects with attributes:

  • upper: Upper Bollinger band
  • average: Simple moving average
  • lower: Lower Bollinger band

# indicatorBollingerBands.value([value])

Get/set the accessor function used to obtain the value to be used by the calculator from the supplied array of data. The accessor function is invoked exactly once per datum. Defaults to the identity function.

# indicatorBollingerBands.period([size])

Get/set the period of the moving average and standard deviation calculations performed by the calculator. Can be specified as a number, or as a function of the supplied array of data. Defaults to 10.

# indicatorBollingerBands.multiplier([multiplier])

Get/set the multiplier of the of the standard deviation around the moving average for the upper and lower bands. Defaults to 2.

Elder-Ray

# fc.indicatorElderRay()

Constructs a new Elder-ray calculator with the default settings.

# indicatorElderRay(data)

Computes the Elder-ray for the given data array. Returns an array of objects with attributes:

  • bullPower: Data highValue - EMA of specified period
  • bearPower: Data lowValue - EMA of specified period

# indicatorElderRay.closeValue([value])

Get/set the accessor function used to obtain the close price value to be used by the calculator from the supplied array of data. The accessor function is invoked exactly once per datum. Defaults to (d) => d.close.

# indicatorElderRay.highValue([value])

Get/set the accessor function used to obtain the high price value to be used by the calculator from the supplied array of data. The accessor function is invoked exactly once per datum. Defaults to (d) => d.high.

# indicatorElderRay.lowValue([value])

Get/set the accessor function used to obtain the low price value to be used by the calculator from the supplied array of data. The accessor function is invoked exactly once per datum. Defaults to (d) => d.low.

# indicatorElderRay.period([period])

Get/set the period of the moving average calculation performed by the calculator. Can be specified as a number, or as a function of the supplied array of data. Defaults to 13.

Envelope

# fc.indicatorEnvelope()

Constructs a new envelope calculator with the default settings.

# indicatorEnvelope(data)

Computes the envelope for the given data array. Returns an array of objects with attributes:

  • upper: Upper level
  • lower: Lower level

# indicatorEnvelope.value([value])

Get/set the accessor function used to obtain the value to be used by the calculator from the supplied array of data. The accessor function is invoked exactly once per datum. Defaults to the identity function.

# indicatorEnvelope.factor([factor])

Get/set the multiplier used to obtain the upper and lower levels from the datum values. Defaults to 2.

Moving Average

# fc.indicatorMovingAverage()

Constructs a new simple moving average calculator with the default settings.

# indicatorMovingAverage(data)

Computes the moving average for the given data array. Returns an array of simple moving average values.

# indicatorMovingAverage.value([value])

Get/set the accessor function used to obtain the value to be used by the calculator from the supplied array of data. The accessor function is invoked exactly once per datum. Defaults to the identity function.

# indicatorMovingAverage.period([size])

Get/set the period of the moving average calculation performed by the calculator. Can be specified as a number, or as a function of the supplied array of data. Defaults to 10.

Exponential Moving Average

# fc.indicatorExponentialMovingAverage()

Constructs a new exponential moving average calculator with the default settings.

# indicatorExponentialMovingAverage(data)

Computes the exponential moving average for the given data array. Returns an array of exponential moving average values.

# indicatorExponentialMovingAverage.value([value])

Get/set the accessor function used to obtain the value to be used by the calculator from the supplied array of data. The accessor function is invoked exactly once per datum. Defaults to the identity function.

# indicatorExponentialMovingAverage.period([size])

Get/set the period of the exponential moving average calculation performed by the calculator. Can be specified as a number, or as a function of the supplied array of data. Defaults to 9.

Force Index

# fc.indicatorForceIndex()

Constructs a new force index calculator with the default settings.

# indicatorForceIndex(data)

Computes the force index for the given data array. Returns an array of force index values.

# indicatorForceIndex.closeValue([value])

Get/set the accessor function used to obtain the close price value to be used by the calculator from the supplied array of data. The accessor function is invoked exactly once per datum. Defaults to (d) => d.close.

# indicatorForceIndex.volumeValue([value])

Get/set the accessor function used to obtain the trade volume value to be used by the calculator from the supplied array of data. The accessor function is invoked exactly once per datum. Defaults to (d) => d.volume.

# indicatorForceIndex.period([size])

Get/set the period of the exponential moving average calculation performed by the calculator. Can be specified as a number, or as a function of the supplied array of data. Defaults to 13.

MACD

# fc.indicatorMacd()

Constructs a new MACD calculator with the default settings.

# indicatorMacd(data)

Computes the MACD for the given data array. Returns an array of objects with attributes:

  • macd
  • signal
  • divergence

# indicatorMacd.value([value])

Get/set the accessor function used to obtain the value to be used by the calculator from the supplied array of data. The accessor function is invoked exactly once per datum. Defaults to the identity function.

# indicatorMacd.fastPeriod([period])

Get/set the period of the 'fast' exponential moving average calculation performed by the calculator. Can be specified as a number, or as a function of the supplied array of data. Defaults to 12.

# indicatorMacd.slowPeriod([period])

Get/set the period of the 'slow' exponential moving average calculation performed by the calculator. Can be specified as a number, or as a function of the supplied array of data. Defaults to 26.

# indicatorMacd.signalPeriod([period])

Get/set the period of the 'signal' exponential moving average calculation performed by the calculator. Can be specified as a number, or as a function of the supplied array of data. Defaults to 9.

Relative Strength Index

# fc.indicatorRelativeStrengthIndex()

Constructs a new RSI calculator with the default settings.

# indicatorRelativeStrengthIndex(data)

Computes the RSI for the given data array. Returns an array of RSI values.

# indicatorRelativeStrengthIndex.value([value])

Get/set the accessor function used to obtain the value to be used by the calculator from the supplied array of data. The accessor function is invoked exactly once per datum. Defaults to the identity function.

# indicatorRelativeStrengthIndex.period([size])

Get/set the period of the relative strength index calculation performed by the calculator. Can be specified as a number, or as a function of the supplied array of data. Defaults to 14.

Stochastic Oscillator

# fc.indicatorStochasticOscillator()

Constructs a new stochastic oscillator calculator with the default settings. Returns an array of objects with attributes:

  • k: The 'k' percentage
  • d: The 'd' percentage

# indicatorStochasticOscillator(data)

Computes an array of stochastic oscillator values from the given input array.

# indicatorStochasticOscillator.closeValue([value])

Get/set the accessor function used to obtain the close price value to be used by the calculator from the supplied array of data. The accessor function is invoked exactly once per datum. Defaults to (d) => d.close.

# indicatorStochasticOscillator.highValue([value])

Get/set the accessor function used to obtain the high price value to be used by the calculator from the supplied array of data. The accessor function is invoked exactly once per datum. Defaults to (d) => d.high.

# indicatorStochasticOscillator.lowValue([value])

Get/set the accessor function used to obtain the low price value to be used by the calculator from the supplied array of data. The accessor function is invoked exactly once per datum. Defaults to (d) => d.low.

# indicatorStochasticOscillator.kPeriod([size])

Get/set the period of the '%K' calculation performed by the calculator. Can be specified as a number, or as a function of the supplied array of data. Defaults to 5.

# indicatorStochasticOscillator.dPeriod([size])

Get/set the period of the '%D' moving average calculation performed by the calculator. Can be specified as a number, or as a function of the supplied array of data. Defaults to 3.

版本与发布记录

@d3fc/d3fc-technical-indicator 共发布 77 个版本,首次发布于 2018/08/02;过去 12 个月发布了 0 个版本。

版本发布日期距今
8.1.1latest2024/06/132 年前
8.1.02021/04/295 年前
8.0.12020/07/146 年前
8.0.02020/04/166 年前
7.1.62020/04/076 年前
7.1.52020/04/026 年前

关于 @d3fc/d3fc-technical-indicator 的常见问题

@d3fc/d3fc-technical-indicator 是什么?

Components for calculating technical indicators on data series

如何安装 @d3fc/d3fc-technical-indicator?

在项目目录运行 npm install @d3fc/d3fc-technical-indicator,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:d3-array(*)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@d3fc/d3fc-technical-indicator 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@d3fc/d3fc-technical-indicator 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@d3fc/d3fc-technical-indicator 可以商用吗?

@d3fc/d3fc-technical-indicator 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@d3fc/d3fc-technical-indicator 的下载量有多少?

根据 npm 官方下载统计,@d3fc/d3fc-technical-indicator 在 2026/10/11 – 2026/11/09 这 30 天内被下载 66,668 次,日均约 2,222 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@d3fc/d3fc-technical-indicator 还在维护吗?

最新版本 8.1.1 发布于 2024/06/13(2 年前);至今共发布 77 个版本,其中过去 12 个月发布了 0 个;首次发布于 2018/08/02。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。