{"id":15645284,"url":"https://github.com/kaelzhang/finmath","last_synced_at":"2025-04-30T11:11:08.985Z","repository":{"id":57154632,"uuid":"47863502","full_name":"kaelzhang/finmath","owner":"kaelzhang","description":"The collections of simple, weighted, exponential, smoothed moving averages.","archived":false,"fork":false,"pushed_at":"2021-03-02T03:29:33.000Z","size":65,"stargazers_count":55,"open_issues_count":0,"forks_count":20,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-11-07T01:16:48.516Z","etag":null,"topics":["dmarc","dynamic-weighted-moving-average","ema","exponential-moving-average","fintech","ma","math","math-library","moving-average","sma","weighted-moving-average"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kaelzhang.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-12-12T04:04:16.000Z","updated_at":"2024-06-07T07:40:39.000Z","dependencies_parsed_at":"2022-09-06T15:40:41.387Z","dependency_job_id":null,"html_url":"https://github.com/kaelzhang/finmath","commit_stats":null,"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaelzhang%2Ffinmath","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaelzhang%2Ffinmath/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaelzhang%2Ffinmath/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaelzhang%2Ffinmath/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kaelzhang","download_url":"https://codeload.github.com/kaelzhang/finmath/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223574724,"owners_count":17167550,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dmarc","dynamic-weighted-moving-average","ema","exponential-moving-average","fintech","ma","math","math-library","moving-average","sma","weighted-moving-average"],"created_at":"2024-10-03T12:05:46.979Z","updated_at":"2024-11-09T03:14:08.417Z","avatar_url":"https://github.com/kaelzhang.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/kaelzhang/finmath.svg?branch=master)](https://travis-ci.org/kaelzhang/finmath)\n[![Coverage](https://codecov.io/gh/kaelzhang/finmath/branch/master/graph/badge.svg)](https://codecov.io/gh/kaelzhang/finmath)\n\u003c!-- optional npm version\n[![NPM version](https://badge.fury.io/js/moving-averages.svg)](http://badge.fury.io/js/moving-averages)\n--\u003e\n\u003c!-- optional npm downloads\n[![npm module downloads per month](http://img.shields.io/npm/dm/moving-averages.svg)](https://www.npmjs.org/package/moving-averages)\n--\u003e\n\u003c!-- optional dependency status\n[![Dependency Status](https://david-dm.org/kaelzhang/finmath.svg)](https://david-dm.org/kaelzhang/finmath)\n--\u003e\n\n# MAINTENANCE WARNING\n\nThis module is lack of maintenance.\n\nIf you are familiar with python programming maybe you could check [**stock-pandas**](https://github.com/kaelzhang/stock-pandas) which provides powerful statistic indicators support, and is backed by [`numpy`](https://numpy.org/) and [`pandas`](https://pandas.pydata.org/).\n\nThe performance of [**stock-pandas**](https://github.com/kaelzhang/stock-pandas) is many times higher than JavaScript libraries, and can be directly used by machine learning programs.\n\n****\n\n# finmath\n\nThe complete collection of mathematical utility methods for [FinTech](https://en.wikipedia.org/wiki/Financial_technology) , including:\n\n- [Moving averages](https://en.wikipedia.org/wiki/Moving_average)\n- [MACD](https://en.wikipedia.org/wiki/MACD)\n- [Bollinger bands](https://en.wikipedia.org/wiki/Bollinger_Bands)\n- [Standard deviations](https://en.wikipedia.org/wiki/Standard_deviation)\n- Highest high values / Lowest low values\n\nAnd all finmath methods also handle empty values.\n\n# Table of Contents\n\n- [simple Moving Average (MA)](#simple-moving-average-madata-size)\n- [Dynamic weighted Moving Average (DMA)](#dynamic-weighted-moving-average-dmadata-alpha-nohead)\n- [Exponential Moving Average (EMA)](#exponential-moving-average-emadata-size)\n- [Smoothed Moving Average (SMA)](#smoothed-moving-average-smadata-size-times)\n- [Weighted Moving Average (WMA)](#weighted-moving-average-wmadata-size)\n- [MACD](#MACD-macddata-slowPeriods-fastPeriods-signalPeriods)\n- [BOLLinger bands (BOLL)](#bollinger-bands-bolldata-size-times-options)\n- [Standard Deviations (SD)](#standard-deviations-sddata-size)\n- [Highest High Values (HHV)](#highest-high-values-hhvdata-periods)\n- [Lowest Low Values (LLV)](#lowest-low-values-llvdata-periods)\n\n## install\n\n```sh\n$ npm i finmath\n```\n\n## usage\n\n```js\nimport {\n  ma, dma, ema, sma, wma,\n  macd,\n  boll,\n  sd,\n  hhv, llv,\n  add, sub, mul, div\n} from 'finmath'\n\nma([1, 2, 3, 4, 5], 2)\n// [\u003c1 empty item\u003e, 1.5, 2.5, 3.5, 4.5]\n```\n\n## Simple Moving Average: `ma(data, size)`\n\n```ts\ntype Data = EmptyableArray\u003cnumber\u003e\n```\n\n- **data** `Data` the collection of data inside which empty values are allowed. Empty values are useful if a stock is suspended.\n- **size** `number` the size of the periods.\n\nReturns `Data`\n\nType `Array\u003cnumber|Empty\u003e` represents an array of numbers or empty items. And every method of `finmath` does **NOT** accepts items that are not numbers.\n\n```js\n[1,, 2, 3] // OK ✅\n\n[1, undefined, 2, 3] // NOT OK ❌\n\n[1, null, 2, 3] // NOT OK ❌\n```\n\n#### Special Cases\n\n```js\n// If the size is less than `1`\nma([1, 2, 3], 0.5)       // [1, 2, 3]\n\n// If the size is larger than data length\nma([1, 2, 3], 5)         // [\u003c3 empty items\u003e]\n\nma([, 1,, 3, 4, 5], 2)\n// [\u003c2 empty items\u003e, 0.5, 1.5, 3.5, 4.5]\n```\n\nAnd all of the other moving average methods have similar mechanism.\n\n## Dynamic Weighted Moving Average: `dma(data, alpha, noHead)`\n\n- **data**\n- **alpha** `Data` the coefficient or list of coefficients `alpha` represents the degree of weighting decrease for each datum.\n  - If `alpha` is a number, then the weighting decrease for each datum is the same.\n  - If `alpha` larger than `1` is invalid, then the return value will be an empty array of the same length of the original data.\n  - If `alpha` is an array, then it could provide different decreasing degree for each datum.\n- **noHead** `Boolean=` whether we should abandon the first DMA.\n\nReturns `Data`\n\n```js\ndma([1, 2, 3], 2)    // [\u003c3 empty items\u003e]\n\ndma([1, 2, 3], 0.5)  // [1, 1.5, 2.25]\n\ndma([1, 2, 3, 4, 5], [0.1, 0.2, 0.1])\n// [1, 1.2, 1.38]\n```\n\n## Exponential Moving Average: `ema(data, size)`\n\nCalulates the most frequent used exponential average which covers about 86% of the total weight (when `alpha = 2 / (N + 1)`).\n\n- **data**\n- **size** `Number` the size of the periods.\n\nReturns `Data`\n\n## Smoothed Moving Average: `sma(data, size, times)`\n\nAlso known as the modified moving average or running moving average, with `alpha = times / size`.\n\n- **data**\n- **size**\n- **times?** `Number=1`\n\nReturns `Data`\n\n## Weighted Moving Average: `wma(data, size)`\n\nCalculates convolution of the datum points with a fixed weighting function.\n\nReturns `Data`\n\n## MACD: macd(data, slowPeriods?, fastPeriods?, signalPeriods?)\n\n**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.\n\n- **data** `Data` the collection of prices\n- **slowPeriods?** `number=26` the size of slow periods. Defaults to `26`\n- **fastPeriods?** `number=12` the size of fast periods. Defaults to `12`\n- **signalPeriods?** `number=9` the size of periods to calculate the MACD signal line.\n\nReturns `MACDGraph`\n\n```js\nmacd(data)\n\n// which returns:\n// {\n//   MACD: \u003cArray\u003e,\n//   signal: \u003cArray\u003e,\n//   histogram: \u003cArray\u003e\n// }\n```\n\n### struct `MACDGraph`\n\n- **MACD** `Data` the difference between [EMAs](https://www.npmjs.com/package/moving-averages#exponential-moving-average-emadata-size) of the fast periods and EMAs of the slow periods.\n- **signal** `Data` the EMAs of the `MACD`\n- **histogram** `Data` `MACD` minus `signal`\n\nIn some countries, such as China, the three series above are commonly known as:\n\n```sh\nMACD       -\u003e DIF\nsignal     -\u003e DEA\nhistogram  -\u003e MACD\n```\n\n## Bollinger Bands: boll(data, size?, times?, options?)\n\n```js\nboll([1, 2, 4, 8], 2, 2)\n// {\n//   upper: [, 2.5, 5, 10],\n//   mid  : [, 1.5, 3, 6],\n//   lower: [, 0.5, 1, 2]\n// }\n```\n\n- **data** `Data` the collection of data\n- **size?** `Number=20` the period size, defaults to `20`\n- **times?** `Number=2` the times of standard deviation between the upper band and the moving average.\n- **options?** `Object=` optional options\n  - **ma?** `Data=` the moving averages of the provided `datum` and period `size`. This option is used to prevent duplicate calculation of moving average.\n  - **sd?** `Data=` the standard average of the provided `datum` and period `size`\n\nReturns `Array\u003cBand\u003e` the array of the `Band` object.\n\n```ts\ninterface Band {\n  // the value of the upper band\n  upper: number\n  // the value middle band (simple moving average)\n  mid: number\n  // the value of the lower band\n  lower: number\n}\n```\n\n## Standard deviations: sd(data, size)\n\n- **data** `Data` the collection of data\n- **size** `number` the sample size of\n\nReturns `Data` the array of standard deviations.\n\n```js\nsd([1, 2, 4, 8], 2)         // [\u003c1 empty item\u003e, 0.5, 1, 2]\n\nsd([1, 2, 3, 4, 5, 6], 4)\n// [\n//   \u003c3 empty items\u003e,\n//   1.118033988749895,\n//   1.118033988749895,\n//   1.118033988749895\n// ]\n```\n\n## Highest High Values: hhv(data, periods)\n\n- **data** `Data` the array of closing prices.\n- **periods** `number` the size of periods\n\nReturns `Data` the highest high values of closing prices over the preceding `periods` periods (periods includes the current time).\n\n```js\nconst array = [1, 2, 4, 1]\n\nhhv(array, 2)    // [, 2, 4, 4]\nhhv(array)       // 4\nhhv(array, 5)    // [\u003c4 empty items\u003e]\nhhv(array, 1)    // [1, 2, 4, 1]\n\nhhv(array, 2)    // [, 1, 2, 2]\n```\n\n## Lowest Low Values: llv(data, periods)\n\nInstead, returns `Data` the lowest low values.\n\n## License\n\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkaelzhang%2Ffinmath","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkaelzhang%2Ffinmath","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkaelzhang%2Ffinmath/lists"}