ferro-ta-wasm 1.1.1 → 1.1.2
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 +63 -111
- package/node/README.md +125 -0
- package/node/ferro_ta_wasm_bg.wasm +0 -0
- package/package.json +21 -6
- package/web/README.md +125 -0
- package/web/ferro_ta_wasm.d.ts +1707 -0
- package/web/ferro_ta_wasm.js +4321 -0
- package/web/ferro_ta_wasm_bg.wasm +0 -0
- package/web/ferro_ta_wasm_bg.wasm.d.ts +347 -0
- package/pkg/README.md +0 -173
- package/pkg/ferro_ta_wasm_bg.wasm +0 -0
- package/pkg/package.json +0 -13
- /package/{pkg → node}/ferro_ta_wasm.d.ts +0 -0
- /package/{pkg → node}/ferro_ta_wasm.js +0 -0
- /package/{pkg → node}/ferro_ta_wasm_bg.wasm.d.ts +0 -0
package/README.md
CHANGED
|
@@ -1,53 +1,42 @@
|
|
|
1
1
|
# ferro-ta WASM
|
|
2
2
|
|
|
3
|
-
WebAssembly bindings for the [ferro-ta](https://github.com/pratikbhadane24/ferro-ta) technical analysis library.
|
|
3
|
+
WebAssembly bindings for the [ferro-ta](https://github.com/pratikbhadane24/ferro-ta) technical analysis library. Full feature parity with the Python and Rust core packages.
|
|
4
4
|
|
|
5
5
|
## Install from npm
|
|
6
6
|
|
|
7
|
-
Once published, install the Node.js build from npm:
|
|
8
|
-
|
|
9
7
|
```bash
|
|
10
8
|
npm install ferro-ta-wasm
|
|
11
9
|
```
|
|
12
10
|
|
|
13
11
|
```javascript
|
|
14
|
-
const
|
|
12
|
+
const ferro = require('ferro-ta-wasm');
|
|
15
13
|
|
|
16
14
|
const close = new Float64Array([44.34, 44.09, 44.15, 43.61, 44.33, 44.83, 45.10]);
|
|
17
|
-
|
|
18
|
-
console.log('
|
|
15
|
+
console.log('SMA:', Array.from(ferro.sma(close, 3)));
|
|
16
|
+
console.log('RSI:', Array.from(ferro.rsi(close, 14)));
|
|
19
17
|
```
|
|
20
18
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
|
28
|
-
|
|
29
|
-
|
|
|
30
|
-
|
|
|
31
|
-
|
|
|
32
|
-
|
|
|
33
|
-
|
|
|
34
|
-
|
|
|
35
|
-
|
|
|
36
|
-
|
|
|
37
|
-
|
|
|
38
|
-
|
|
|
39
|
-
|
|
|
40
|
-
|
|
|
41
|
-
|
|
42
|
-
### Adding more indicators
|
|
43
|
-
|
|
44
|
-
WASM exports live in `src/lib.rs` and can either implement logic directly or delegate to `ferro_ta_core`.
|
|
45
|
-
To add a new indicator:
|
|
46
|
-
|
|
47
|
-
1. Add a `#[wasm_bindgen]` export in `src/lib.rs` (prefer delegating to `ferro_ta_core` where possible).
|
|
48
|
-
2. Add at least two `#[wasm_bindgen_test]` tests covering output length and a known value.
|
|
49
|
-
3. Update this README table.
|
|
50
|
-
4. Run `wasm-pack test --node` to verify.
|
|
19
|
+
## Available Indicators (200+ exports)
|
|
20
|
+
|
|
21
|
+
| Category | Functions | Examples |
|
|
22
|
+
|----------|-----------|----------|
|
|
23
|
+
| Overlap Studies (20) | Moving averages, bands, SAR | `sma`, `ema`, `wma`, `dema`, `tema`, `trima`, `kama`, `t3`, `bbands`, `macd`, `macdfix`, `macdext`, `sar`, `sarext`, `mama`, `midpoint`, `midprice`, `ma`, `mavp`, `hull_ma` |
|
|
24
|
+
| Momentum (26) | Oscillators, directional movement | `rsi`, `mom`, `stoch`, `stochf`, `adx`, `adxr`, `dx`, `plus_di`, `minus_di`, `roc`, `willr`, `aroon`, `aroonosc`, `cci`, `bop`, `stochrsi`, `apo`, `ppo`, `cmo`, `trix_indicator`, `ultosc` |
|
|
25
|
+
| Candlestick Patterns (61) | All TA-Lib patterns | `cdlhammer`, `cdlengulfing`, `cdldoji`, `cdlmorningstar`, `cdlshootingstar`, ... (all 61) |
|
|
26
|
+
| Volatility (3) | True range, ATR | `atr`, `natr`, `trange` |
|
|
27
|
+
| Volume (6) | On-balance volume, accumulation | `obv`, `mfi`, `vwap`, `vwma`, `ad`, `adosc` |
|
|
28
|
+
| Price Transforms (4) | Synthetic prices | `avgprice`, `medprice`, `typprice`, `wclprice` |
|
|
29
|
+
| Cycle / Hilbert (6) | Hilbert Transform suite | `ht_trendline`, `ht_dcperiod`, `ht_dcphase`, `ht_phasor`, `ht_sine`, `ht_trendmode` |
|
|
30
|
+
| Statistics (10) | Regression, correlation | `stddev`, `var`, `linearreg`, `linearreg_slope`, `linearreg_intercept`, `linearreg_angle`, `tsf`, `beta_rolling`, `correl` |
|
|
31
|
+
| Math (19) | Operators and transforms | `math_add`, `math_sub`, `math_mult`, `math_div`, `transform_sin`, `transform_cos`, `transform_exp`, `transform_sqrt`, ... |
|
|
32
|
+
| Extended (10) | Supertrend, channels, Ichimoku | `supertrend`, `donchian`, `keltner_channels`, `ichimoku`, `pivot_points`, `chandelier_exit`, `choppiness_index` |
|
|
33
|
+
| Streaming API (9 classes) | Bar-by-bar stateful | `WasmStreamingSMA`, `WasmStreamingEMA`, `WasmStreamingRSI`, `WasmStreamingATR`, `WasmStreamingBBands`, `WasmStreamingMACD`, `WasmStreamingStoch`, `WasmStreamingVWAP`, `WasmStreamingSupertrend` |
|
|
34
|
+
| Options (14) | Pricing, Greeks, IV | `black_scholes_price`, `black_76_price`, `black_scholes_greeks`, `implied_volatility`, `iv_rank`, `smile_metrics`, ... |
|
|
35
|
+
| Futures (12) | Basis, roll, curve | `futures_basis`, `annualized_basis`, `roll_yield`, `weighted_continuous`, `calendar_spreads`, `curve_summary`, ... |
|
|
36
|
+
| Backtesting (9) | Signal generation, engines | `backtest_core`, `backtest_ohlcv`, `rsi_threshold_signals`, `macd_crossover_signals`, `walk_forward_indices`, `monte_carlo_bootstrap`, ... |
|
|
37
|
+
| Alerts & Regime (7) | Signals and regime detection | `check_threshold`, `check_cross`, `regime_adx`, `regime_combined`, `detect_breaks_cusum` |
|
|
38
|
+
| Batch & Portfolio (9) | Multi-asset analytics | `batch_sma`, `batch_ema`, `batch_rsi`, `correlation_matrix`, `portfolio_volatility`, `drawdown_series` |
|
|
39
|
+
| Aggregation (8) | Tick/volume/time bars | `aggregate_tick_bars`, `aggregate_volume_bars_ticks`, `volume_bars`, `ohlcv_agg` |
|
|
51
40
|
|
|
52
41
|
## Prerequisites
|
|
53
42
|
|
|
@@ -57,91 +46,64 @@ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
|
|
|
57
46
|
|
|
58
47
|
# Install wasm-pack
|
|
59
48
|
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
|
|
60
|
-
# OR via cargo:
|
|
61
|
-
cargo install wasm-pack
|
|
62
49
|
```
|
|
63
50
|
|
|
64
51
|
## Build
|
|
65
52
|
|
|
66
53
|
```bash
|
|
67
54
|
cd wasm/
|
|
68
|
-
wasm-pack build --target nodejs --out-dir pkg
|
|
69
|
-
```
|
|
70
55
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
- `ferro_ta_wasm_bg.wasm` — compiled WebAssembly binary
|
|
74
|
-
- `ferro_ta_wasm.d.ts` — TypeScript declarations
|
|
56
|
+
# Build both Node.js and web targets
|
|
57
|
+
npm run build
|
|
75
58
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
wasm-pack build --target web --out-dir pkg-web
|
|
59
|
+
# Or build individually:
|
|
60
|
+
npm run build:node # → node/
|
|
61
|
+
npm run build:web # → web/
|
|
80
62
|
```
|
|
81
63
|
|
|
64
|
+
This produces two directories:
|
|
65
|
+
- `node/` -- CommonJS glue for Node.js (`require()`)
|
|
66
|
+
- `web/` -- ESM glue for browsers and web workers (`import`)
|
|
67
|
+
|
|
68
|
+
Both contain `ferro_ta_wasm.js`, `ferro_ta_wasm_bg.wasm`, and `ferro_ta_wasm.d.ts`.
|
|
69
|
+
|
|
82
70
|
## Usage (Node.js)
|
|
83
71
|
|
|
84
72
|
```javascript
|
|
85
|
-
const {
|
|
73
|
+
const {
|
|
74
|
+
sma, ema, rsi, bbands, macd, atr, adx, obv, mfi,
|
|
75
|
+
cdlhammer, cdlengulfing,
|
|
76
|
+
WasmStreamingSMA,
|
|
77
|
+
} = require('ferro-ta-wasm');
|
|
86
78
|
|
|
87
79
|
const close = new Float64Array([44.34, 44.09, 44.15, 43.61, 44.33, 44.83, 45.10]);
|
|
80
|
+
const high = new Float64Array([45.0, 46.0, 47.0, 46.0, 45.0, 44.0, 45.0]);
|
|
81
|
+
const low = new Float64Array([43.0, 44.0, 45.0, 44.0, 43.0, 42.0, 43.0]);
|
|
88
82
|
|
|
89
|
-
//
|
|
90
|
-
|
|
91
|
-
console.log('
|
|
92
|
-
|
|
93
|
-
// RSI (period 5)
|
|
94
|
-
const rsiOut = rsi(close, 5);
|
|
95
|
-
console.log('RSI:', Array.from(rsiOut));
|
|
83
|
+
// Indicators
|
|
84
|
+
console.log('SMA:', Array.from(sma(close, 3)));
|
|
85
|
+
console.log('RSI:', Array.from(rsi(close, 5)));
|
|
96
86
|
|
|
97
|
-
//
|
|
98
|
-
const wmaOut = wma(close, 5);
|
|
99
|
-
console.log('WMA:', Array.from(wmaOut));
|
|
100
|
-
|
|
101
|
-
// Bollinger Bands (period 5, ±2σ) — returns [upper, middle, lower]
|
|
87
|
+
// Multi-output
|
|
102
88
|
const [upper, middle, lower] = bbands(close, 5, 2.0, 2.0);
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
//
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
console.log('
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
// ATR (period 3)
|
|
112
|
-
const high = new Float64Array([45.0, 46.0, 47.0, 46.0, 45.0, 44.0, 45.0]);
|
|
113
|
-
const low = new Float64Array([43.0, 44.0, 45.0, 44.0, 43.0, 42.0, 43.0]);
|
|
114
|
-
const atrOut = atr(high, low, close, 3);
|
|
115
|
-
console.log('ATR:', Array.from(atrOut));
|
|
116
|
-
|
|
117
|
-
// ADX (period 3)
|
|
118
|
-
const adxOut = adx(high, low, close, 3);
|
|
119
|
-
console.log('ADX:', Array.from(adxOut));
|
|
120
|
-
|
|
121
|
-
// OBV
|
|
122
|
-
const volume = new Float64Array([1000, 1200, 900, 1500, 800, 600, 700]);
|
|
123
|
-
const obvOut = obv(close, volume);
|
|
124
|
-
console.log('OBV:', Array.from(obvOut));
|
|
125
|
-
|
|
126
|
-
// MFI (period 3)
|
|
127
|
-
const mfiOut = mfi(high, low, close, volume, 3);
|
|
128
|
-
console.log('MFI:', Array.from(mfiOut));
|
|
89
|
+
const [macdLine, signal, hist] = macd(close, 3, 5, 2);
|
|
90
|
+
|
|
91
|
+
// Streaming (bar-by-bar)
|
|
92
|
+
const stream = new WasmStreamingSMA(3);
|
|
93
|
+
for (const price of close) {
|
|
94
|
+
console.log('streaming SMA:', stream.update(price));
|
|
95
|
+
}
|
|
129
96
|
```
|
|
130
97
|
|
|
131
98
|
## Usage (Browser)
|
|
132
99
|
|
|
133
100
|
```html
|
|
134
101
|
<script type="module">
|
|
135
|
-
import init, { sma, macd } from './pkg-web/ferro_ta_wasm.js';
|
|
136
|
-
await init();
|
|
102
|
+
import init, { sma, rsi, macd } from './pkg-web/ferro_ta_wasm.js';
|
|
103
|
+
await init();
|
|
137
104
|
|
|
138
105
|
const close = new Float64Array([44.34, 44.09, 44.15, 43.61, 44.33]);
|
|
139
|
-
|
|
140
|
-
console.log('SMA:', Array.from(smaOut));
|
|
141
|
-
|
|
142
|
-
// MACD
|
|
143
|
-
const [macdLine, signal, hist] = macd(close, 3, 5, 2);
|
|
144
|
-
console.log('MACD line:', Array.from(macdLine));
|
|
106
|
+
console.log('SMA:', Array.from(sma(close, 3)));
|
|
145
107
|
</script>
|
|
146
108
|
```
|
|
147
109
|
|
|
@@ -152,22 +114,12 @@ cd wasm/
|
|
|
152
114
|
wasm-pack test --node
|
|
153
115
|
```
|
|
154
116
|
|
|
155
|
-
##
|
|
156
|
-
|
|
157
|
-
Every CI run on `main` builds the WASM package and uploads it as a GitHub Actions
|
|
158
|
-
artifact named `wasm-pkg`. To download the latest pre-built package without building
|
|
159
|
-
from source:
|
|
117
|
+
## Limitations
|
|
160
118
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
4. Unzip and use `pkg/ferro_ta_wasm.js` directly in your project.
|
|
119
|
+
- Large arrays (> 10M bars) may be slow due to JS-WASM memory copies. For high-throughput use cases prefer the Python (PyO3) binding.
|
|
120
|
+
- WASM does not support multi-threading natively in browsers (SharedArrayBuffer requires COOP/COEP headers).
|
|
121
|
+
- The npm package ships both Node.js (`require`) and browser/web worker (`import`) builds. Conditional exports in `package.json` select the right one automatically.
|
|
165
122
|
|
|
166
|
-
##
|
|
123
|
+
## License
|
|
167
124
|
|
|
168
|
-
|
|
169
|
-
Additional indicators will be added following the same pattern in `src/lib.rs`.
|
|
170
|
-
- Large arrays (> 10M bars) may be slow due to JS↔WASM memory copies. For high-throughput
|
|
171
|
-
use cases prefer the Python (PyO3) binding.
|
|
172
|
-
- WASM does not support multi-threading natively in browsers (SharedArrayBuffer requires
|
|
173
|
-
COOP/COEP headers).
|
|
125
|
+
MIT
|
package/node/README.md
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# ferro-ta WASM
|
|
2
|
+
|
|
3
|
+
WebAssembly bindings for the [ferro-ta](https://github.com/pratikbhadane24/ferro-ta) technical analysis library. Full feature parity with the Python and Rust core packages.
|
|
4
|
+
|
|
5
|
+
## Install from npm
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install ferro-ta-wasm
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
```javascript
|
|
12
|
+
const ferro = require('ferro-ta-wasm');
|
|
13
|
+
|
|
14
|
+
const close = new Float64Array([44.34, 44.09, 44.15, 43.61, 44.33, 44.83, 45.10]);
|
|
15
|
+
console.log('SMA:', Array.from(ferro.sma(close, 3)));
|
|
16
|
+
console.log('RSI:', Array.from(ferro.rsi(close, 14)));
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Available Indicators (200+ exports)
|
|
20
|
+
|
|
21
|
+
| Category | Functions | Examples |
|
|
22
|
+
|----------|-----------|----------|
|
|
23
|
+
| Overlap Studies (20) | Moving averages, bands, SAR | `sma`, `ema`, `wma`, `dema`, `tema`, `trima`, `kama`, `t3`, `bbands`, `macd`, `macdfix`, `macdext`, `sar`, `sarext`, `mama`, `midpoint`, `midprice`, `ma`, `mavp`, `hull_ma` |
|
|
24
|
+
| Momentum (26) | Oscillators, directional movement | `rsi`, `mom`, `stoch`, `stochf`, `adx`, `adxr`, `dx`, `plus_di`, `minus_di`, `roc`, `willr`, `aroon`, `aroonosc`, `cci`, `bop`, `stochrsi`, `apo`, `ppo`, `cmo`, `trix_indicator`, `ultosc` |
|
|
25
|
+
| Candlestick Patterns (61) | All TA-Lib patterns | `cdlhammer`, `cdlengulfing`, `cdldoji`, `cdlmorningstar`, `cdlshootingstar`, ... (all 61) |
|
|
26
|
+
| Volatility (3) | True range, ATR | `atr`, `natr`, `trange` |
|
|
27
|
+
| Volume (6) | On-balance volume, accumulation | `obv`, `mfi`, `vwap`, `vwma`, `ad`, `adosc` |
|
|
28
|
+
| Price Transforms (4) | Synthetic prices | `avgprice`, `medprice`, `typprice`, `wclprice` |
|
|
29
|
+
| Cycle / Hilbert (6) | Hilbert Transform suite | `ht_trendline`, `ht_dcperiod`, `ht_dcphase`, `ht_phasor`, `ht_sine`, `ht_trendmode` |
|
|
30
|
+
| Statistics (10) | Regression, correlation | `stddev`, `var`, `linearreg`, `linearreg_slope`, `linearreg_intercept`, `linearreg_angle`, `tsf`, `beta_rolling`, `correl` |
|
|
31
|
+
| Math (19) | Operators and transforms | `math_add`, `math_sub`, `math_mult`, `math_div`, `transform_sin`, `transform_cos`, `transform_exp`, `transform_sqrt`, ... |
|
|
32
|
+
| Extended (10) | Supertrend, channels, Ichimoku | `supertrend`, `donchian`, `keltner_channels`, `ichimoku`, `pivot_points`, `chandelier_exit`, `choppiness_index` |
|
|
33
|
+
| Streaming API (9 classes) | Bar-by-bar stateful | `WasmStreamingSMA`, `WasmStreamingEMA`, `WasmStreamingRSI`, `WasmStreamingATR`, `WasmStreamingBBands`, `WasmStreamingMACD`, `WasmStreamingStoch`, `WasmStreamingVWAP`, `WasmStreamingSupertrend` |
|
|
34
|
+
| Options (14) | Pricing, Greeks, IV | `black_scholes_price`, `black_76_price`, `black_scholes_greeks`, `implied_volatility`, `iv_rank`, `smile_metrics`, ... |
|
|
35
|
+
| Futures (12) | Basis, roll, curve | `futures_basis`, `annualized_basis`, `roll_yield`, `weighted_continuous`, `calendar_spreads`, `curve_summary`, ... |
|
|
36
|
+
| Backtesting (9) | Signal generation, engines | `backtest_core`, `backtest_ohlcv`, `rsi_threshold_signals`, `macd_crossover_signals`, `walk_forward_indices`, `monte_carlo_bootstrap`, ... |
|
|
37
|
+
| Alerts & Regime (7) | Signals and regime detection | `check_threshold`, `check_cross`, `regime_adx`, `regime_combined`, `detect_breaks_cusum` |
|
|
38
|
+
| Batch & Portfolio (9) | Multi-asset analytics | `batch_sma`, `batch_ema`, `batch_rsi`, `correlation_matrix`, `portfolio_volatility`, `drawdown_series` |
|
|
39
|
+
| Aggregation (8) | Tick/volume/time bars | `aggregate_tick_bars`, `aggregate_volume_bars_ticks`, `volume_bars`, `ohlcv_agg` |
|
|
40
|
+
|
|
41
|
+
## Prerequisites
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
# Install Rust (if not already present)
|
|
45
|
+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
|
|
46
|
+
|
|
47
|
+
# Install wasm-pack
|
|
48
|
+
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Build
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
cd wasm/
|
|
55
|
+
|
|
56
|
+
# Build both Node.js and web targets
|
|
57
|
+
npm run build
|
|
58
|
+
|
|
59
|
+
# Or build individually:
|
|
60
|
+
npm run build:node # → node/
|
|
61
|
+
npm run build:web # → web/
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
This produces two directories:
|
|
65
|
+
- `node/` -- CommonJS glue for Node.js (`require()`)
|
|
66
|
+
- `web/` -- ESM glue for browsers and web workers (`import`)
|
|
67
|
+
|
|
68
|
+
Both contain `ferro_ta_wasm.js`, `ferro_ta_wasm_bg.wasm`, and `ferro_ta_wasm.d.ts`.
|
|
69
|
+
|
|
70
|
+
## Usage (Node.js)
|
|
71
|
+
|
|
72
|
+
```javascript
|
|
73
|
+
const {
|
|
74
|
+
sma, ema, rsi, bbands, macd, atr, adx, obv, mfi,
|
|
75
|
+
cdlhammer, cdlengulfing,
|
|
76
|
+
WasmStreamingSMA,
|
|
77
|
+
} = require('ferro-ta-wasm');
|
|
78
|
+
|
|
79
|
+
const close = new Float64Array([44.34, 44.09, 44.15, 43.61, 44.33, 44.83, 45.10]);
|
|
80
|
+
const high = new Float64Array([45.0, 46.0, 47.0, 46.0, 45.0, 44.0, 45.0]);
|
|
81
|
+
const low = new Float64Array([43.0, 44.0, 45.0, 44.0, 43.0, 42.0, 43.0]);
|
|
82
|
+
|
|
83
|
+
// Indicators
|
|
84
|
+
console.log('SMA:', Array.from(sma(close, 3)));
|
|
85
|
+
console.log('RSI:', Array.from(rsi(close, 5)));
|
|
86
|
+
|
|
87
|
+
// Multi-output
|
|
88
|
+
const [upper, middle, lower] = bbands(close, 5, 2.0, 2.0);
|
|
89
|
+
const [macdLine, signal, hist] = macd(close, 3, 5, 2);
|
|
90
|
+
|
|
91
|
+
// Streaming (bar-by-bar)
|
|
92
|
+
const stream = new WasmStreamingSMA(3);
|
|
93
|
+
for (const price of close) {
|
|
94
|
+
console.log('streaming SMA:', stream.update(price));
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Usage (Browser)
|
|
99
|
+
|
|
100
|
+
```html
|
|
101
|
+
<script type="module">
|
|
102
|
+
import init, { sma, rsi, macd } from './pkg-web/ferro_ta_wasm.js';
|
|
103
|
+
await init();
|
|
104
|
+
|
|
105
|
+
const close = new Float64Array([44.34, 44.09, 44.15, 43.61, 44.33]);
|
|
106
|
+
console.log('SMA:', Array.from(sma(close, 3)));
|
|
107
|
+
</script>
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Run Tests
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
cd wasm/
|
|
114
|
+
wasm-pack test --node
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Limitations
|
|
118
|
+
|
|
119
|
+
- Large arrays (> 10M bars) may be slow due to JS-WASM memory copies. For high-throughput use cases prefer the Python (PyO3) binding.
|
|
120
|
+
- WASM does not support multi-threading natively in browsers (SharedArrayBuffer requires COOP/COEP headers).
|
|
121
|
+
- The npm package ships both Node.js (`require`) and browser/web worker (`import`) builds. Conditional exports in `package.json` select the right one automatically.
|
|
122
|
+
|
|
123
|
+
## License
|
|
124
|
+
|
|
125
|
+
MIT
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,14 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ferro-ta-wasm",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "WebAssembly bindings for ferro-ta technical analysis indicators",
|
|
5
|
-
"main": "
|
|
6
|
-
"
|
|
7
|
-
"
|
|
5
|
+
"main": "node/ferro_ta_wasm.js",
|
|
6
|
+
"module": "web/ferro_ta_wasm.js",
|
|
7
|
+
"types": "node/ferro_ta_wasm.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"node": {
|
|
11
|
+
"types": "./node/ferro_ta_wasm.d.ts",
|
|
12
|
+
"require": "./node/ferro_ta_wasm.js"
|
|
13
|
+
},
|
|
14
|
+
"default": {
|
|
15
|
+
"types": "./web/ferro_ta_wasm.d.ts",
|
|
16
|
+
"import": "./web/ferro_ta_wasm.js"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"files": ["node", "web"],
|
|
8
21
|
"scripts": {
|
|
9
|
-
"build": "
|
|
22
|
+
"build": "npm run build:node && npm run build:web",
|
|
23
|
+
"build:node": "wasm-pack build --target nodejs --out-dir node && node -e \"require('fs').rmSync('node/.gitignore', { force: true }); require('fs').rmSync('node/package.json', { force: true });\"",
|
|
24
|
+
"build:web": "wasm-pack build --target web --out-dir web && node -e \"require('fs').rmSync('web/.gitignore', { force: true }); require('fs').rmSync('web/package.json', { force: true });\"",
|
|
10
25
|
"bench": "node bench.js",
|
|
11
|
-
"prepack": "npm run build
|
|
26
|
+
"prepack": "npm run build",
|
|
12
27
|
"test": "wasm-pack test --node"
|
|
13
28
|
},
|
|
14
29
|
"license": "MIT",
|
package/web/README.md
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# ferro-ta WASM
|
|
2
|
+
|
|
3
|
+
WebAssembly bindings for the [ferro-ta](https://github.com/pratikbhadane24/ferro-ta) technical analysis library. Full feature parity with the Python and Rust core packages.
|
|
4
|
+
|
|
5
|
+
## Install from npm
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install ferro-ta-wasm
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
```javascript
|
|
12
|
+
const ferro = require('ferro-ta-wasm');
|
|
13
|
+
|
|
14
|
+
const close = new Float64Array([44.34, 44.09, 44.15, 43.61, 44.33, 44.83, 45.10]);
|
|
15
|
+
console.log('SMA:', Array.from(ferro.sma(close, 3)));
|
|
16
|
+
console.log('RSI:', Array.from(ferro.rsi(close, 14)));
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Available Indicators (200+ exports)
|
|
20
|
+
|
|
21
|
+
| Category | Functions | Examples |
|
|
22
|
+
|----------|-----------|----------|
|
|
23
|
+
| Overlap Studies (20) | Moving averages, bands, SAR | `sma`, `ema`, `wma`, `dema`, `tema`, `trima`, `kama`, `t3`, `bbands`, `macd`, `macdfix`, `macdext`, `sar`, `sarext`, `mama`, `midpoint`, `midprice`, `ma`, `mavp`, `hull_ma` |
|
|
24
|
+
| Momentum (26) | Oscillators, directional movement | `rsi`, `mom`, `stoch`, `stochf`, `adx`, `adxr`, `dx`, `plus_di`, `minus_di`, `roc`, `willr`, `aroon`, `aroonosc`, `cci`, `bop`, `stochrsi`, `apo`, `ppo`, `cmo`, `trix_indicator`, `ultosc` |
|
|
25
|
+
| Candlestick Patterns (61) | All TA-Lib patterns | `cdlhammer`, `cdlengulfing`, `cdldoji`, `cdlmorningstar`, `cdlshootingstar`, ... (all 61) |
|
|
26
|
+
| Volatility (3) | True range, ATR | `atr`, `natr`, `trange` |
|
|
27
|
+
| Volume (6) | On-balance volume, accumulation | `obv`, `mfi`, `vwap`, `vwma`, `ad`, `adosc` |
|
|
28
|
+
| Price Transforms (4) | Synthetic prices | `avgprice`, `medprice`, `typprice`, `wclprice` |
|
|
29
|
+
| Cycle / Hilbert (6) | Hilbert Transform suite | `ht_trendline`, `ht_dcperiod`, `ht_dcphase`, `ht_phasor`, `ht_sine`, `ht_trendmode` |
|
|
30
|
+
| Statistics (10) | Regression, correlation | `stddev`, `var`, `linearreg`, `linearreg_slope`, `linearreg_intercept`, `linearreg_angle`, `tsf`, `beta_rolling`, `correl` |
|
|
31
|
+
| Math (19) | Operators and transforms | `math_add`, `math_sub`, `math_mult`, `math_div`, `transform_sin`, `transform_cos`, `transform_exp`, `transform_sqrt`, ... |
|
|
32
|
+
| Extended (10) | Supertrend, channels, Ichimoku | `supertrend`, `donchian`, `keltner_channels`, `ichimoku`, `pivot_points`, `chandelier_exit`, `choppiness_index` |
|
|
33
|
+
| Streaming API (9 classes) | Bar-by-bar stateful | `WasmStreamingSMA`, `WasmStreamingEMA`, `WasmStreamingRSI`, `WasmStreamingATR`, `WasmStreamingBBands`, `WasmStreamingMACD`, `WasmStreamingStoch`, `WasmStreamingVWAP`, `WasmStreamingSupertrend` |
|
|
34
|
+
| Options (14) | Pricing, Greeks, IV | `black_scholes_price`, `black_76_price`, `black_scholes_greeks`, `implied_volatility`, `iv_rank`, `smile_metrics`, ... |
|
|
35
|
+
| Futures (12) | Basis, roll, curve | `futures_basis`, `annualized_basis`, `roll_yield`, `weighted_continuous`, `calendar_spreads`, `curve_summary`, ... |
|
|
36
|
+
| Backtesting (9) | Signal generation, engines | `backtest_core`, `backtest_ohlcv`, `rsi_threshold_signals`, `macd_crossover_signals`, `walk_forward_indices`, `monte_carlo_bootstrap`, ... |
|
|
37
|
+
| Alerts & Regime (7) | Signals and regime detection | `check_threshold`, `check_cross`, `regime_adx`, `regime_combined`, `detect_breaks_cusum` |
|
|
38
|
+
| Batch & Portfolio (9) | Multi-asset analytics | `batch_sma`, `batch_ema`, `batch_rsi`, `correlation_matrix`, `portfolio_volatility`, `drawdown_series` |
|
|
39
|
+
| Aggregation (8) | Tick/volume/time bars | `aggregate_tick_bars`, `aggregate_volume_bars_ticks`, `volume_bars`, `ohlcv_agg` |
|
|
40
|
+
|
|
41
|
+
## Prerequisites
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
# Install Rust (if not already present)
|
|
45
|
+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
|
|
46
|
+
|
|
47
|
+
# Install wasm-pack
|
|
48
|
+
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Build
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
cd wasm/
|
|
55
|
+
|
|
56
|
+
# Build both Node.js and web targets
|
|
57
|
+
npm run build
|
|
58
|
+
|
|
59
|
+
# Or build individually:
|
|
60
|
+
npm run build:node # → node/
|
|
61
|
+
npm run build:web # → web/
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
This produces two directories:
|
|
65
|
+
- `node/` -- CommonJS glue for Node.js (`require()`)
|
|
66
|
+
- `web/` -- ESM glue for browsers and web workers (`import`)
|
|
67
|
+
|
|
68
|
+
Both contain `ferro_ta_wasm.js`, `ferro_ta_wasm_bg.wasm`, and `ferro_ta_wasm.d.ts`.
|
|
69
|
+
|
|
70
|
+
## Usage (Node.js)
|
|
71
|
+
|
|
72
|
+
```javascript
|
|
73
|
+
const {
|
|
74
|
+
sma, ema, rsi, bbands, macd, atr, adx, obv, mfi,
|
|
75
|
+
cdlhammer, cdlengulfing,
|
|
76
|
+
WasmStreamingSMA,
|
|
77
|
+
} = require('ferro-ta-wasm');
|
|
78
|
+
|
|
79
|
+
const close = new Float64Array([44.34, 44.09, 44.15, 43.61, 44.33, 44.83, 45.10]);
|
|
80
|
+
const high = new Float64Array([45.0, 46.0, 47.0, 46.0, 45.0, 44.0, 45.0]);
|
|
81
|
+
const low = new Float64Array([43.0, 44.0, 45.0, 44.0, 43.0, 42.0, 43.0]);
|
|
82
|
+
|
|
83
|
+
// Indicators
|
|
84
|
+
console.log('SMA:', Array.from(sma(close, 3)));
|
|
85
|
+
console.log('RSI:', Array.from(rsi(close, 5)));
|
|
86
|
+
|
|
87
|
+
// Multi-output
|
|
88
|
+
const [upper, middle, lower] = bbands(close, 5, 2.0, 2.0);
|
|
89
|
+
const [macdLine, signal, hist] = macd(close, 3, 5, 2);
|
|
90
|
+
|
|
91
|
+
// Streaming (bar-by-bar)
|
|
92
|
+
const stream = new WasmStreamingSMA(3);
|
|
93
|
+
for (const price of close) {
|
|
94
|
+
console.log('streaming SMA:', stream.update(price));
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Usage (Browser)
|
|
99
|
+
|
|
100
|
+
```html
|
|
101
|
+
<script type="module">
|
|
102
|
+
import init, { sma, rsi, macd } from './pkg-web/ferro_ta_wasm.js';
|
|
103
|
+
await init();
|
|
104
|
+
|
|
105
|
+
const close = new Float64Array([44.34, 44.09, 44.15, 43.61, 44.33]);
|
|
106
|
+
console.log('SMA:', Array.from(sma(close, 3)));
|
|
107
|
+
</script>
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Run Tests
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
cd wasm/
|
|
114
|
+
wasm-pack test --node
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Limitations
|
|
118
|
+
|
|
119
|
+
- Large arrays (> 10M bars) may be slow due to JS-WASM memory copies. For high-throughput use cases prefer the Python (PyO3) binding.
|
|
120
|
+
- WASM does not support multi-threading natively in browsers (SharedArrayBuffer requires COOP/COEP headers).
|
|
121
|
+
- The npm package ships both Node.js (`require`) and browser/web worker (`import`) builds. Conditional exports in `package.json` select the right one automatically.
|
|
122
|
+
|
|
123
|
+
## License
|
|
124
|
+
|
|
125
|
+
MIT
|