Naughty Platypus Memorabilia

# npm

Need private packages and team management tools?Check out npm Teams »

## finmath

2.0.0 • Public • Published

# finmath

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

And all finmath methods also handle empty values.

## Simple Moving Average: `ma(data, size)`

• 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.

#### Special Cases

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`

## 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`

### 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:

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

• 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.

## Standard deviations: sd(data, size)

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

Returns `Data` the array of standard deviations.

## 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).

## Lowest Low Values: llv(data, periods)

Instead, returns `Data` the lowest low values.

MIT

### Install

`npm i finmath`

56

2.0.0

MIT

26.9 kB

25