All Projects → kaelzhang → finmath

kaelzhang / finmath

Licence: other
The collections of simple, weighted, exponential, smoothed moving averages.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to finmath

exponential-moving-average
Calculate an exponential moving average from an array of numbers.
Stars: ✭ 41 (-16.33%)
Mutual labels:  math, exponential-moving-average, moving-average
Yykline
iOS YYKline:Kline、Chart、Volume、Scroll、Scale、MACD、KDJ、K线图、分时图...
Stars: ✭ 2,318 (+4630.61%)
Mutual labels:  ema, ma
HLML
Auto-generated maths library for C and C++ based on HLSL/Cg
Stars: ✭ 23 (-53.06%)
Mutual labels:  math, math-library
SCNMathExtensions
Math extensions for SCNVector3, SCNQuaternion, SCNMatrix4
Stars: ✭ 32 (-34.69%)
Mutual labels:  math, math-library
MathImprove
Modify and Improve math expressions.
Stars: ✭ 13 (-73.47%)
Mutual labels:  math, math-library
pyGameMath
Math library for game programming in python.
Stars: ✭ 20 (-59.18%)
Mutual labels:  math, math-library
math eval
✖️➕➖➗ `math_eval` safely evaluates mathematical expressions
Stars: ✭ 33 (-32.65%)
Mutual labels:  math
my-math-notes
All of my math stuff from grad school.
Stars: ✭ 41 (-16.33%)
Mutual labels:  math
arabic-mathjax
Beautiful Arabic Math on all browsers. An extension for MathJax v2.
Stars: ✭ 12 (-75.51%)
Mutual labels:  math
maths-for-deep-learning-ai
A open source book covering the foundational maths of deep learning and machine learning using TensorFlow
Stars: ✭ 35 (-28.57%)
Mutual labels:  math
Angles.js
Angles.js is a collection of functions to work with angles
Stars: ✭ 16 (-67.35%)
Mutual labels:  math
LaTeXStrings.jl
convenient input and display of LaTeX equation strings for the Julia language
Stars: ✭ 152 (+210.2%)
Mutual labels:  math
FixedPoint-Sharp
Fixed point math with 48.16 precision (based on lib by https://github.com/fholm)
Stars: ✭ 114 (+132.65%)
Mutual labels:  math
starling-developer-sdk
The official JavaScript development kit for building on the Starling API
Stars: ✭ 45 (-8.16%)
Mutual labels:  fintech
rclc
Mathematical expression calculator with big integers, floats, common fractions, and complex numbers support
Stars: ✭ 24 (-51.02%)
Mutual labels:  math
lit
Literature for the self-taught AI practitioner! 📚
Stars: ✭ 199 (+306.12%)
Mutual labels:  math
arogozhnikov.github.io
'Brilliantly wrong' blog, Machine Learning visualizations live here
Stars: ✭ 120 (+144.9%)
Mutual labels:  math
binary.com-bot
Scripts for using on Binary.com Bots.
Stars: ✭ 60 (+22.45%)
Mutual labels:  moving-average
mpsl
Shader-Like Mathematical Expression JIT Engine for C++ Language
Stars: ✭ 52 (+6.12%)
Mutual labels:  math
autoscheduler
Staffjoy Suite (V1) Deprecated Microservice - Original autoscheduling algorithm, which combines shift creation and assignment. No longer compatible with open-source suite.
Stars: ✭ 68 (+38.78%)
Mutual labels:  math

Build Status Coverage

MAINTENANCE WARNING

This module is lack of maintenance.

If you are familiar with python programming maybe you could check stock-pandas which provides powerful statistic indicators support, and is backed by numpy and pandas.

The performance of stock-pandas is many times higher than JavaScript libraries, and can be directly used by machine learning programs.


finmath

The complete collection of mathematical utility methods for FinTech , including:

And all finmath methods also handle empty values.

Table of Contents

install

$ npm i finmath

usage

import {
  ma, dma, ema, sma, wma,
  macd,
  boll,
  sd,
  hhv, llv,
  add, sub, mul, div
} from 'finmath'

ma([1, 2, 3, 4, 5], 2)
// [<1 empty item>, 1.5, 2.5, 3.5, 4.5]

Simple Moving Average: ma(data, size)

type Data = EmptyableArray<number>
  • data Data the collection of data inside which empty values are allowed. Empty values are useful if a stock is suspended.
  • size number the size of the periods.

Returns Data

Type Array<number|Empty> represents an array of numbers or empty items. And every method of finmath does NOT accepts items that are not numbers.

[1,, 2, 3] // OK ✅

[1, undefined, 2, 3] // NOT OK ❌

[1, null, 2, 3] // NOT OK ❌

Special Cases

// If the size is less than `1`
ma([1, 2, 3], 0.5)       // [1, 2, 3]

// If the size is larger than data length
ma([1, 2, 3], 5)         // [<3 empty items>]

ma([, 1,, 3, 4, 5], 2)
// [<2 empty items>, 0.5, 1.5, 3.5, 4.5]

And all of the other moving average methods have similar mechanism.

Dynamic Weighted Moving Average: dma(data, alpha, noHead)

  • data
  • alpha Data the coefficient or list of coefficients alpha represents the degree of weighting decrease for each datum.
    • If alpha is a number, then the weighting decrease for each datum is the same.
    • If alpha larger than 1 is invalid, then the return value will be an empty array of the same length of the original data.
    • If alpha is an array, then it could provide different decreasing degree for each datum.
  • noHead Boolean= whether we should abandon the first DMA.

Returns Data

dma([1, 2, 3], 2)    // [<3 empty items>]

dma([1, 2, 3], 0.5)  // [1, 1.5, 2.25]

dma([1, 2, 3, 4, 5], [0.1, 0.2, 0.1])
// [1, 1.2, 1.38]

Exponential Moving Average: ema(data, size)

Calulates the most frequent used exponential average which covers about 86% of the total weight (when alpha = 2 / (N + 1)).

  • data
  • size Number the size of the periods.

Returns Data

Smoothed Moving Average: sma(data, size, times)

Also known as the modified moving average or running moving average, with alpha = times / size.

  • data
  • size
  • times? Number=1

Returns Data

Weighted Moving Average: wma(data, size)

Calculates convolution of the datum points with a fixed weighting function.

Returns Data

MACD: macd(data, slowPeriods?, fastPeriods?, signalPeriods?)

MACD, short for Moving Average Convergence / Divergence, is a trading indicator used in technical analysis of stock prices, created by Gerald Appel in the late 1970s.

  • data Data the collection of prices
  • slowPeriods? number=26 the size of slow periods. Defaults to 26
  • fastPeriods? number=12 the size of fast periods. Defaults to 12
  • signalPeriods? number=9 the size of periods to calculate the MACD signal line.

Returns MACDGraph

macd(data)

// which returns:
// {
//   MACD: <Array>,
//   signal: <Array>,
//   histogram: <Array>
// }

struct MACDGraph

  • MACD Data the difference between EMAs of the fast periods and EMAs of the slow periods.
  • signal Data the EMAs of the MACD
  • histogram Data MACD minus signal

In some countries, such as China, the three series above are commonly known as:

MACD       -> DIF
signal     -> DEA
histogram  -> MACD

Bollinger Bands: boll(data, size?, times?, options?)

boll([1, 2, 4, 8], 2, 2)
// {
//   upper: [, 2.5, 5, 10],
//   mid  : [, 1.5, 3, 6],
//   lower: [, 0.5, 1, 2]
// }
  • data Data the collection of data
  • size? Number=20 the period size, defaults to 20
  • times? Number=2 the times of standard deviation between the upper band and the moving average.
  • options? Object= optional options
    • ma? Data= the moving averages of the provided datum and period size. This option is used to prevent duplicate calculation of moving average.
    • sd? Data= the standard average of the provided datum and period size

Returns Array<Band> the array of the Band object.

interface Band {
  // the value of the upper band
  upper: number
  // the value middle band (simple moving average)
  mid: number
  // the value of the lower band
  lower: number
}

Standard deviations: sd(data, size)

  • data Data the collection of data
  • size number the sample size of

Returns Data the array of standard deviations.

sd([1, 2, 4, 8], 2)         // [<1 empty item>, 0.5, 1, 2]

sd([1, 2, 3, 4, 5, 6], 4)
// [
//   <3 empty items>,
//   1.118033988749895,
//   1.118033988749895,
//   1.118033988749895
// ]

Highest High Values: hhv(data, periods)

  • data Data the array of closing prices.
  • periods number the size of periods

Returns Data the highest high values of closing prices over the preceding periods periods (periods includes the current time).

const array = [1, 2, 4, 1]

hhv(array, 2)    // [, 2, 4, 4]
hhv(array)       // 4
hhv(array, 5)    // [<4 empty items>]
hhv(array, 1)    // [1, 2, 4, 1]

hhv(array, 2)    // [, 1, 2, 2]

Lowest Low Values: llv(data, periods)

Instead, returns Data the lowest low values.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].