qntjs-lib 1.0.3 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,15 +1,15 @@
1
1
  # qntjs-lib
2
2
 
3
- High-performance JavaScript and TypeScript library of technical‑analysis indicators, array utilities, and numerical helpers.
3
+ A pure fast JavaScript/TypeScript library of technical‑analysis indicators, trading performance/risk metrics, array utilities, and numerical helpers.
4
4
 
5
- This repository implements a wide set of TA indicators (EMA, TEMA, T3, MFI, KAMA, etc.), vectorized math functions, and statistical helpers. Implementations are optimized for two common usage patterns:
5
+ This repository implements a wide set of TA indicators (EMA, TEMA, T3, MFI, KAMA, etc.), common trading performance metrics/utilities, vectorized math functions, and statistical helpers. Where applicable, implementations are optimized for two common usage patterns:
6
6
 
7
7
  - NaN‑aware workflows (default): functions are NaN‑aware and will skip NaN values where appropriate.
8
8
  - Dense fast‑path: when you know inputs contain no NaNs you can opt into a dense, faster implementation by passing `skipna=false` to supported functions.
9
9
 
10
10
  By default the main (typed) build returns typed arrays (e.g. `Float64Array`) for better numeric performance and predictable memory layout. A companion "untyped" build exposes the same API but returns plain `number[]` values for easier interoperability with plain JavaScript code.
11
11
 
12
- The library has no runtime dependencies and is zero-dependency by design. It can be used in browser web applications or in Node.js environments that support ESM imports.
12
+ The library has no runtime dependencies. It can be used in browser web applications or in Node.js environments that support ESM imports.
13
13
 
14
14
  ## Quick Start
15
15
 
@@ -55,12 +55,78 @@ ta.sma(pricesWithGaps, 5);
55
55
  ta.sma(densePrices, 5, false);
