Git Product home page Git Product logo

ta-math's Introduction

Technical analysis math bundlephobia Codecov Total alerts

Library for calculating technical indicators and overlays. You can choose format of price data from provider and library will return result. It distributed with Typescript and Javascript (ES6, ES5).

btc-with-bollinger-bands

Check example with plotly library, ccxt data provider and BTC prices from Binance exchange.

Technical Overlays

Function Technical Overlay Tested Developed by Year
bb Bollinger Band ✔️️ John Bollinger 1980s
dema Double Exponential Moving Average ️ ✔️️ Patrick Mulloy 1994
ema Exponential Moving Average ✔️️
ebb Exponential Bollinger Band ✔️️ Based on Welford's
hma Hull Moving Average ok Alan Hull 2005
keltner Keltner Channels ✔️️ Chester Keltner 1960
psar Parabolic SAR Welles Wilder 1978
sma Simple Moving Average ✔️️
tema Triple Exponential Moving Average ️ ✔️️ Patrick Mulloy 1994
vbp Volume by Price ✔️️
vwap Volume Weighted Average Price ✔️️ James Elkins 1984
wma Weighted Moving Average ️ok John J. Murphy 1999
zigzag ZigZag Indicator ✔️️ Arthur Merrill 1977

Technical Indicators

Function Technical Indicator Tested Developed by Year
adl Accumulation / Distribution line ✔️ Marc Chaikin 1970s
atr Average True Range ✔️ Welles Wilder 1978
adx Average Directional Index ✔️ Welles Wilder 1978
ao Awesome Oscillator - Bill Williams
ac Accelerator Oscillator - Bill Williams
bbp Bollinger Bands Percent Bandwidth %B ok
cci Commodity Channel Index ✔️ Donald Lambert 1980
cho Chaikin Oscillator ok Marc Chaikin
expdev Exponential Weighted Deviation ✔️
fi Force Index ✔️
kst Know Sure Thing ✔️
macd Moving Average Convergence/Divergence ✔️ Gerald Appel 1979
madev Mean Absolute Deviation ✔️
mfi Money Flow Index (volume-weighted RSI) ✔️ Gene Quong and Avrum Soudack 1989
obv On Balance Volume ✔️ Joseph Granville 1963
roc Rate-of-Change ✔️
rsi Relative Strength Index ✔️ Welles Wilder 1978
stdev Standard Deviation ✔️️
stoch Stochastic Oscillator (Slow/Fast/Full) ✔️ George Lane 1950s
stochRsi Combines Stochastics with the RSI ✔️ Welles Wilder 1994
vi Vortex Indicator ✔️ Etienne Botes and Douglas Siepman 2010
williams Williams %R ✔️

Error methods

Function Error methods Tested
mae Mean Absolute Error ✔️
mape Mean Absulute Percentage Error ✔️
nrmse Normalized Root-Mean-Square Error ✔️
rmse Root-Mean-Square Error ✔️

Price transformations

Function Price transformation Tested
medianPrice Median Price -
typicalPrice Typical Price ✔️
trueRange True Range ✔️

Statistical methods

Function Statistical methods Tested
cov Covariation ✔️
cor Correlation ✔️
mean Mean (Average) ✔️
sd Standard deviation ✔️

Correlation matrix

correlation-matrix

Usage

  const ohlcv = [[t,o,h,l,c,v], [t2,o2,h2,l2,c2,v2],  ...  ,[tN,oN,hN,lN,cN,vN]];
  const ta = new TA(ohlcv, TA.exchangeFormat);
  const emaShort = ta.ema(10);
  const emaLong = ta.ema(21);
  const bband = ta.bb(15, 2);
  const bbUpper = bband.upper;
  const bbLower = bband.lower;
  const smaOpenPrice = TA.sma(ta.$open);

Installation

Install npm package npm i ta-math or add ta-math.js script file on web page.

2do list

  • basic indicators and overlays
  • unit tests
  • es5 with babel
  • coverage
  • good looking example
  • migrate to typescript
  • fix PSAR

Contributing

Feel free to contribute. Here reference how to implement new indicators. There are test samples in the .xls files, also you can generate testing data with 'generator.py' file. To convert columns into rows in .xls you can use this tool.

ta-math's People

Contributors

dependabot[bot] avatar hopperhuang avatar munrocket avatar renovate-bot avatar renovate[bot] avatar xzilja avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ta-math's Issues

RSI calculation appears to be wrong

