npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

financial-indicators-package

v1.0.0

Published

A package for calculating various financial indicators

Downloads

7

Readme

financial-indicators-package

A comprehensive library for calculating various financial indicators for technical analysis.

Features

  • Moving Average Convergence Divergence (MACD)
  • Stochastic Oscillator
  • Average True Range (ATR)
  • On-Balance Volume (OBV)
  • Money Flow Index (MFI)
  • Williams %R
  • Moving Average (MA)
  • Exponential Moving Average (EMA)
  • Bollinger Bands

Installation

Install the package via npm:

npm install financial-indicators-package

Usage

Each indicator is available as a separate function. You can require and use them as needed.

Example Usage

MACD

const calculateMACD = require('financial-indicators').calculateMACD;

const data = [10, 12, 14, 13, 15, 17, 16, 18, 19, 20, 21];
const { MACDLine, signalLine } = calculateMACD(data);

console.log(`MACD Line: ${MACDLine}`);
console.log(`Signal Line: ${signalLine}`);

Stochastic Oscillator

const calculateStochasticOscillator = require('financial-indicators').calculateStochasticOscillator;

const highs = [50, 55, 60, 62, 65, 68, 70, 72, 75, 78, 80];
const lows = [40, 42, 45, 48, 50, 52, 55, 58, 60, 62, 65];
const closes = [45, 50, 55, 58, 60, 63, 65, 68, 70, 72, 75];

const stochasticOscillator = calculateStochasticOscillator(highs, lows, closes);

console.log(`Stochastic Oscillator: ${stochasticOscillator}`);

Average True Range (ATR)

const calculateATR = require('financial-indicators').calculateATR;

const highs = [10, 12, 14, 13, 15, 17, 16, 18, 19, 20, 21];
const lows = [8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18];
const closes = [9, 10, 12, 13, 14, 15, 16, 17, 18, 19, 20];

const atr = calculateATR(highs, lows, closes, 10);

console.log(`Average True Range (ATR): ${atr}`);

API

calculateMACD(data, shortPeriod = 12, longPeriod = 26, signalPeriod = 9)

Calculates the MACD (Moving Average Convergence Divergence) line and the signal line.

  • data: Array of closing prices.
  • shortPeriod: Number of periods for the short-term EMA. Default is 12.
  • longPeriod: Number of periods for the long-term EMA. Default is 26.
  • signalPeriod: Number of periods for the signal line EMA. Default is 9.

Returns an object with MACDLine and signalLine.

calculateStochasticOscillator(highs, lows, closes, period = 14)

Calculates the Stochastic Oscillator.

  • highs: Array of high prices.
  • lows: Array of low prices.
  • closes: Array of closing prices.
  • period: Number of periods. Default is 14.

Returns the Stochastic Oscillator value.

calculateATR(highs, lows, closes, period = 14)

Calculates the Average True Range (ATR).

  • highs: Array of high prices.
  • lows: Array of low prices.
  • closes: Array of closing prices.
  • period: Number of periods. Default is 14.

Returns the ATR value.

calculateOBV(closes, volumes)

Calculates the On-Balance Volume (OBV).

  • closes: Array of closing prices.
  • volumes: Array of volumes.

Returns the OBV value.

calculateMFI(highs, lows, closes, volumes, period = 14)

Calculates the Money Flow Index (MFI).

  • highs: Array of high prices.
  • lows: Array of low prices.
  • closes: Array of closing prices.
  • volumes: Array of volumes.
  • period: Number of periods. Default is 14.

Returns the MFI value.

calculateWilliamsR(highs, lows, closes, period = 14)

Calculates the Williams %R.

  • highs: Array of high prices.
  • lows: Array of low prices.
  • closes: Array of closing prices.
  • period: Number of periods. Default is 14.

Returns the Williams %R value.

Contributing

Contributions are welcome! Please open an issue or submit a pull request on GitHub.

License

This project is licensed under the MIT License. See the LICENSE file for details.