ferro-ta-wasm 1.0.0
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 +158 -0
- package/package.json +25 -0
- package/pkg/README.md +158 -0
- package/pkg/ferro_ta_wasm.d.ts +121 -0
- package/pkg/ferro_ta_wasm.js +274 -0
- package/pkg/ferro_ta_wasm_bg.wasm +0 -0
- package/pkg/ferro_ta_wasm_bg.wasm.d.ts +14 -0
- package/pkg/package.json +13 -0
package/README.md
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
# ferro-ta WASM
|
|
2
|
+
|
|
3
|
+
WebAssembly bindings for the [ferro-ta](https://github.com/pratikbhadane24/ferro-ta) technical analysis library.
|
|
4
|
+
|
|
5
|
+
## Install from npm
|
|
6
|
+
|
|
7
|
+
Once published, install the Node.js build from npm:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install ferro-ta-wasm
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```javascript
|
|
14
|
+
const { sma, ema, rsi, bbands, atr, obv, macd } = require('ferro-ta-wasm');
|
|
15
|
+
|
|
16
|
+
const close = new Float64Array([44.34, 44.09, 44.15, 43.61, 44.33, 44.83, 45.10]);
|
|
17
|
+
const smaOut = sma(close, 3);
|
|
18
|
+
console.log('SMA:', Array.from(smaOut));
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
> **Decision**: We chose WebAssembly (wasm-bindgen / wasm-pack) as the second binding because it runs in
|
|
22
|
+
> browsers *and* Node.js without any native addons, and shares zero unsafe FFI surface with the Python
|
|
23
|
+
> build. Node.js users get a pure-JS entry point; browser users get the same `.wasm` file.
|
|
24
|
+
|
|
25
|
+
## Available Indicators
|
|
26
|
+
|
|
27
|
+
| Category | Function | Parameters | Returns |
|
|
28
|
+
|------------|---------------|----------------------------------------------------|---------|
|
|
29
|
+
| Overlap | `sma` | `close: Float64Array, timeperiod: number` | `Float64Array` |
|
|
30
|
+
| Overlap | `ema` | `close: Float64Array, timeperiod: number` | `Float64Array` |
|
|
31
|
+
| Overlap | `bbands` | `close, timeperiod, nbdevup, nbdevdn` | `Array[upper, middle, lower]` |
|
|
32
|
+
| Momentum | `rsi` | `close: Float64Array, timeperiod: number` | `Float64Array` |
|
|
33
|
+
| Momentum | `macd` | `close, fastperiod, slowperiod, signalperiod` | `Array[macd, signal, hist]` |
|
|
34
|
+
| Momentum | `mom` | `close: Float64Array, timeperiod: number` | `Float64Array` |
|
|
35
|
+
| Momentum | `stochf` | `high, low, close, fastk_period, fastd_period` | `Array[fastk, fastd]` |
|
|
36
|
+
| Volatility | `atr` | `high, low, close: Float64Array, timeperiod` | `Float64Array` |
|
|
37
|
+
| Volume | `obv` | `close: Float64Array, volume: Float64Array` | `Float64Array` |
|
|
38
|
+
|
|
39
|
+
### Adding more indicators
|
|
40
|
+
|
|
41
|
+
All implementations are self-contained in `src/lib.rs` — no external crate dependency needed.
|
|
42
|
+
To add a new indicator:
|
|
43
|
+
|
|
44
|
+
1. Implement the algorithm in a `#[wasm_bindgen]` function in `src/lib.rs`.
|
|
45
|
+
2. Add at least two `#[wasm_bindgen_test]` tests covering output length and a known value.
|
|
46
|
+
3. Update this README table.
|
|
47
|
+
4. Run `wasm-pack test --node` to verify.
|
|
48
|
+
|
|
49
|
+
## Prerequisites
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
# Install Rust (if not already present)
|
|
53
|
+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
|
|
54
|
+
|
|
55
|
+
# Install wasm-pack
|
|
56
|
+
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
|
|
57
|
+
# OR via cargo:
|
|
58
|
+
cargo install wasm-pack
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Build
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
cd wasm/
|
|
65
|
+
wasm-pack build --target nodejs --out-dir pkg
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
This produces a `pkg/` directory containing:
|
|
69
|
+
- `ferro_ta_wasm.js` — JavaScript glue code
|
|
70
|
+
- `ferro_ta_wasm_bg.wasm` — compiled WebAssembly binary
|
|
71
|
+
- `ferro_ta_wasm.d.ts` — TypeScript declarations
|
|
72
|
+
|
|
73
|
+
For a browser build:
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
wasm-pack build --target web --out-dir pkg-web
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Usage (Node.js)
|
|
80
|
+
|
|
81
|
+
```javascript
|
|
82
|
+
const { sma, ema, rsi, bbands, atr, obv, macd } = require('./pkg/ferro_ta_wasm.js');
|
|
83
|
+
|
|
84
|
+
const close = new Float64Array([44.34, 44.09, 44.15, 43.61, 44.33, 44.83, 45.10]);
|
|
85
|
+
|
|
86
|
+
// Simple Moving Average (period 3)
|
|
87
|
+
const smaOut = sma(close, 3);
|
|
88
|
+
console.log('SMA:', Array.from(smaOut)); // [ NaN, NaN, 44.193, ... ]
|
|
89
|
+
|
|
90
|
+
// RSI (period 5)
|
|
91
|
+
const rsiOut = rsi(close, 5);
|
|
92
|
+
console.log('RSI:', Array.from(rsiOut));
|
|
93
|
+
|
|
94
|
+
// Bollinger Bands (period 5, ±2σ) — returns [upper, middle, lower]
|
|
95
|
+
const [upper, middle, lower] = bbands(close, 5, 2.0, 2.0);
|
|
96
|
+
console.log('BBANDS upper:', Array.from(upper));
|
|
97
|
+
|
|
98
|
+
// MACD (fast=3, slow=5, signal=2) — returns [macd_line, signal_line, histogram]
|
|
99
|
+
const [macdLine, signalLine, histogram] = macd(close, 3, 5, 2);
|
|
100
|
+
console.log('MACD:', Array.from(macdLine));
|
|
101
|
+
console.log('Signal:', Array.from(signalLine));
|
|
102
|
+
console.log('Histogram:', Array.from(histogram));
|
|
103
|
+
|
|
104
|
+
// ATR (period 3)
|
|
105
|
+
const high = new Float64Array([45.0, 46.0, 47.0, 46.0, 45.0, 44.0, 45.0]);
|
|
106
|
+
const low = new Float64Array([43.0, 44.0, 45.0, 44.0, 43.0, 42.0, 43.0]);
|
|
107
|
+
const atrOut = atr(high, low, close, 3);
|
|
108
|
+
console.log('ATR:', Array.from(atrOut));
|
|
109
|
+
|
|
110
|
+
// OBV
|
|
111
|
+
const volume = new Float64Array([1000, 1200, 900, 1500, 800, 600, 700]);
|
|
112
|
+
const obvOut = obv(close, volume);
|
|
113
|
+
console.log('OBV:', Array.from(obvOut));
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## Usage (Browser)
|
|
117
|
+
|
|
118
|
+
```html
|
|
119
|
+
<script type="module">
|
|
120
|
+
import init, { sma, macd } from './pkg-web/ferro_ta_wasm.js';
|
|
121
|
+
await init(); // loads the .wasm binary
|
|
122
|
+
|
|
123
|
+
const close = new Float64Array([44.34, 44.09, 44.15, 43.61, 44.33]);
|
|
124
|
+
const smaOut = sma(close, 3);
|
|
125
|
+
console.log('SMA:', Array.from(smaOut));
|
|
126
|
+
|
|
127
|
+
// MACD
|
|
128
|
+
const [macdLine, signal, hist] = macd(close, 3, 5, 2);
|
|
129
|
+
console.log('MACD line:', Array.from(macdLine));
|
|
130
|
+
</script>
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Run Tests
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
cd wasm/
|
|
137
|
+
wasm-pack test --node
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## CI Artifact
|
|
141
|
+
|
|
142
|
+
Every CI run on `main` builds the WASM package and uploads it as a GitHub Actions
|
|
143
|
+
artifact named `wasm-pkg`. To download the latest pre-built package without building
|
|
144
|
+
from source:
|
|
145
|
+
|
|
146
|
+
1. Go to the [Actions tab](https://github.com/pratikbhadane24/ferro-ta/actions).
|
|
147
|
+
2. Open the latest successful CI run.
|
|
148
|
+
3. Download the `wasm-pkg` artifact from the **Artifacts** section.
|
|
149
|
+
4. Unzip and use `pkg/ferro_ta_wasm.js` directly in your project.
|
|
150
|
+
|
|
151
|
+
## Limitations
|
|
152
|
+
|
|
153
|
+
- Only 9 indicators are currently exposed (SMA, EMA, BBANDS, RSI, MACD, MOM, STOCHF, ATR, OBV).
|
|
154
|
+
Additional indicators will be added following the same pattern in `src/lib.rs`.
|
|
155
|
+
- Large arrays (> 10M bars) may be slow due to JS↔WASM memory copies. For high-throughput
|
|
156
|
+
use cases prefer the Python (PyO3) binding.
|
|
157
|
+
- WASM does not support multi-threading natively in browsers (SharedArrayBuffer requires
|
|
158
|
+
COOP/COEP headers).
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ferro-ta-wasm",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "WebAssembly bindings for ferro-ta technical analysis indicators",
|
|
5
|
+
"main": "pkg/ferro_ta_wasm.js",
|
|
6
|
+
"types": "pkg/ferro_ta_wasm.d.ts",
|
|
7
|
+
"files": ["pkg"],
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "wasm-pack build --target nodejs --out-dir pkg",
|
|
10
|
+
"prepack": "npm run build && node -e \"require('fs').rmSync('pkg/.gitignore', { force: true })\"",
|
|
11
|
+
"test": "wasm-pack test --node"
|
|
12
|
+
},
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://github.com/pratikbhadane24/ferro-ta.git",
|
|
17
|
+
"directory": "wasm"
|
|
18
|
+
},
|
|
19
|
+
"homepage": "https://github.com/pratikbhadane24/ferro-ta#readme",
|
|
20
|
+
"bugs": "https://github.com/pratikbhadane24/ferro-ta/issues",
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {}
|
|
25
|
+
}
|
package/pkg/README.md
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
# ferro-ta WASM
|
|
2
|
+
|
|
3
|
+
WebAssembly bindings for the [ferro-ta](https://github.com/pratikbhadane24/ferro-ta) technical analysis library.
|
|
4
|
+
|
|
5
|
+
## Install from npm
|
|
6
|
+
|
|
7
|
+
Once published, install the Node.js build from npm:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install ferro-ta-wasm
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```javascript
|
|
14
|
+
const { sma, ema, rsi, bbands, atr, obv, macd } = require('ferro-ta-wasm');
|
|
15
|
+
|
|
16
|
+
const close = new Float64Array([44.34, 44.09, 44.15, 43.61, 44.33, 44.83, 45.10]);
|
|
17
|
+
const smaOut = sma(close, 3);
|
|
18
|
+
console.log('SMA:', Array.from(smaOut));
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
> **Decision**: We chose WebAssembly (wasm-bindgen / wasm-pack) as the second binding because it runs in
|
|
22
|
+
> browsers *and* Node.js without any native addons, and shares zero unsafe FFI surface with the Python
|
|
23
|
+
> build. Node.js users get a pure-JS entry point; browser users get the same `.wasm` file.
|
|
24
|
+
|
|
25
|
+
## Available Indicators
|
|
26
|
+
|
|
27
|
+
| Category | Function | Parameters | Returns |
|
|
28
|
+
|------------|---------------|----------------------------------------------------|---------|
|
|
29
|
+
| Overlap | `sma` | `close: Float64Array, timeperiod: number` | `Float64Array` |
|
|
30
|
+
| Overlap | `ema` | `close: Float64Array, timeperiod: number` | `Float64Array` |
|
|
31
|
+
| Overlap | `bbands` | `close, timeperiod, nbdevup, nbdevdn` | `Array[upper, middle, lower]` |
|
|
32
|
+
| Momentum | `rsi` | `close: Float64Array, timeperiod: number` | `Float64Array` |
|
|
33
|
+
| Momentum | `macd` | `close, fastperiod, slowperiod, signalperiod` | `Array[macd, signal, hist]` |
|
|
34
|
+
| Momentum | `mom` | `close: Float64Array, timeperiod: number` | `Float64Array` |
|
|
35
|
+
| Momentum | `stochf` | `high, low, close, fastk_period, fastd_period` | `Array[fastk, fastd]` |
|
|
36
|
+
| Volatility | `atr` | `high, low, close: Float64Array, timeperiod` | `Float64Array` |
|
|
37
|
+
| Volume | `obv` | `close: Float64Array, volume: Float64Array` | `Float64Array` |
|
|
38
|
+
|
|
39
|
+
### Adding more indicators
|
|
40
|
+
|
|
41
|
+
All implementations are self-contained in `src/lib.rs` — no external crate dependency needed.
|
|
42
|
+
To add a new indicator:
|
|
43
|
+
|
|
44
|
+
1. Implement the algorithm in a `#[wasm_bindgen]` function in `src/lib.rs`.
|
|
45
|
+
2. Add at least two `#[wasm_bindgen_test]` tests covering output length and a known value.
|
|
46
|
+
3. Update this README table.
|
|
47
|
+
4. Run `wasm-pack test --node` to verify.
|
|
48
|
+
|
|
49
|
+
## Prerequisites
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
# Install Rust (if not already present)
|
|
53
|
+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
|
|
54
|
+
|
|
55
|
+
# Install wasm-pack
|
|
56
|
+
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
|
|
57
|
+
# OR via cargo:
|
|
58
|
+
cargo install wasm-pack
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Build
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
cd wasm/
|
|
65
|
+
wasm-pack build --target nodejs --out-dir pkg
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
This produces a `pkg/` directory containing:
|
|
69
|
+
- `ferro_ta_wasm.js` — JavaScript glue code
|
|
70
|
+
- `ferro_ta_wasm_bg.wasm` — compiled WebAssembly binary
|
|
71
|
+
- `ferro_ta_wasm.d.ts` — TypeScript declarations
|
|
72
|
+
|
|
73
|
+
For a browser build:
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
wasm-pack build --target web --out-dir pkg-web
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Usage (Node.js)
|
|
80
|
+
|
|
81
|
+
```javascript
|
|
82
|
+
const { sma, ema, rsi, bbands, atr, obv, macd } = require('./pkg/ferro_ta_wasm.js');
|
|
83
|
+
|
|
84
|
+
const close = new Float64Array([44.34, 44.09, 44.15, 43.61, 44.33, 44.83, 45.10]);
|
|
85
|
+
|
|
86
|
+
// Simple Moving Average (period 3)
|
|
87
|
+
const smaOut = sma(close, 3);
|
|
88
|
+
console.log('SMA:', Array.from(smaOut)); // [ NaN, NaN, 44.193, ... ]
|
|
89
|
+
|
|
90
|
+
// RSI (period 5)
|
|
91
|
+
const rsiOut = rsi(close, 5);
|
|
92
|
+
console.log('RSI:', Array.from(rsiOut));
|
|
93
|
+
|
|
94
|
+
// Bollinger Bands (period 5, ±2σ) — returns [upper, middle, lower]
|
|
95
|
+
const [upper, middle, lower] = bbands(close, 5, 2.0, 2.0);
|
|
96
|
+
console.log('BBANDS upper:', Array.from(upper));
|
|
97
|
+
|
|
98
|
+
// MACD (fast=3, slow=5, signal=2) — returns [macd_line, signal_line, histogram]
|
|
99
|
+
const [macdLine, signalLine, histogram] = macd(close, 3, 5, 2);
|
|
100
|
+
console.log('MACD:', Array.from(macdLine));
|
|
101
|
+
console.log('Signal:', Array.from(signalLine));
|
|
102
|
+
console.log('Histogram:', Array.from(histogram));
|
|
103
|
+
|
|
104
|
+
// ATR (period 3)
|
|
105
|
+
const high = new Float64Array([45.0, 46.0, 47.0, 46.0, 45.0, 44.0, 45.0]);
|
|
106
|
+
const low = new Float64Array([43.0, 44.0, 45.0, 44.0, 43.0, 42.0, 43.0]);
|
|
107
|
+
const atrOut = atr(high, low, close, 3);
|
|
108
|
+
console.log('ATR:', Array.from(atrOut));
|
|
109
|
+
|
|
110
|
+
// OBV
|
|
111
|
+
const volume = new Float64Array([1000, 1200, 900, 1500, 800, 600, 700]);
|
|
112
|
+
const obvOut = obv(close, volume);
|
|
113
|
+
console.log('OBV:', Array.from(obvOut));
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## Usage (Browser)
|
|
117
|
+
|
|
118
|
+
```html
|
|
119
|
+
<script type="module">
|
|
120
|
+
import init, { sma, macd } from './pkg-web/ferro_ta_wasm.js';
|
|
121
|
+
await init(); // loads the .wasm binary
|
|
122
|
+
|
|
123
|
+
const close = new Float64Array([44.34, 44.09, 44.15, 43.61, 44.33]);
|
|
124
|
+
const smaOut = sma(close, 3);
|
|
125
|
+
console.log('SMA:', Array.from(smaOut));
|
|
126
|
+
|
|
127
|
+
// MACD
|
|
128
|
+
const [macdLine, signal, hist] = macd(close, 3, 5, 2);
|
|
129
|
+
console.log('MACD line:', Array.from(macdLine));
|
|
130
|
+
</script>
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Run Tests
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
cd wasm/
|
|
137
|
+
wasm-pack test --node
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## CI Artifact
|
|
141
|
+
|
|
142
|
+
Every CI run on `main` builds the WASM package and uploads it as a GitHub Actions
|
|
143
|
+
artifact named `wasm-pkg`. To download the latest pre-built package without building
|
|
144
|
+
from source:
|
|
145
|
+
|
|
146
|
+
1. Go to the [Actions tab](https://github.com/pratikbhadane24/ferro-ta/actions).
|
|
147
|
+
2. Open the latest successful CI run.
|
|
148
|
+
3. Download the `wasm-pkg` artifact from the **Artifacts** section.
|
|
149
|
+
4. Unzip and use `pkg/ferro_ta_wasm.js` directly in your project.
|
|
150
|
+
|
|
151
|
+
## Limitations
|
|
152
|
+
|
|
153
|
+
- Only 9 indicators are currently exposed (SMA, EMA, BBANDS, RSI, MACD, MOM, STOCHF, ATR, OBV).
|
|
154
|
+
Additional indicators will be added following the same pattern in `src/lib.rs`.
|
|
155
|
+
- Large arrays (> 10M bars) may be slow due to JS↔WASM memory copies. For high-throughput
|
|
156
|
+
use cases prefer the Python (PyO3) binding.
|
|
157
|
+
- WASM does not support multi-threading natively in browsers (SharedArrayBuffer requires
|
|
158
|
+
COOP/COEP headers).
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Average True Range (Wilder smoothing, TA-Lib compatible).
|
|
6
|
+
*
|
|
7
|
+
* # Arguments
|
|
8
|
+
* - `high` – `Float64Array` of high prices.
|
|
9
|
+
* - `low` – `Float64Array` of low prices.
|
|
10
|
+
* - `close` – `Float64Array` of close prices.
|
|
11
|
+
* - `timeperiod` – look-back period (default 14, minimum 1).
|
|
12
|
+
*
|
|
13
|
+
* # Returns
|
|
14
|
+
* `Float64Array`; first `timeperiod` values are `NaN`.
|
|
15
|
+
*/
|
|
16
|
+
export function atr(high: Float64Array, low: Float64Array, close: Float64Array, timeperiod: number): Float64Array;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Bollinger Bands (SMA ± k × rolling standard deviation).
|
|
20
|
+
*
|
|
21
|
+
* # Arguments
|
|
22
|
+
* - `close` – `Float64Array` of close prices.
|
|
23
|
+
* - `timeperiod` – look-back window (default 5, minimum 1).
|
|
24
|
+
* - `nbdevup` – multiplier for the upper band (default 2.0).
|
|
25
|
+
* - `nbdevdn` – multiplier for the lower band (default 2.0).
|
|
26
|
+
*
|
|
27
|
+
* # Returns
|
|
28
|
+
* A `js_sys::Array` containing three `Float64Array` elements:
|
|
29
|
+
* `[upperband, middleband, lowerband]`.
|
|
30
|
+
*/
|
|
31
|
+
export function bbands(close: Float64Array, timeperiod: number, nbdevup: number, nbdevdn: number): Array<any>;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Exponential Moving Average (SMA-seeded).
|
|
35
|
+
*
|
|
36
|
+
* # Arguments
|
|
37
|
+
* - `close` – `Float64Array` of close prices.
|
|
38
|
+
* - `timeperiod` – look-back period (default 30, minimum 1).
|
|
39
|
+
*
|
|
40
|
+
* # Returns
|
|
41
|
+
* `Float64Array` with the first `timeperiod - 1` values set to `NaN`.
|
|
42
|
+
*/
|
|
43
|
+
export function ema(close: Float64Array, timeperiod: number): Float64Array;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Moving Average Convergence/Divergence.
|
|
47
|
+
*
|
|
48
|
+
* # Arguments
|
|
49
|
+
* - `close` – `Float64Array` of close prices.
|
|
50
|
+
* - `fastperiod` – fast EMA period (default 12).
|
|
51
|
+
* - `slowperiod` – slow EMA period (default 26).
|
|
52
|
+
* - `signalperiod` – signal EMA period (default 9).
|
|
53
|
+
*
|
|
54
|
+
* # Returns
|
|
55
|
+
* A `js_sys::Array` containing three `Float64Array` elements:
|
|
56
|
+
* `[macd_line, signal_line, histogram]`.
|
|
57
|
+
*/
|
|
58
|
+
export function macd(close: Float64Array, fastperiod: number, slowperiod: number, signalperiod: number): Array<any>;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Momentum — difference between current close and close *timeperiod* bars ago.
|
|
62
|
+
*
|
|
63
|
+
* # Arguments
|
|
64
|
+
* - `close` – `Float64Array` of close prices.
|
|
65
|
+
* - `timeperiod` – look-back window (default 10, minimum 1).
|
|
66
|
+
*
|
|
67
|
+
* # Returns
|
|
68
|
+
* `Float64Array`; first `timeperiod` values are `NaN`.
|
|
69
|
+
*/
|
|
70
|
+
export function mom(close: Float64Array, timeperiod: number): Float64Array;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* On-Balance Volume.
|
|
74
|
+
*
|
|
75
|
+
* # Arguments
|
|
76
|
+
* - `close` – `Float64Array` of close prices.
|
|
77
|
+
* - `volume` – `Float64Array` of volume values.
|
|
78
|
+
*
|
|
79
|
+
* # Returns
|
|
80
|
+
* `Float64Array` — cumulative OBV.
|
|
81
|
+
*/
|
|
82
|
+
export function obv(close: Float64Array, volume: Float64Array): Float64Array;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Relative Strength Index (Wilder smoothing).
|
|
86
|
+
*
|
|
87
|
+
* # Arguments
|
|
88
|
+
* - `close` – `Float64Array` of close prices.
|
|
89
|
+
* - `timeperiod` – look-back period (default 14, minimum 1).
|
|
90
|
+
*
|
|
91
|
+
* # Returns
|
|
92
|
+
* `Float64Array` — values in `[0, 100]`; first `timeperiod` values are `NaN`.
|
|
93
|
+
*/
|
|
94
|
+
export function rsi(close: Float64Array, timeperiod: number): Float64Array;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Simple Moving Average.
|
|
98
|
+
*
|
|
99
|
+
* # Arguments
|
|
100
|
+
* - `close` – `Float64Array` of close prices.
|
|
101
|
+
* - `timeperiod` – look-back window (default 30, minimum 1).
|
|
102
|
+
*
|
|
103
|
+
* # Returns
|
|
104
|
+
* `Float64Array` with the first `timeperiod - 1` values set to `NaN`.
|
|
105
|
+
*/
|
|
106
|
+
export function sma(close: Float64Array, timeperiod: number): Float64Array;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Fast Stochastic Oscillator.
|
|
110
|
+
*
|
|
111
|
+
* # Arguments
|
|
112
|
+
* - `high` – `Float64Array` of high prices.
|
|
113
|
+
* - `low` – `Float64Array` of low prices.
|
|
114
|
+
* - `close` – `Float64Array` of close prices.
|
|
115
|
+
* - `fastk_period` – fast-%K look-back window (default 5, minimum 1).
|
|
116
|
+
* - `fastd_period` – fast-%D SMA smoothing period (default 3, minimum 1).
|
|
117
|
+
*
|
|
118
|
+
* # Returns
|
|
119
|
+
* A `js_sys::Array` containing two `Float64Array` elements: `[fastk, fastd]`.
|
|
120
|
+
*/
|
|
121
|
+
export function stochf(high: Float64Array, low: Float64Array, close: Float64Array, fastk_period: number, fastd_period: number): Array<any>;
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
/* @ts-self-types="./ferro_ta_wasm.d.ts" */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Average True Range (Wilder smoothing, TA-Lib compatible).
|
|
5
|
+
*
|
|
6
|
+
* # Arguments
|
|
7
|
+
* - `high` – `Float64Array` of high prices.
|
|
8
|
+
* - `low` – `Float64Array` of low prices.
|
|
9
|
+
* - `close` – `Float64Array` of close prices.
|
|
10
|
+
* - `timeperiod` – look-back period (default 14, minimum 1).
|
|
11
|
+
*
|
|
12
|
+
* # Returns
|
|
13
|
+
* `Float64Array`; first `timeperiod` values are `NaN`.
|
|
14
|
+
* @param {Float64Array} high
|
|
15
|
+
* @param {Float64Array} low
|
|
16
|
+
* @param {Float64Array} close
|
|
17
|
+
* @param {number} timeperiod
|
|
18
|
+
* @returns {Float64Array}
|
|
19
|
+
*/
|
|
20
|
+
function atr(high, low, close, timeperiod) {
|
|
21
|
+
const ret = wasm.atr(high, low, close, timeperiod);
|
|
22
|
+
return ret;
|
|
23
|
+
}
|
|
24
|
+
exports.atr = atr;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Bollinger Bands (SMA ± k × rolling standard deviation).
|
|
28
|
+
*
|
|
29
|
+
* # Arguments
|
|
30
|
+
* - `close` – `Float64Array` of close prices.
|
|
31
|
+
* - `timeperiod` – look-back window (default 5, minimum 1).
|
|
32
|
+
* - `nbdevup` – multiplier for the upper band (default 2.0).
|
|
33
|
+
* - `nbdevdn` – multiplier for the lower band (default 2.0).
|
|
34
|
+
*
|
|
35
|
+
* # Returns
|
|
36
|
+
* A `js_sys::Array` containing three `Float64Array` elements:
|
|
37
|
+
* `[upperband, middleband, lowerband]`.
|
|
38
|
+
* @param {Float64Array} close
|
|
39
|
+
* @param {number} timeperiod
|
|
40
|
+
* @param {number} nbdevup
|
|
41
|
+
* @param {number} nbdevdn
|
|
42
|
+
* @returns {Array<any>}
|
|
43
|
+
*/
|
|
44
|
+
function bbands(close, timeperiod, nbdevup, nbdevdn) {
|
|
45
|
+
const ret = wasm.bbands(close, timeperiod, nbdevup, nbdevdn);
|
|
46
|
+
return ret;
|
|
47
|
+
}
|
|
48
|
+
exports.bbands = bbands;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Exponential Moving Average (SMA-seeded).
|
|
52
|
+
*
|
|
53
|
+
* # Arguments
|
|
54
|
+
* - `close` – `Float64Array` of close prices.
|
|
55
|
+
* - `timeperiod` – look-back period (default 30, minimum 1).
|
|
56
|
+
*
|
|
57
|
+
* # Returns
|
|
58
|
+
* `Float64Array` with the first `timeperiod - 1` values set to `NaN`.
|
|
59
|
+
* @param {Float64Array} close
|
|
60
|
+
* @param {number} timeperiod
|
|
61
|
+
* @returns {Float64Array}
|
|
62
|
+
*/
|
|
63
|
+
function ema(close, timeperiod) {
|
|
64
|
+
const ret = wasm.ema(close, timeperiod);
|
|
65
|
+
return ret;
|
|
66
|
+
}
|
|
67
|
+
exports.ema = ema;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Moving Average Convergence/Divergence.
|
|
71
|
+
*
|
|
72
|
+
* # Arguments
|
|
73
|
+
* - `close` – `Float64Array` of close prices.
|
|
74
|
+
* - `fastperiod` – fast EMA period (default 12).
|
|
75
|
+
* - `slowperiod` – slow EMA period (default 26).
|
|
76
|
+
* - `signalperiod` – signal EMA period (default 9).
|
|
77
|
+
*
|
|
78
|
+
* # Returns
|
|
79
|
+
* A `js_sys::Array` containing three `Float64Array` elements:
|
|
80
|
+
* `[macd_line, signal_line, histogram]`.
|
|
81
|
+
* @param {Float64Array} close
|
|
82
|
+
* @param {number} fastperiod
|
|
83
|
+
* @param {number} slowperiod
|
|
84
|
+
* @param {number} signalperiod
|
|
85
|
+
* @returns {Array<any>}
|
|
86
|
+
*/
|
|
87
|
+
function macd(close, fastperiod, slowperiod, signalperiod) {
|
|
88
|
+
const ret = wasm.macd(close, fastperiod, slowperiod, signalperiod);
|
|
89
|
+
return ret;
|
|
90
|
+
}
|
|
91
|
+
exports.macd = macd;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Momentum — difference between current close and close *timeperiod* bars ago.
|
|
95
|
+
*
|
|
96
|
+
* # Arguments
|
|
97
|
+
* - `close` – `Float64Array` of close prices.
|
|
98
|
+
* - `timeperiod` – look-back window (default 10, minimum 1).
|
|
99
|
+
*
|
|
100
|
+
* # Returns
|
|
101
|
+
* `Float64Array`; first `timeperiod` values are `NaN`.
|
|
102
|
+
* @param {Float64Array} close
|
|
103
|
+
* @param {number} timeperiod
|
|
104
|
+
* @returns {Float64Array}
|
|
105
|
+
*/
|
|
106
|
+
function mom(close, timeperiod) {
|
|
107
|
+
const ret = wasm.mom(close, timeperiod);
|
|
108
|
+
return ret;
|
|
109
|
+
}
|
|
110
|
+
exports.mom = mom;
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* On-Balance Volume.
|
|
114
|
+
*
|
|
115
|
+
* # Arguments
|
|
116
|
+
* - `close` – `Float64Array` of close prices.
|
|
117
|
+
* - `volume` – `Float64Array` of volume values.
|
|
118
|
+
*
|
|
119
|
+
* # Returns
|
|
120
|
+
* `Float64Array` — cumulative OBV.
|
|
121
|
+
* @param {Float64Array} close
|
|
122
|
+
* @param {Float64Array} volume
|
|
123
|
+
* @returns {Float64Array}
|
|
124
|
+
*/
|
|
125
|
+
function obv(close, volume) {
|
|
126
|
+
const ret = wasm.obv(close, volume);
|
|
127
|
+
return ret;
|
|
128
|
+
}
|
|
129
|
+
exports.obv = obv;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Relative Strength Index (Wilder smoothing).
|
|
133
|
+
*
|
|
134
|
+
* # Arguments
|
|
135
|
+
* - `close` – `Float64Array` of close prices.
|
|
136
|
+
* - `timeperiod` – look-back period (default 14, minimum 1).
|
|
137
|
+
*
|
|
138
|
+
* # Returns
|
|
139
|
+
* `Float64Array` — values in `[0, 100]`; first `timeperiod` values are `NaN`.
|
|
140
|
+
* @param {Float64Array} close
|
|
141
|
+
* @param {number} timeperiod
|
|
142
|
+
* @returns {Float64Array}
|
|
143
|
+
*/
|
|
144
|
+
function rsi(close, timeperiod) {
|
|
145
|
+
const ret = wasm.rsi(close, timeperiod);
|
|
146
|
+
return ret;
|
|
147
|
+
}
|
|
148
|
+
exports.rsi = rsi;
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Simple Moving Average.
|
|
152
|
+
*
|
|
153
|
+
* # Arguments
|
|
154
|
+
* - `close` – `Float64Array` of close prices.
|
|
155
|
+
* - `timeperiod` – look-back window (default 30, minimum 1).
|
|
156
|
+
*
|
|
157
|
+
* # Returns
|
|
158
|
+
* `Float64Array` with the first `timeperiod - 1` values set to `NaN`.
|
|
159
|
+
* @param {Float64Array} close
|
|
160
|
+
* @param {number} timeperiod
|
|
161
|
+
* @returns {Float64Array}
|
|
162
|
+
*/
|
|
163
|
+
function sma(close, timeperiod) {
|
|
164
|
+
const ret = wasm.sma(close, timeperiod);
|
|
165
|
+
return ret;
|
|
166
|
+
}
|
|
167
|
+
exports.sma = sma;
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Fast Stochastic Oscillator.
|
|
171
|
+
*
|
|
172
|
+
* # Arguments
|
|
173
|
+
* - `high` – `Float64Array` of high prices.
|
|
174
|
+
* - `low` – `Float64Array` of low prices.
|
|
175
|
+
* - `close` – `Float64Array` of close prices.
|
|
176
|
+
* - `fastk_period` – fast-%K look-back window (default 5, minimum 1).
|
|
177
|
+
* - `fastd_period` – fast-%D SMA smoothing period (default 3, minimum 1).
|
|
178
|
+
*
|
|
179
|
+
* # Returns
|
|
180
|
+
* A `js_sys::Array` containing two `Float64Array` elements: `[fastk, fastd]`.
|
|
181
|
+
* @param {Float64Array} high
|
|
182
|
+
* @param {Float64Array} low
|
|
183
|
+
* @param {Float64Array} close
|
|
184
|
+
* @param {number} fastk_period
|
|
185
|
+
* @param {number} fastd_period
|
|
186
|
+
* @returns {Array<any>}
|
|
187
|
+
*/
|
|
188
|
+
function stochf(high, low, close, fastk_period, fastd_period) {
|
|
189
|
+
const ret = wasm.stochf(high, low, close, fastk_period, fastd_period);
|
|
190
|
+
return ret;
|
|
191
|
+
}
|
|
192
|
+
exports.stochf = stochf;
|
|
193
|
+
|
|
194
|
+
function __wbg_get_imports() {
|
|
195
|
+
const import0 = {
|
|
196
|
+
__proto__: null,
|
|
197
|
+
__wbg___wbindgen_throw_6ddd609b62940d55: function(arg0, arg1) {
|
|
198
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
199
|
+
},
|
|
200
|
+
__wbg_length_550d8a396009cd38: function(arg0) {
|
|
201
|
+
const ret = arg0.length;
|
|
202
|
+
return ret;
|
|
203
|
+
},
|
|
204
|
+
__wbg_new_a70fbab9066b301f: function() {
|
|
205
|
+
const ret = new Array();
|
|
206
|
+
return ret;
|
|
207
|
+
},
|
|
208
|
+
__wbg_new_with_length_eae667475c36c4e4: function(arg0) {
|
|
209
|
+
const ret = new Float64Array(arg0 >>> 0);
|
|
210
|
+
return ret;
|
|
211
|
+
},
|
|
212
|
+
__wbg_prototypesetcall_79daf97fb14c7a19: function(arg0, arg1, arg2) {
|
|
213
|
+
Float64Array.prototype.set.call(getArrayF64FromWasm0(arg0, arg1), arg2);
|
|
214
|
+
},
|
|
215
|
+
__wbg_push_e87b0e732085a946: function(arg0, arg1) {
|
|
216
|
+
const ret = arg0.push(arg1);
|
|
217
|
+
return ret;
|
|
218
|
+
},
|
|
219
|
+
__wbg_set_636d1e3e4286e068: function(arg0, arg1, arg2) {
|
|
220
|
+
arg0.set(getArrayF64FromWasm0(arg1, arg2));
|
|
221
|
+
},
|
|
222
|
+
__wbindgen_init_externref_table: function() {
|
|
223
|
+
const table = wasm.__wbindgen_externrefs;
|
|
224
|
+
const offset = table.grow(4);
|
|
225
|
+
table.set(0, undefined);
|
|
226
|
+
table.set(offset + 0, undefined);
|
|
227
|
+
table.set(offset + 1, null);
|
|
228
|
+
table.set(offset + 2, true);
|
|
229
|
+
table.set(offset + 3, false);
|
|
230
|
+
},
|
|
231
|
+
};
|
|
232
|
+
return {
|
|
233
|
+
__proto__: null,
|
|
234
|
+
"./ferro_ta_wasm_bg.js": import0,
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function getArrayF64FromWasm0(ptr, len) {
|
|
239
|
+
ptr = ptr >>> 0;
|
|
240
|
+
return getFloat64ArrayMemory0().subarray(ptr / 8, ptr / 8 + len);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
let cachedFloat64ArrayMemory0 = null;
|
|
244
|
+
function getFloat64ArrayMemory0() {
|
|
245
|
+
if (cachedFloat64ArrayMemory0 === null || cachedFloat64ArrayMemory0.byteLength === 0) {
|
|
246
|
+
cachedFloat64ArrayMemory0 = new Float64Array(wasm.memory.buffer);
|
|
247
|
+
}
|
|
248
|
+
return cachedFloat64ArrayMemory0;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function getStringFromWasm0(ptr, len) {
|
|
252
|
+
ptr = ptr >>> 0;
|
|
253
|
+
return decodeText(ptr, len);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
let cachedUint8ArrayMemory0 = null;
|
|
257
|
+
function getUint8ArrayMemory0() {
|
|
258
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
259
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
260
|
+
}
|
|
261
|
+
return cachedUint8ArrayMemory0;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
265
|
+
cachedTextDecoder.decode();
|
|
266
|
+
function decodeText(ptr, len) {
|
|
267
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
const wasmPath = `${__dirname}/ferro_ta_wasm_bg.wasm`;
|
|
271
|
+
const wasmBytes = require('fs').readFileSync(wasmPath);
|
|
272
|
+
const wasmModule = new WebAssembly.Module(wasmBytes);
|
|
273
|
+
let wasm = new WebAssembly.Instance(wasmModule, __wbg_get_imports()).exports;
|
|
274
|
+
wasm.__wbindgen_start();
|
|
Binary file
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
export const memory: WebAssembly.Memory;
|
|
4
|
+
export const atr: (a: any, b: any, c: any, d: number) => any;
|
|
5
|
+
export const bbands: (a: any, b: number, c: number, d: number) => any;
|
|
6
|
+
export const ema: (a: any, b: number) => any;
|
|
7
|
+
export const macd: (a: any, b: number, c: number, d: number) => any;
|
|
8
|
+
export const mom: (a: any, b: number) => any;
|
|
9
|
+
export const obv: (a: any, b: any) => any;
|
|
10
|
+
export const rsi: (a: any, b: number) => any;
|
|
11
|
+
export const sma: (a: any, b: number) => any;
|
|
12
|
+
export const stochf: (a: any, b: any, c: any, d: number, e: number) => any;
|
|
13
|
+
export const __wbindgen_externrefs: WebAssembly.Table;
|
|
14
|
+
export const __wbindgen_start: () => void;
|
package/pkg/package.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ferro_ta_wasm",
|
|
3
|
+
"description": "WebAssembly bindings for ferro-ta technical analysis indicators",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"files": [
|
|
7
|
+
"ferro_ta_wasm_bg.wasm",
|
|
8
|
+
"ferro_ta_wasm.js",
|
|
9
|
+
"ferro_ta_wasm.d.ts"
|
|
10
|
+
],
|
|
11
|
+
"main": "ferro_ta_wasm.js",
|
|
12
|
+
"types": "ferro_ta_wasm.d.ts"
|
|
13
|
+
}
|