Comparing to other charting sites (TradingView, Yahoo, StockCharts,etc), values appear to be off by about 10% with the latest fix.

Reverting back to the previous version fixes most of it, but needs more testing.

curious about rsi

export function rsi($close: Array<number>, window: number) {
  let gains = [0], loss = [1e-14];
  for (let i = 1, len = $close.length; i < len; i++) {
    let diff = $close[i] - $close[i - 1];
    gains.push(diff >= 0 ? diff : 0);
    loss.push(diff < 0 ? -diff : 0);
  }
  return pointwise((a: number, b: number) => 100 - 100 / (1 + a / b), ema(gains, 2 * window - 1), ema(loss, 2 * window - 1));
}
  1. why use ema here?
  2. why should the window be double?

refference : https://www.macroption.com/rsi-calculation/
i don't think you should double the window.

ta-math with Angular

Hi,

I'm interested in this library.
Can i use it with Angular 10 ? If yes, how ?

Thanks for your time !

Chart doesn't work well for minutely plots with the given example.

Current example/index.html doesn't work well for real trading data. It creates gap in the plot.

Following fix will take out weekends and non-trading hours. If including pre-post trading hours in the data then this shouldn't be an issue, but most of the users may only be working with trading data.

margin: { r: 5, t: 5, b: 50, l: 5 }, xaxis: { autorange: true, type:'date', rangebreaks:[{bounds:[13, 6.25], pattern: 'hour'}, {bounds:['sat', 'mon']}]}, yaxis: { autorange: true, type: 'linear' },

[Question] What format should "t" be in?

I've worked with few market data apis and their t (time) data is usually provided in seconds. I was trying to understand what format ta-math uses, but am not sure, is it also seconds or do I need to multiply them by 1000 to get milliseconds?

implement about Stochastic Oscillator (Full)

I think the current implement of Stochastic Oscillator (Full) is not right. Instead, it's the implement of Stochastic Oscillator (Fast)

current algorithm:

export function stoch($high: Array<number>, $low: Array<number>,
                      $close: Array<number>, window: number, signal: number, smooth: number) {
  let lowest = rolling((s: Array<number>) => Math.min(...s), $low, window);
  let highest = rolling((s: Array<number>) => Math.max(...s), $high, window);
  let K = pointwise((h: number, l: number, c: number) => 100 * (c - l) / (h - l), highest, lowest, $close); 
  if (smooth > 1) { K = sma(K, smooth) }
  return { line: K, signal: sma(K, signal) };
}

Below is the description about difference between fast, slow and full.

Fast Stochastic Oscillator:

Fast %K = %K basic calculation
Fast %D = 3-period SMA of Fast %K
Slow Stochastic Oscillator:

Slow %K = Fast %K smoothed with 3-period SMA
Slow %D = 3-period SMA of Slow %K
The Full Stochastic Oscillator is a fully customizable version of the Slow Stochastic Oscillator. Users can set the look-back period, the number of periods for slow %K and the number of periods for the %D moving average. The default parameters were used in these examples: Fast Stochastic Oscillator (14,3), Slow Stochastic Oscillator (14,3) and Full Stochastic Oscillator (14,3,3).

Full Stochastic Oscillator:

Full %K = Fast %K smoothed with X-period SMA
Full %D = X-period SMA of Full %K

compare with current algorithm, current implement is the fast one.

I recommend modify current description, change Stochastic Oscillator (Full) to Stochastic Oscillator (Fast). Meanwhile, imply another two indicator.

Reference: here

[Proposal] CodeSandbox examples

Hey 👋

I came across this lib today and after using it for few calculations, I think it has great potential (I found it very hard to find good ta libs for typescript env, that are also well tested).

It was a bit tricky to get started due to little documentation and I found that example a bit overwhelming as it was doing a lot of stuff related to drawing charts. My use case was simpler, I just want to use this lib to perform ta calculations in NodeJS env and get indicators.

This lead me to idea of how I might be able to help here in terms of contribution, would you be open to following idea?

I want to create a set of small https://codesandbox.io examples for each function that just use small dummy data array and mainly aim to provide good examples of how each function should be used. These examples could than be added to your tables in readme perhaps?

Latter on if I have time I could try to also add charts showcasing each indicator individually, but for time being I just wanted to output indicator values as text on the page.

Let me know what you think, would love to help 👍 will also help me learn the lib better.

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

File: .renovaterc.json
Error type: The renovate configuration file contains some invalid settings
Message: Configuration option bumpVersion should be a string

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.