56
56
  ```
57
57
 
58
- ## API highlights
58
+ ## Modules and examples
59
+
60
+ Overview of top-level modules and minimal examples showing common usage patterns.
61
+
62
+ ### `ta` — technical indicators (moving averages, oscillators, volatility measures).
63
+
64
+ Example: compute an exponential moving average (EMA)
65
+
66
+ ```js
67
+ import { ta } from 'qntjs-lib';
68
+ const prices = [1,2,3,4,5,6,7];
69
+ const ema3 = ta.ema(prices, 3); // Float64Array
70
+ ```
71
+
72
+ ### `math` — array-oriented math primitives and elementwise operations.
73
+
74
+ Example: elementwise subtract and scale
75
+
76
+ ```js
77
+ import { math } from 'qntjs-lib';
78
+ const a = [1,2,3];
79
+ const b = [0.1,0.1,0.1];
80
+ const diff = math.sub(a, b); // Float64Array of a-b
81
+ const scaled = math.scale(diff, 100);
82
+ ```
83
+
84
+ ### `perf` — performance and risk helpers (returns, drawdowns, volatility, VaR/ES, ratios).
85
+
86
+ Example: compute daily returns, Sharpe, and parametric VaR
87
+
88
+ ```js
89
+ import { perf } from 'qntjs-lib';
90
+ const prices = [100, 110, 105, 120];
91
+ const rets = perf.returns(prices); // simple returns (Float32Array)
92
+ const daily = perf.dailyReturns([Date.now(), Date.now() + 86400000], [0.01, 0.02]);
93
+ const sr = perf.sharpe([0.01, -0.02, 0.03]);
94
+ const varP = perf.valueAtRisk([0.01, -0.02, 0.03], 0.05, 'parametric');
95
+ ```
96
+
97
+ ### `stats` — aggregations, percentiles, variance, sampling utilities.
98
+
99
+ Example: quantile and sample
100
+
101
+ ```js
102
+ import { stats } from 'qntjs-lib';
103
+ const v = stats.quantile([1,2,3,4,5], 0.1);
104
+ const sample = stats.sample([1,2,3,4,5], 3);
105
+ ```
106
+
107
+ ### `arr` — low-level array utilities (NaN handling, masks, fill/shift helpers).
108
+
109
+ Example: drop NaNs and forward-fill
110
+
111
+ ```js
112
+ import { arr } from 'qntjs-lib';
113
+ const a = [NaN, 1, NaN, 2];
114
+ const clean = arr.dropna(a);
115
+ const filled = arr.ffill(a);
116
+ ```
117
+
118
+ ## List of available API
119
+
120
+ - **`arr.*`** : `isna`, `notna`, `fillna`, `ffill`, `bfill`, `replace`, `dropna`, `allna`, `equals`, `countna`, `havena`, `lag`
121
+
122
+ - **`math.*`** : `add`, `sub`, `avg`, `mul`, `div`, `scale`, `abs`, `sign`, `round`, `floor`, `ceil`, `eq`, `neq`, `gt`, `gte`, `lt`, `lte`, `and`, `or`, `not`, `clamp`, `sum`, `prod`, `min`, `max`, `argmin`, `argmax`, `cumsum`, `cumprod`, `cummax`, `cummin`, `rollsum`, `rollmin`, `rollmax`, `rollminmax`, `rollprod`, `rollargmin`, `rollargmax`, `diff`, `randuniform`, `randnormal`, `dot`, `norm`, `ols`, `olsMulti`
123
+
124
+ - **`stats.*`** : `mean`, `hmean`, `gmean`, `mad`, `skew`, `kurtosis`, `median`, `quantile`, `percentiles`, `var`, `covar`, `stdev`, `corr`, `zscore`, `norminmax`, `winsorize`, `sample`, `shuffle`, `bootstrap`
125
+
126
+ - **`ta.*`** : `dema`, `ema`, `hma`, `kama`, `sma`, `wma`, `vwma`, `trima`, `t3`, `tema`, `rma`, `ao`, `apo`, `aroon`, `change`, `cmo`, `kst`, `macd`, `mom`, `ppo`, `roc`, `rsi`, `stoch`, `stochrsi`, `ultosc`, `wpr`, `supertrend`, `adx`, `adxr`, `dx`, `cci`, `di`, `dpo`, `ichimoku`, `psar`, `atr`, `tr`, `natr`, `bb`, `bbw`, `donchian`, `keltner`, `adosc`, `obv`, `pnvi`, `wad`, `ad`, `mfi`, `cross`, `crossover`, `crossunder`, `rising`, `falling`
127
+
128
+ - **`perf.*`** : `returns`, `logreturns`, `cumreturns`, `cagr`, `dailyReturns`, `dd`, `maxdd`, `maxddDetails`, `dduration`, `rollmaxdd`, `recoveryFactor`, `calmarRatio`, `ulcerIndex`, `rollUlcerIndex`, `sharpe`, `sortino`, `rollsharpe`, `rollsortino`, `vol`, `rollvol`, `valueAtRisk`, `expectedShortfall`, `tailRatio`, `omegaRatio`
59
129
 
60
- - `arr.*` — array utilities: `isna`, `notna`, `fillna`, `ffill`, `bfill`, `replace`, `dropna`, `allna`, `equals`, `countna`, `havena`, `lag`
61
- - `math.*` — math helpers: `add`, `sub`, `avg`, `mul`, `div`, `scale`, `abs`, `sign`, `round`, `floor`, `ceil`, `eq`, `neq`, `gt`, `gte`, `lt`, `lte`, `and`, `or`, `not`, `clamp`, `sum`, `prod`, `min`, `max`, `argmin`, `argmax`, `cumsum`, `cumprod`, `cummax`, `cummin`, `rollsum`, `rollmin`, `rollmax`, `rollminmax`, `rollprod`, `rollargmin`, `rollargmax`, `diff`, `randuniform`, `randnormal`, `dot`, `norm`, `ols`, `olsMulti`
62
- - `stats.*` — statistical helpers: `mean`, `hmean`, `gmean`, `mad`, `skew`, `kurtosis`, `median`, `quantile`, `percentiles`, `var`, `covar`, `stdev`, `corr`, `zscore`, `norminmax`, `winsorize`, `sample`, `shuffle`, `bootstrap`
63
- - `ta.*` — technical indicators: `dema`, `ema`, `hma`, `kama`, `sma`, `wma`, `vwma`, `trima`, `t3`, `tema`, `rma`, `ao`, `apo`, `aroon`, `change`, `cmo`, `kst`, `macd`, `mom`, `ppo`, `roc`, `rsi`, `stoch`, `stochrsi`, `ultosc`, `wpr`, `supertrend`, `adx`, `adxr`, `dx`, `cci`, `di`, `dpo`, `ichimoku`, `psar`, `atr`, `tr`, `natr`, `bb`, `bbw`, `donchian`, `keltner`, `adosc`, `obv`, `pnvi`, `wad`, `ad`, `mfi`, `cross`, `crossover`, `crossunder`, `rising`, `falling`
64
130
 
65
131
  ## Tests & development
66
132