trading-signals 6.6.1 → 6.8.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 +2 -1
- package/dist/index.cjs +69 -5
- package/dist/index.d.cts +52 -47
- package/dist/index.d.ts +52 -47
- package/dist/index.js +65 -3
- package/package.json +6 -5
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ The "trading-signals" library provides a TypeScript implementation for common te
|
|
|
10
10
|
|
|
11
11
|
The main focus of this library is on the accuracy of calculations, but using the provided [faster implementations][2] you can also use it where performance is important.
|
|
12
12
|
|
|
13
|
-
All indicators can be updated over time by streaming data (prices or candles) to the `
|
|
13
|
+
All indicators can be updated over time by streaming data (prices or [candles](https://en.wikipedia.org/wiki/Candlestick_chart)) to the `add` method. Some indicators also provide `static` batch methods for further performance improvements when providing data up-front during a backtest or historical data import. You can try it out streaming input data by running the provided [demo script](./src/start/demo.ts) with `npm start`, which uses a keyboard input stream.
|
|
14
14
|
|
|
15
15
|
## Installation
|
|
16
16
|
|
|
@@ -147,6 +147,7 @@ Most of the time, the minimum amount of data depends on the interval / time peri
|
|
|
147
147
|
1. [Stochastic RSI](./src/STOCH/StochasticRSI.ts) (STOCHRSI)
|
|
148
148
|
1. [Tom Demark's Sequential Indicator](./src/TDS/TDS.ts) (TDS)
|
|
149
149
|
1. [True Range](./src/TR/TR.ts) (TR)
|
|
150
|
+
1. [Volume-Weighted Average Price](./src/VWAP/VWAP.ts) (VWAP)
|
|
150
151
|
1. [Weighted Moving Average](./src/WMA/WMA.ts) (WMA)
|
|
151
152
|
1. [Wilder's Smoothed Moving Average](./src/WSMA/WSMA.ts) (WSMA / WWS / SMMA / MEMA)
|
|
152
153
|
|
package/dist/index.cjs
CHANGED
|
@@ -36,7 +36,7 @@ __export(index_exports, {
|
|
|
36
36
|
ATR: () => ATR,
|
|
37
37
|
AccelerationBands: () => AccelerationBands,
|
|
38
38
|
BaseIndicatorSeries: () => BaseIndicatorSeries,
|
|
39
|
-
Big: () =>
|
|
39
|
+
Big: () => import_big30.default,
|
|
40
40
|
BigIndicatorSeries: () => BigIndicatorSeries,
|
|
41
41
|
BollingerBands: () => BollingerBands,
|
|
42
42
|
BollingerBandsWidth: () => BollingerBandsWidth,
|
|
@@ -76,6 +76,7 @@ __export(index_exports, {
|
|
|
76
76
|
FasterStochasticRSI: () => FasterStochasticRSI,
|
|
77
77
|
FasterTDS: () => FasterTDS,
|
|
78
78
|
FasterTR: () => FasterTR,
|
|
79
|
+
FasterVWAP: () => FasterVWAP,
|
|
79
80
|
FasterWMA: () => FasterWMA,
|
|
80
81
|
FasterWSMA: () => FasterWSMA,
|
|
81
82
|
IQR: () => IQR,
|
|
@@ -98,6 +99,7 @@ __export(index_exports, {
|
|
|
98
99
|
TDS: () => TDS,
|
|
99
100
|
TR: () => TR,
|
|
100
101
|
TechnicalIndicator: () => TechnicalIndicator,
|
|
102
|
+
VWAP: () => VWAP,
|
|
101
103
|
WMA: () => WMA,
|
|
102
104
|
WSMA: () => WSMA,
|
|
103
105
|
getAverage: () => getAverage,
|
|
@@ -114,7 +116,7 @@ __export(index_exports, {
|
|
|
114
116
|
pushUpdate: () => pushUpdate
|
|
115
117
|
});
|
|
116
118
|
module.exports = __toCommonJS(index_exports);
|
|
117
|
-
var
|
|
119
|
+
var import_big30 = __toESM(require("big.js"), 1);
|
|
118
120
|
|
|
119
121
|
// src/error/NotEnoughDataError.ts
|
|
120
122
|
var NotEnoughDataError = class extends Error {
|
|
@@ -2348,8 +2350,68 @@ var FasterTDS = class extends NumberIndicatorSeries {
|
|
|
2348
2350
|
}
|
|
2349
2351
|
};
|
|
2350
2352
|
|
|
2351
|
-
// src/
|
|
2353
|
+
// src/VWAP/VWAP.ts
|
|
2352
2354
|
var import_big28 = __toESM(require("big.js"), 1);
|
|
2355
|
+
var VWAP = class extends BigIndicatorSeries {
|
|
2356
|
+
cumulativeTypicalPriceVolume = new import_big28.default(0);
|
|
2357
|
+
cumulativeVolume = new import_big28.default(0);
|
|
2358
|
+
lastCandle = null;
|
|
2359
|
+
constructor() {
|
|
2360
|
+
super();
|
|
2361
|
+
}
|
|
2362
|
+
calculateTypicalPriceVolume(data) {
|
|
2363
|
+
const high = new import_big28.default(data.high);
|
|
2364
|
+
const hlc3 = high.plus(data.low).plus(data.close).div(3);
|
|
2365
|
+
return hlc3.mul(data.volume);
|
|
2366
|
+
}
|
|
2367
|
+
update(candle, replace) {
|
|
2368
|
+
if (candle.volume === 0) {
|
|
2369
|
+
return null;
|
|
2370
|
+
}
|
|
2371
|
+
if (replace && this.lastCandle !== null) {
|
|
2372
|
+
const lastTypicalPriceVolume = this.calculateTypicalPriceVolume(this.lastCandle);
|
|
2373
|
+
this.cumulativeTypicalPriceVolume = this.cumulativeTypicalPriceVolume.minus(lastTypicalPriceVolume);
|
|
2374
|
+
this.cumulativeVolume = this.cumulativeVolume.minus(this.lastCandle.volume);
|
|
2375
|
+
}
|
|
2376
|
+
this.lastCandle = candle;
|
|
2377
|
+
const typicalPriceVolume = this.calculateTypicalPriceVolume(candle);
|
|
2378
|
+
this.cumulativeTypicalPriceVolume = this.cumulativeTypicalPriceVolume.plus(typicalPriceVolume);
|
|
2379
|
+
this.cumulativeVolume = this.cumulativeVolume.plus(candle.volume);
|
|
2380
|
+
const vwap = this.cumulativeTypicalPriceVolume.div(this.cumulativeVolume);
|
|
2381
|
+
return this.setResult(vwap, replace);
|
|
2382
|
+
}
|
|
2383
|
+
};
|
|
2384
|
+
var FasterVWAP = class extends NumberIndicatorSeries {
|
|
2385
|
+
cumulativeTypicalPriceVolume = 0;
|
|
2386
|
+
cumulativeVolume = 0;
|
|
2387
|
+
lastCandle = null;
|
|
2388
|
+
constructor() {
|
|
2389
|
+
super();
|
|
2390
|
+
}
|
|
2391
|
+
calculateTypicalPriceVolume(data) {
|
|
2392
|
+
const hlc3 = (data.high + data.low + data.close) / 3;
|
|
2393
|
+
return hlc3 * data.volume;
|
|
2394
|
+
}
|
|
2395
|
+
update(candle, replace) {
|
|
2396
|
+
if (candle.volume === 0) {
|
|
2397
|
+
return null;
|
|
2398
|
+
}
|
|
2399
|
+
if (replace && this.lastCandle !== null) {
|
|
2400
|
+
const lastTypicalPriceVolume = this.calculateTypicalPriceVolume(this.lastCandle);
|
|
2401
|
+
this.cumulativeTypicalPriceVolume = this.cumulativeTypicalPriceVolume - lastTypicalPriceVolume;
|
|
2402
|
+
this.cumulativeVolume = this.cumulativeVolume - this.lastCandle.volume;
|
|
2403
|
+
}
|
|
2404
|
+
this.lastCandle = candle;
|
|
2405
|
+
const typicalPriceVolume = this.calculateTypicalPriceVolume(candle);
|
|
2406
|
+
this.cumulativeTypicalPriceVolume = this.cumulativeTypicalPriceVolume + typicalPriceVolume;
|
|
2407
|
+
this.cumulativeVolume = this.cumulativeVolume + candle.volume;
|
|
2408
|
+
const vwap = this.cumulativeTypicalPriceVolume / this.cumulativeVolume;
|
|
2409
|
+
return this.setResult(vwap, replace);
|
|
2410
|
+
}
|
|
2411
|
+
};
|
|
2412
|
+
|
|
2413
|
+
// src/WMA/WMA.ts
|
|
2414
|
+
var import_big29 = __toESM(require("big.js"), 1);
|
|
2353
2415
|
var WMA = class extends MovingAverage {
|
|
2354
2416
|
constructor(interval) {
|
|
2355
2417
|
super(interval);
|
|
@@ -2360,9 +2422,9 @@ var WMA = class extends MovingAverage {
|
|
|
2360
2422
|
pushUpdate(this.prices, replace, price, this.interval);
|
|
2361
2423
|
if (this.prices.length === this.interval) {
|
|
2362
2424
|
const weightedPricesSum = this.prices.reduce((acc, price2, index) => {
|
|
2363
|
-
const weightedPrice = new
|
|
2425
|
+
const weightedPrice = new import_big29.default(price2).mul(index + 1);
|
|
2364
2426
|
return acc.add(weightedPrice);
|
|
2365
|
-
}, new
|
|
2427
|
+
}, new import_big29.default(0));
|
|
2366
2428
|
const weightBase = this.interval * (this.interval + 1) / 2;
|
|
2367
2429
|
const weightedMa = weightedPricesSum.div(weightBase);
|
|
2368
2430
|
return this.setResult(weightedMa, replace);
|
|
@@ -2438,6 +2500,7 @@ var FasterWMA = class extends FasterMovingAverage {
|
|
|
2438
2500
|
FasterStochasticRSI,
|
|
2439
2501
|
FasterTDS,
|
|
2440
2502
|
FasterTR,
|
|
2503
|
+
FasterVWAP,
|
|
2441
2504
|
FasterWMA,
|
|
2442
2505
|
FasterWSMA,
|
|
2443
2506
|
IQR,
|
|
@@ -2460,6 +2523,7 @@ var FasterWMA = class extends FasterMovingAverage {
|
|
|
2460
2523
|
TDS,
|
|
2461
2524
|
TR,
|
|
2462
2525
|
TechnicalIndicator,
|
|
2526
|
+
VWAP,
|
|
2463
2527
|
WMA,
|
|
2464
2528
|
WSMA,
|
|
2465
2529
|
getAverage,
|
package/dist/index.d.cts
CHANGED
|
@@ -157,32 +157,20 @@ type Streak = {
|
|
|
157
157
|
};
|
|
158
158
|
declare function getStreaks(prices: number[], keepSide: 'up' | 'down'): Streak[];
|
|
159
159
|
|
|
160
|
-
type HighLow = {
|
|
161
|
-
high:
|
|
162
|
-
low:
|
|
160
|
+
type HighLow<T = BigSource> = {
|
|
161
|
+
high: T;
|
|
162
|
+
low: T;
|
|
163
163
|
};
|
|
164
|
-
type HighLowClose = HighLow & {
|
|
165
|
-
close:
|
|
164
|
+
type HighLowClose<T = BigSource> = HighLow<T> & {
|
|
165
|
+
close: T;
|
|
166
166
|
};
|
|
167
|
-
type OpenHighLowClose = HighLowClose & {
|
|
168
|
-
open:
|
|
167
|
+
type OpenHighLowClose<T = BigSource> = HighLowClose<T> & {
|
|
168
|
+
open: T;
|
|
169
169
|
};
|
|
170
|
-
type OpenHighLowCloseVolume = OpenHighLowClose & {
|
|
171
|
-
volume:
|
|
172
|
-
};
|
|
173
|
-
type HighLowNumber = {
|
|
174
|
-
high: number;
|
|
175
|
-
low: number;
|
|
176
|
-
};
|
|
177
|
-
type HighLowCloseNumber = HighLowNumber & {
|
|
178
|
-
close: number;
|
|
179
|
-
};
|
|
180
|
-
type OpenHighLowCloseNumber = HighLowCloseNumber & {
|
|
181
|
-
open: number;
|
|
182
|
-
};
|
|
183
|
-
type OpenHighLowCloseVolumeNumber = OpenHighLowCloseNumber & {
|
|
184
|
-
volume: number;
|
|
170
|
+
type OpenHighLowCloseVolume<T = BigSource> = OpenHighLowClose<T> & {
|
|
171
|
+
volume: T;
|
|
185
172
|
};
|
|
173
|
+
type HighLowCloseVolume<T = BigSource> = Omit<OpenHighLowCloseVolume<T>, 'open'>;
|
|
186
174
|
|
|
187
175
|
interface PeriodResult {
|
|
188
176
|
highest: Big__default;
|
|
@@ -235,14 +223,14 @@ declare class AccelerationBands extends TechnicalIndicator<BandsResult, HighLowC
|
|
|
235
223
|
upper: Big__default.Big;
|
|
236
224
|
} | null;
|
|
237
225
|
}
|
|
238
|
-
declare class FasterAccelerationBands extends TechnicalIndicator<FasterBandsResult,
|
|
226
|
+
declare class FasterAccelerationBands extends TechnicalIndicator<FasterBandsResult, HighLowClose<number>> {
|
|
239
227
|
readonly interval: number;
|
|
240
228
|
readonly width: number;
|
|
241
229
|
private readonly lowerBand;
|
|
242
230
|
private readonly middleBand;
|
|
243
231
|
private readonly upperBand;
|
|
244
232
|
constructor(interval: number, width: number, SmoothingIndicator?: FasterMovingAverageTypes);
|
|
245
|
-
update({ high, low, close }:
|
|
233
|
+
update({ high, low, close }: HighLowClose<number>, replace: boolean): {
|
|
246
234
|
lower: number;
|
|
247
235
|
middle: number;
|
|
248
236
|
upper: number;
|
|
@@ -258,13 +246,13 @@ declare class AO extends BigIndicatorSeries<HighLow> {
|
|
|
258
246
|
constructor(shortInterval: number, longInterval: number, SmoothingIndicator?: MovingAverageTypes);
|
|
259
247
|
update({ low, high }: HighLow, replace: boolean): Big__default.Big | null;
|
|
260
248
|
}
|
|
261
|
-
declare class FasterAO extends NumberIndicatorSeries<
|
|
249
|
+
declare class FasterAO extends NumberIndicatorSeries<HighLow<number>> {
|
|
262
250
|
readonly shortInterval: number;
|
|
263
251
|
readonly longInterval: number;
|
|
264
252
|
readonly long: FasterMovingAverage;
|
|
265
253
|
readonly short: FasterMovingAverage;
|
|
266
254
|
constructor(shortInterval: number, longInterval: number, SmoothingIndicator?: FasterMovingAverageTypes);
|
|
267
|
-
update({ low, high }:
|
|
255
|
+
update({ low, high }: HighLow<number>, replace: boolean): number | null;
|
|
268
256
|
}
|
|
269
257
|
|
|
270
258
|
declare class MOM extends BigIndicatorSeries {
|
|
@@ -292,7 +280,7 @@ declare class AC extends BigIndicatorSeries<HighLow> {
|
|
|
292
280
|
constructor(shortAO: number, longAO: number, signalInterval: number);
|
|
293
281
|
update(input: HighLow, replace: boolean): Big$1.Big | null;
|
|
294
282
|
}
|
|
295
|
-
declare class FasterAC extends NumberIndicatorSeries<
|
|
283
|
+
declare class FasterAC extends NumberIndicatorSeries<HighLow<number>> {
|
|
296
284
|
readonly shortAO: number;
|
|
297
285
|
readonly longAO: number;
|
|
298
286
|
readonly signalInterval: number;
|
|
@@ -300,7 +288,7 @@ declare class FasterAC extends NumberIndicatorSeries<HighLowNumber> {
|
|
|
300
288
|
readonly momentum: FasterMOM;
|
|
301
289
|
readonly signal: FasterSMA;
|
|
302
290
|
constructor(shortAO: number, longAO: number, signalInterval: number);
|
|
303
|
-
update(input:
|
|
291
|
+
update(input: HighLow<number>, replace: boolean): number | null;
|
|
304
292
|
}
|
|
305
293
|
|
|
306
294
|
declare class ADX extends BigIndicatorSeries<HighLowClose> {
|
|
@@ -312,14 +300,14 @@ declare class ADX extends BigIndicatorSeries<HighLowClose> {
|
|
|
312
300
|
get pdi(): Big$1.Big | undefined;
|
|
313
301
|
update(candle: HighLowClose, replace: boolean): Big$1.Big | null;
|
|
314
302
|
}
|
|
315
|
-
declare class FasterADX extends NumberIndicatorSeries<
|
|
303
|
+
declare class FasterADX extends NumberIndicatorSeries<HighLowClose<number>> {
|
|
316
304
|
readonly interval: number;
|
|
317
305
|
private readonly dx;
|
|
318
306
|
private readonly smoothed;
|
|
319
307
|
constructor(interval: number, SmoothingIndicator?: FasterMovingAverageTypes);
|
|
320
308
|
get mdi(): number | void;
|
|
321
309
|
get pdi(): number | void;
|
|
322
|
-
update(candle:
|
|
310
|
+
update(candle: HighLowClose<number>, replace: boolean): number | null;
|
|
323
311
|
}
|
|
324
312
|
|
|
325
313
|
declare class ATR extends BigIndicatorSeries<HighLowClose> {
|
|
@@ -329,12 +317,12 @@ declare class ATR extends BigIndicatorSeries<HighLowClose> {
|
|
|
329
317
|
constructor(interval: number, SmoothingIndicator?: MovingAverageTypes);
|
|
330
318
|
update(candle: HighLowClose, replace: boolean): Big$1.Big | null;
|
|
331
319
|
}
|
|
332
|
-
declare class FasterATR extends NumberIndicatorSeries<
|
|
320
|
+
declare class FasterATR extends NumberIndicatorSeries<HighLowClose<number>> {
|
|
333
321
|
readonly interval: number;
|
|
334
322
|
private readonly tr;
|
|
335
323
|
private readonly smoothing;
|
|
336
324
|
constructor(interval: number, SmoothingIndicator?: FasterMovingAverageTypes);
|
|
337
|
-
update(candle:
|
|
325
|
+
update(candle: HighLowClose<number>, replace: boolean): number | null;
|
|
338
326
|
}
|
|
339
327
|
|
|
340
328
|
declare class BollingerBands extends TechnicalIndicator<BandsResult, BigSource> {
|
|
@@ -379,12 +367,12 @@ declare class CCI extends BigIndicatorSeries<HighLowClose> {
|
|
|
379
367
|
update(candle: HighLowClose, replace: boolean): Big__default.Big | null;
|
|
380
368
|
private cacheTypicalPrice;
|
|
381
369
|
}
|
|
382
|
-
declare class FasterCCI extends NumberIndicatorSeries<
|
|
370
|
+
declare class FasterCCI extends NumberIndicatorSeries<HighLowClose<number>> {
|
|
383
371
|
readonly interval: number;
|
|
384
372
|
private readonly sma;
|
|
385
373
|
private readonly typicalPrices;
|
|
386
374
|
constructor(interval: number);
|
|
387
|
-
update(candle:
|
|
375
|
+
update(candle: HighLowClose<number>, replace: boolean): number | null;
|
|
388
376
|
private cacheTypicalPrice;
|
|
389
377
|
}
|
|
390
378
|
|
|
@@ -466,7 +454,7 @@ declare class DX extends BigIndicatorSeries<HighLowClose> {
|
|
|
466
454
|
private updateState;
|
|
467
455
|
update(candle: HighLowClose, replace: boolean): Big__default.Big | null;
|
|
468
456
|
}
|
|
469
|
-
declare class FasterDX extends NumberIndicatorSeries<
|
|
457
|
+
declare class FasterDX extends NumberIndicatorSeries<HighLowClose<number>> {
|
|
470
458
|
readonly interval: number;
|
|
471
459
|
private readonly movesUp;
|
|
472
460
|
private readonly movesDown;
|
|
@@ -477,7 +465,7 @@ declare class FasterDX extends NumberIndicatorSeries<HighLowCloseNumber> {
|
|
|
477
465
|
pdi?: number;
|
|
478
466
|
constructor(interval: number, SmoothingIndicator?: FasterMovingAverageTypes);
|
|
479
467
|
private updateState;
|
|
480
|
-
update(candle:
|
|
468
|
+
update(candle: HighLowClose<number>, replace: boolean): number | null;
|
|
481
469
|
}
|
|
482
470
|
|
|
483
471
|
declare class NotEnoughDataError extends Error {
|
|
@@ -589,9 +577,9 @@ declare class OBV extends BigIndicatorSeries<OpenHighLowCloseVolume> {
|
|
|
589
577
|
readonly candles: OpenHighLowCloseVolume[];
|
|
590
578
|
update(candle: OpenHighLowCloseVolume, replace: boolean): Big__default.Big | null;
|
|
591
579
|
}
|
|
592
|
-
declare class FasterOBV extends NumberIndicatorSeries<
|
|
593
|
-
readonly candles:
|
|
594
|
-
update(candle:
|
|
580
|
+
declare class FasterOBV extends NumberIndicatorSeries<OpenHighLowCloseVolume<number>> {
|
|
581
|
+
readonly candles: OpenHighLowCloseVolume<number>[];
|
|
582
|
+
update(candle: OpenHighLowCloseVolume<number>, replace: boolean): number | null;
|
|
595
583
|
}
|
|
596
584
|
|
|
597
585
|
type PSARConfig = {
|
|
@@ -612,7 +600,7 @@ declare class PSAR extends BigIndicatorSeries<HighLow> {
|
|
|
612
600
|
update(candle: HighLow, replace: boolean): Big__default | null;
|
|
613
601
|
getResultOrThrow(): Big__default;
|
|
614
602
|
}
|
|
615
|
-
declare class FasterPSAR extends NumberIndicatorSeries<
|
|
603
|
+
declare class FasterPSAR extends NumberIndicatorSeries<HighLow<number>> {
|
|
616
604
|
private readonly accelerationStep;
|
|
617
605
|
private readonly accelerationMax;
|
|
618
606
|
private acceleration;
|
|
@@ -623,7 +611,7 @@ declare class FasterPSAR extends NumberIndicatorSeries<HighLowNumber> {
|
|
|
623
611
|
private prePreviousCandle;
|
|
624
612
|
constructor(config: PSARConfig);
|
|
625
613
|
get isStable(): boolean;
|
|
626
|
-
update(candle:
|
|
614
|
+
update(candle: HighLow<number>, replace: boolean): number | null;
|
|
627
615
|
getResultOrThrow(): number;
|
|
628
616
|
}
|
|
629
617
|
|
|
@@ -680,15 +668,15 @@ declare class StochasticOscillator extends TechnicalIndicator<StochasticResult,
|
|
|
680
668
|
stochK: Big__default.Big;
|
|
681
669
|
} | null;
|
|
682
670
|
}
|
|
683
|
-
declare class FasterStochasticOscillator extends TechnicalIndicator<FasterStochasticResult,
|
|
671
|
+
declare class FasterStochasticOscillator extends TechnicalIndicator<FasterStochasticResult, HighLowClose<number>> {
|
|
684
672
|
n: number;
|
|
685
673
|
m: number;
|
|
686
674
|
p: number;
|
|
687
|
-
readonly candles:
|
|
675
|
+
readonly candles: HighLowClose<number>[];
|
|
688
676
|
private readonly periodM;
|
|
689
677
|
private readonly periodP;
|
|
690
678
|
constructor(n: number, m: number, p: number);
|
|
691
|
-
update(candle:
|
|
679
|
+
update(candle: HighLowClose<number>, replace: boolean): {
|
|
692
680
|
stochD: number;
|
|
693
681
|
stochK: number;
|
|
694
682
|
} | null;
|
|
@@ -741,10 +729,27 @@ declare class TR extends BigIndicatorSeries<HighLowClose> {
|
|
|
741
729
|
private secondLastCandle?;
|
|
742
730
|
update(candle: HighLowClose, replace: boolean): Big__default;
|
|
743
731
|
}
|
|
744
|
-
declare class FasterTR extends NumberIndicatorSeries<
|
|
732
|
+
declare class FasterTR extends NumberIndicatorSeries<HighLowClose<number>> {
|
|
745
733
|
private previousCandle?;
|
|
746
734
|
private twoPreviousCandle?;
|
|
747
|
-
update(candle:
|
|
735
|
+
update(candle: HighLowClose<number>, replace: boolean): number;
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
declare class VWAP extends BigIndicatorSeries<HighLowCloseVolume> {
|
|
739
|
+
private cumulativeTypicalPriceVolume;
|
|
740
|
+
private cumulativeVolume;
|
|
741
|
+
private lastCandle;
|
|
742
|
+
constructor();
|
|
743
|
+
private calculateTypicalPriceVolume;
|
|
744
|
+
update(candle: HighLowCloseVolume, replace: boolean): Big__default.Big | null;
|
|
745
|
+
}
|
|
746
|
+
declare class FasterVWAP extends NumberIndicatorSeries<HighLowCloseVolume<number>> {
|
|
747
|
+
private cumulativeTypicalPriceVolume;
|
|
748
|
+
private cumulativeVolume;
|
|
749
|
+
private lastCandle;
|
|
750
|
+
constructor();
|
|
751
|
+
private calculateTypicalPriceVolume;
|
|
752
|
+
update(candle: HighLowCloseVolume<number>, replace: boolean): number | null;
|
|
748
753
|
}
|
|
749
754
|
|
|
750
|
-
export { AC, ADX, AO, ATR, AccelerationBands, type BandsResult, BaseIndicatorSeries, BigIndicatorSeries, BollingerBands, BollingerBandsWidth, CCI, CG, DEMA, DMA, type DMAResult, DX, EMA, FasterAC, FasterADX, FasterAO, FasterATR, FasterAccelerationBands, type FasterBandsResult, FasterBollingerBands, FasterBollingerBandsWidth, FasterCCI, FasterCG, FasterDEMA, FasterDMA, type FasterDMAResult, FasterDX, FasterEMA, FasterIQR, FasterLinearRegression, type FasterLinearRegressionResult, FasterMACD, type FasterMACDResult, FasterMAD, FasterMOM, FasterMovingAverage, type FasterMovingAverageTypes, FasterOBV, FasterPSAR, FasterPeriod, type FasterPeriodResult, FasterRMA, FasterROC, FasterRSI, FasterSMA, FasterStochasticOscillator, FasterStochasticRSI, type FasterStochasticResult, FasterTDS, FasterTR, FasterWMA, FasterWSMA, type HighLow, type HighLowClose, type
|
|
755
|
+
export { AC, ADX, AO, ATR, AccelerationBands, type BandsResult, BaseIndicatorSeries, BigIndicatorSeries, BollingerBands, BollingerBandsWidth, CCI, CG, DEMA, DMA, type DMAResult, DX, EMA, FasterAC, FasterADX, FasterAO, FasterATR, FasterAccelerationBands, type FasterBandsResult, FasterBollingerBands, FasterBollingerBandsWidth, FasterCCI, FasterCG, FasterDEMA, FasterDMA, type FasterDMAResult, FasterDX, FasterEMA, FasterIQR, FasterLinearRegression, type FasterLinearRegressionResult, FasterMACD, type FasterMACDResult, FasterMAD, FasterMOM, FasterMovingAverage, type FasterMovingAverageTypes, FasterOBV, FasterPSAR, FasterPeriod, type FasterPeriodResult, FasterRMA, FasterROC, FasterRSI, FasterSMA, FasterStochasticOscillator, FasterStochasticRSI, type FasterStochasticResult, FasterTDS, FasterTR, FasterVWAP, FasterWMA, FasterWSMA, type HighLow, type HighLowClose, type HighLowCloseVolume, IQR, LinearRegression, type LinearRegressionConfig, type LinearRegressionResult, MACD, type MACDConfig, type MACDResult, MAD, MOM, MovingAverage, type MovingAverageTypes, NotEnoughDataError, NumberIndicatorSeries, OBV, type OpenHighLowClose, type OpenHighLowCloseVolume, PSAR, type PSARConfig, Period, type PeriodResult, RMA, ROC, RSI, SMA, StochasticOscillator, StochasticRSI, type StochasticResult, type Streak, TDS, TR, TechnicalIndicator, VWAP, WMA, WSMA, getAverage, getFasterAverage, getFasterMedian, getFasterQuartile, getFasterStandardDeviation, getMaximum, getMedian, getMinimum, getQuartile, getStandardDeviation, getStreaks, pushUpdate };
|
package/dist/index.d.ts
CHANGED
|
@@ -157,32 +157,20 @@ type Streak = {
|
|
|
157
157
|
};
|
|
158
158
|
declare function getStreaks(prices: number[], keepSide: 'up' | 'down'): Streak[];
|
|
159
159
|
|
|
160
|
-
type HighLow = {
|
|
161
|
-
high:
|
|
162
|
-
low:
|
|
160
|
+
type HighLow<T = BigSource> = {
|
|
161
|
+
high: T;
|
|
162
|
+
low: T;
|
|
163
163
|
};
|
|
164
|
-
type HighLowClose = HighLow & {
|
|
165
|
-
close:
|
|
164
|
+
type HighLowClose<T = BigSource> = HighLow<T> & {
|
|
165
|
+
close: T;
|
|
166
166
|
};
|
|
167
|
-
type OpenHighLowClose = HighLowClose & {
|
|
168
|
-
open:
|
|
167
|
+
type OpenHighLowClose<T = BigSource> = HighLowClose<T> & {
|
|
168
|
+
open: T;
|
|
169
169
|
};
|
|
170
|
-
type OpenHighLowCloseVolume = OpenHighLowClose & {
|
|
171
|
-
volume:
|
|
172
|
-
};
|
|
173
|
-
type HighLowNumber = {
|
|
174
|
-
high: number;
|
|
175
|
-
low: number;
|
|
176
|
-
};
|
|
177
|
-
type HighLowCloseNumber = HighLowNumber & {
|
|
178
|
-
close: number;
|
|
179
|
-
};
|
|
180
|
-
type OpenHighLowCloseNumber = HighLowCloseNumber & {
|
|
181
|
-
open: number;
|
|
182
|
-
};
|
|
183
|
-
type OpenHighLowCloseVolumeNumber = OpenHighLowCloseNumber & {
|
|
184
|
-
volume: number;
|
|
170
|
+
type OpenHighLowCloseVolume<T = BigSource> = OpenHighLowClose<T> & {
|
|
171
|
+
volume: T;
|
|
185
172
|
};
|
|
173
|
+
type HighLowCloseVolume<T = BigSource> = Omit<OpenHighLowCloseVolume<T>, 'open'>;
|
|
186
174
|
|
|
187
175
|
interface PeriodResult {
|
|
188
176
|
highest: Big__default;
|
|
@@ -235,14 +223,14 @@ declare class AccelerationBands extends TechnicalIndicator<BandsResult, HighLowC
|
|
|
235
223
|
upper: Big__default.Big;
|
|
236
224
|
} | null;
|
|
237
225
|
}
|
|
238
|
-
declare class FasterAccelerationBands extends TechnicalIndicator<FasterBandsResult,
|
|
226
|
+
declare class FasterAccelerationBands extends TechnicalIndicator<FasterBandsResult, HighLowClose<number>> {
|
|
239
227
|
readonly interval: number;
|
|
240
228
|
readonly width: number;
|
|
241
229
|
private readonly lowerBand;
|
|
242
230
|
private readonly middleBand;
|
|
243
231
|
private readonly upperBand;
|
|
244
232
|
constructor(interval: number, width: number, SmoothingIndicator?: FasterMovingAverageTypes);
|
|
245
|
-
update({ high, low, close }:
|
|
233
|
+
update({ high, low, close }: HighLowClose<number>, replace: boolean): {
|
|
246
234
|
lower: number;
|
|
247
235
|
middle: number;
|
|
248
236
|
upper: number;
|
|
@@ -258,13 +246,13 @@ declare class AO extends BigIndicatorSeries<HighLow> {
|
|
|
258
246
|
constructor(shortInterval: number, longInterval: number, SmoothingIndicator?: MovingAverageTypes);
|
|
259
247
|
update({ low, high }: HighLow, replace: boolean): Big__default.Big | null;
|
|
260
248
|
}
|
|
261
|
-
declare class FasterAO extends NumberIndicatorSeries<
|
|
249
|
+
declare class FasterAO extends NumberIndicatorSeries<HighLow<number>> {
|
|
262
250
|
readonly shortInterval: number;
|
|
263
251
|
readonly longInterval: number;
|
|
264
252
|
readonly long: FasterMovingAverage;
|
|
265
253
|
readonly short: FasterMovingAverage;
|
|
266
254
|
constructor(shortInterval: number, longInterval: number, SmoothingIndicator?: FasterMovingAverageTypes);
|
|
267
|
-
update({ low, high }:
|
|
255
|
+
update({ low, high }: HighLow<number>, replace: boolean): number | null;
|
|
268
256
|
}
|
|
269
257
|
|
|
270
258
|
declare class MOM extends BigIndicatorSeries {
|
|
@@ -292,7 +280,7 @@ declare class AC extends BigIndicatorSeries<HighLow> {
|
|
|
292
280
|
constructor(shortAO: number, longAO: number, signalInterval: number);
|
|
293
281
|
update(input: HighLow, replace: boolean): Big$1.Big | null;
|
|
294
282
|
}
|
|
295
|
-
declare class FasterAC extends NumberIndicatorSeries<
|
|
283
|
+
declare class FasterAC extends NumberIndicatorSeries<HighLow<number>> {
|
|
296
284
|
readonly shortAO: number;
|
|
297
285
|
readonly longAO: number;
|
|
298
286
|
readonly signalInterval: number;
|
|
@@ -300,7 +288,7 @@ declare class FasterAC extends NumberIndicatorSeries<HighLowNumber> {
|
|
|
300
288
|
readonly momentum: FasterMOM;
|
|
301
289
|
readonly signal: FasterSMA;
|
|
302
290
|
constructor(shortAO: number, longAO: number, signalInterval: number);
|
|
303
|
-
update(input:
|
|
291
|
+
update(input: HighLow<number>, replace: boolean): number | null;
|
|
304
292
|
}
|
|
305
293
|
|
|
306
294
|
declare class ADX extends BigIndicatorSeries<HighLowClose> {
|
|
@@ -312,14 +300,14 @@ declare class ADX extends BigIndicatorSeries<HighLowClose> {
|
|
|
312
300
|
get pdi(): Big$1.Big | undefined;
|
|
313
301
|
update(candle: HighLowClose, replace: boolean): Big$1.Big | null;
|
|
314
302
|
}
|
|
315
|
-
declare class FasterADX extends NumberIndicatorSeries<
|
|
303
|
+
declare class FasterADX extends NumberIndicatorSeries<HighLowClose<number>> {
|
|
316
304
|
readonly interval: number;
|
|
317
305
|
private readonly dx;
|
|
318
306
|
private readonly smoothed;
|
|
319
307
|
constructor(interval: number, SmoothingIndicator?: FasterMovingAverageTypes);
|
|
320
308
|
get mdi(): number | void;
|
|
321
309
|
get pdi(): number | void;
|
|
322
|
-
update(candle:
|
|
310
|
+
update(candle: HighLowClose<number>, replace: boolean): number | null;
|
|
323
311
|
}
|
|
324
312
|
|
|
325
313
|
declare class ATR extends BigIndicatorSeries<HighLowClose> {
|
|
@@ -329,12 +317,12 @@ declare class ATR extends BigIndicatorSeries<HighLowClose> {
|
|
|
329
317
|
constructor(interval: number, SmoothingIndicator?: MovingAverageTypes);
|
|
330
318
|
update(candle: HighLowClose, replace: boolean): Big$1.Big | null;
|
|
331
319
|
}
|
|
332
|
-
declare class FasterATR extends NumberIndicatorSeries<
|
|
320
|
+
declare class FasterATR extends NumberIndicatorSeries<HighLowClose<number>> {
|
|
333
321
|
readonly interval: number;
|
|
334
322
|
private readonly tr;
|
|
335
323
|
private readonly smoothing;
|
|
336
324
|
constructor(interval: number, SmoothingIndicator?: FasterMovingAverageTypes);
|
|
337
|
-
update(candle:
|
|
325
|
+
update(candle: HighLowClose<number>, replace: boolean): number | null;
|
|
338
326
|
}
|
|
339
327
|
|
|
340
328
|
declare class BollingerBands extends TechnicalIndicator<BandsResult, BigSource> {
|
|
@@ -379,12 +367,12 @@ declare class CCI extends BigIndicatorSeries<HighLowClose> {
|
|
|
379
367
|
update(candle: HighLowClose, replace: boolean): Big__default.Big | null;
|
|
380
368
|
private cacheTypicalPrice;
|
|
381
369
|
}
|
|
382
|
-
declare class FasterCCI extends NumberIndicatorSeries<
|
|
370
|
+
declare class FasterCCI extends NumberIndicatorSeries<HighLowClose<number>> {
|
|
383
371
|
readonly interval: number;
|
|
384
372
|
private readonly sma;
|
|
385
373
|
private readonly typicalPrices;
|
|
386
374
|
constructor(interval: number);
|
|
387
|
-
update(candle:
|
|
375
|
+
update(candle: HighLowClose<number>, replace: boolean): number | null;
|
|
388
376
|
private cacheTypicalPrice;
|
|
389
377
|
}
|
|
390
378
|
|
|
@@ -466,7 +454,7 @@ declare class DX extends BigIndicatorSeries<HighLowClose> {
|
|
|
466
454
|
private updateState;
|
|
467
455
|
update(candle: HighLowClose, replace: boolean): Big__default.Big | null;
|
|
468
456
|
}
|
|
469
|
-
declare class FasterDX extends NumberIndicatorSeries<
|
|
457
|
+
declare class FasterDX extends NumberIndicatorSeries<HighLowClose<number>> {
|
|
470
458
|
readonly interval: number;
|
|
471
459
|
private readonly movesUp;
|
|
472
460
|
private readonly movesDown;
|
|
@@ -477,7 +465,7 @@ declare class FasterDX extends NumberIndicatorSeries<HighLowCloseNumber> {
|
|
|
477
465
|
pdi?: number;
|
|
478
466
|
constructor(interval: number, SmoothingIndicator?: FasterMovingAverageTypes);
|
|
479
467
|
private updateState;
|
|
480
|
-
update(candle:
|
|
468
|
+
update(candle: HighLowClose<number>, replace: boolean): number | null;
|
|
481
469
|
}
|
|
482
470
|
|
|
483
471
|
declare class NotEnoughDataError extends Error {
|
|
@@ -589,9 +577,9 @@ declare class OBV extends BigIndicatorSeries<OpenHighLowCloseVolume> {
|
|
|
589
577
|
readonly candles: OpenHighLowCloseVolume[];
|
|
590
578
|
update(candle: OpenHighLowCloseVolume, replace: boolean): Big__default.Big | null;
|
|
591
579
|
}
|
|
592
|
-
declare class FasterOBV extends NumberIndicatorSeries<
|
|
593
|
-
readonly candles:
|
|
594
|
-
update(candle:
|
|
580
|
+
declare class FasterOBV extends NumberIndicatorSeries<OpenHighLowCloseVolume<number>> {
|
|
581
|
+
readonly candles: OpenHighLowCloseVolume<number>[];
|
|
582
|
+
update(candle: OpenHighLowCloseVolume<number>, replace: boolean): number | null;
|
|
595
583
|
}
|
|
596
584
|
|
|
597
585
|
type PSARConfig = {
|
|
@@ -612,7 +600,7 @@ declare class PSAR extends BigIndicatorSeries<HighLow> {
|
|
|
612
600
|
update(candle: HighLow, replace: boolean): Big__default | null;
|
|
613
601
|
getResultOrThrow(): Big__default;
|
|
614
602
|
}
|
|
615
|
-
declare class FasterPSAR extends NumberIndicatorSeries<
|
|
603
|
+
declare class FasterPSAR extends NumberIndicatorSeries<HighLow<number>> {
|
|
616
604
|
private readonly accelerationStep;
|
|
617
605
|
private readonly accelerationMax;
|
|
618
606
|
private acceleration;
|
|
@@ -623,7 +611,7 @@ declare class FasterPSAR extends NumberIndicatorSeries<HighLowNumber> {
|
|
|
623
611
|
private prePreviousCandle;
|
|
624
612
|
constructor(config: PSARConfig);
|
|
625
613
|
get isStable(): boolean;
|
|
626
|
-
update(candle:
|
|
614
|
+
update(candle: HighLow<number>, replace: boolean): number | null;
|
|
627
615
|
getResultOrThrow(): number;
|
|
628
616
|
}
|
|
629
617
|
|
|
@@ -680,15 +668,15 @@ declare class StochasticOscillator extends TechnicalIndicator<StochasticResult,
|
|
|
680
668
|
stochK: Big__default.Big;
|
|
681
669
|
} | null;
|
|
682
670
|
}
|
|
683
|
-
declare class FasterStochasticOscillator extends TechnicalIndicator<FasterStochasticResult,
|
|
671
|
+
declare class FasterStochasticOscillator extends TechnicalIndicator<FasterStochasticResult, HighLowClose<number>> {
|
|
684
672
|
n: number;
|
|
685
673
|
m: number;
|
|
686
674
|
p: number;
|
|
687
|
-
readonly candles:
|
|
675
|
+
readonly candles: HighLowClose<number>[];
|
|
688
676
|
private readonly periodM;
|
|
689
677
|
private readonly periodP;
|
|
690
678
|
constructor(n: number, m: number, p: number);
|
|
691
|
-
update(candle:
|
|
679
|
+
update(candle: HighLowClose<number>, replace: boolean): {
|
|
692
680
|
stochD: number;
|
|
693
681
|
stochK: number;
|
|
694
682
|
} | null;
|
|
@@ -741,10 +729,27 @@ declare class TR extends BigIndicatorSeries<HighLowClose> {
|
|
|
741
729
|
private secondLastCandle?;
|
|
742
730
|
update(candle: HighLowClose, replace: boolean): Big__default;
|
|
743
731
|
}
|
|
744
|
-
declare class FasterTR extends NumberIndicatorSeries<
|
|
732
|
+
declare class FasterTR extends NumberIndicatorSeries<HighLowClose<number>> {
|
|
745
733
|
private previousCandle?;
|
|
746
734
|
private twoPreviousCandle?;
|
|
747
|
-
update(candle:
|
|
735
|
+
update(candle: HighLowClose<number>, replace: boolean): number;
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
declare class VWAP extends BigIndicatorSeries<HighLowCloseVolume> {
|
|
739
|
+
private cumulativeTypicalPriceVolume;
|
|
740
|
+
private cumulativeVolume;
|
|
741
|
+
private lastCandle;
|
|
742
|
+
constructor();
|
|
743
|
+
private calculateTypicalPriceVolume;
|
|
744
|
+
update(candle: HighLowCloseVolume, replace: boolean): Big__default.Big | null;
|
|
745
|
+
}
|
|
746
|
+
declare class FasterVWAP extends NumberIndicatorSeries<HighLowCloseVolume<number>> {
|
|
747
|
+
private cumulativeTypicalPriceVolume;
|
|
748
|
+
private cumulativeVolume;
|
|
749
|
+
private lastCandle;
|
|
750
|
+
constructor();
|
|
751
|
+
private calculateTypicalPriceVolume;
|
|
752
|
+
update(candle: HighLowCloseVolume<number>, replace: boolean): number | null;
|
|
748
753
|
}
|
|
749
754
|
|
|
750
|
-
export { AC, ADX, AO, ATR, AccelerationBands, type BandsResult, BaseIndicatorSeries, BigIndicatorSeries, BollingerBands, BollingerBandsWidth, CCI, CG, DEMA, DMA, type DMAResult, DX, EMA, FasterAC, FasterADX, FasterAO, FasterATR, FasterAccelerationBands, type FasterBandsResult, FasterBollingerBands, FasterBollingerBandsWidth, FasterCCI, FasterCG, FasterDEMA, FasterDMA, type FasterDMAResult, FasterDX, FasterEMA, FasterIQR, FasterLinearRegression, type FasterLinearRegressionResult, FasterMACD, type FasterMACDResult, FasterMAD, FasterMOM, FasterMovingAverage, type FasterMovingAverageTypes, FasterOBV, FasterPSAR, FasterPeriod, type FasterPeriodResult, FasterRMA, FasterROC, FasterRSI, FasterSMA, FasterStochasticOscillator, FasterStochasticRSI, type FasterStochasticResult, FasterTDS, FasterTR, FasterWMA, FasterWSMA, type HighLow, type HighLowClose, type
|
|
755
|
+
export { AC, ADX, AO, ATR, AccelerationBands, type BandsResult, BaseIndicatorSeries, BigIndicatorSeries, BollingerBands, BollingerBandsWidth, CCI, CG, DEMA, DMA, type DMAResult, DX, EMA, FasterAC, FasterADX, FasterAO, FasterATR, FasterAccelerationBands, type FasterBandsResult, FasterBollingerBands, FasterBollingerBandsWidth, FasterCCI, FasterCG, FasterDEMA, FasterDMA, type FasterDMAResult, FasterDX, FasterEMA, FasterIQR, FasterLinearRegression, type FasterLinearRegressionResult, FasterMACD, type FasterMACDResult, FasterMAD, FasterMOM, FasterMovingAverage, type FasterMovingAverageTypes, FasterOBV, FasterPSAR, FasterPeriod, type FasterPeriodResult, FasterRMA, FasterROC, FasterRSI, FasterSMA, FasterStochasticOscillator, FasterStochasticRSI, type FasterStochasticResult, FasterTDS, FasterTR, FasterVWAP, FasterWMA, FasterWSMA, type HighLow, type HighLowClose, type HighLowCloseVolume, IQR, LinearRegression, type LinearRegressionConfig, type LinearRegressionResult, MACD, type MACDConfig, type MACDResult, MAD, MOM, MovingAverage, type MovingAverageTypes, NotEnoughDataError, NumberIndicatorSeries, OBV, type OpenHighLowClose, type OpenHighLowCloseVolume, PSAR, type PSARConfig, Period, type PeriodResult, RMA, ROC, RSI, SMA, StochasticOscillator, StochasticRSI, type StochasticResult, type Streak, TDS, TR, TechnicalIndicator, VWAP, WMA, WSMA, getAverage, getFasterAverage, getFasterMedian, getFasterQuartile, getFasterStandardDeviation, getMaximum, getMedian, getMinimum, getQuartile, getStandardDeviation, getStreaks, pushUpdate };
|
package/dist/index.js
CHANGED
|
@@ -2233,8 +2233,68 @@ var FasterTDS = class extends NumberIndicatorSeries {
|
|
|
2233
2233
|
}
|
|
2234
2234
|
};
|
|
2235
2235
|
|
|
2236
|
-
// src/
|
|
2236
|
+
// src/VWAP/VWAP.ts
|
|
2237
2237
|
import Big28 from "big.js";
|
|
2238
|
+
var VWAP = class extends BigIndicatorSeries {
|
|
2239
|
+
cumulativeTypicalPriceVolume = new Big28(0);
|
|
2240
|
+
cumulativeVolume = new Big28(0);
|
|
2241
|
+
lastCandle = null;
|
|
2242
|
+
constructor() {
|
|
2243
|
+
super();
|
|
2244
|
+
}
|
|
2245
|
+
calculateTypicalPriceVolume(data) {
|
|
2246
|
+
const high = new Big28(data.high);
|
|
2247
|
+
const hlc3 = high.plus(data.low).plus(data.close).div(3);
|
|
2248
|
+
return hlc3.mul(data.volume);
|
|
2249
|
+
}
|
|
2250
|
+
update(candle, replace) {
|
|
2251
|
+
if (candle.volume === 0) {
|
|
2252
|
+
return null;
|
|
2253
|
+
}
|
|
2254
|
+
if (replace && this.lastCandle !== null) {
|
|
2255
|
+
const lastTypicalPriceVolume = this.calculateTypicalPriceVolume(this.lastCandle);
|
|
2256
|
+
this.cumulativeTypicalPriceVolume = this.cumulativeTypicalPriceVolume.minus(lastTypicalPriceVolume);
|
|
2257
|
+
this.cumulativeVolume = this.cumulativeVolume.minus(this.lastCandle.volume);
|
|
2258
|
+
}
|
|
2259
|
+
this.lastCandle = candle;
|
|
2260
|
+
const typicalPriceVolume = this.calculateTypicalPriceVolume(candle);
|
|
2261
|
+
this.cumulativeTypicalPriceVolume = this.cumulativeTypicalPriceVolume.plus(typicalPriceVolume);
|
|
2262
|
+
this.cumulativeVolume = this.cumulativeVolume.plus(candle.volume);
|
|
2263
|
+
const vwap = this.cumulativeTypicalPriceVolume.div(this.cumulativeVolume);
|
|
2264
|
+
return this.setResult(vwap, replace);
|
|
2265
|
+
}
|
|
2266
|
+
};
|
|
2267
|
+
var FasterVWAP = class extends NumberIndicatorSeries {
|
|
2268
|
+
cumulativeTypicalPriceVolume = 0;
|
|
2269
|
+
cumulativeVolume = 0;
|
|
2270
|
+
lastCandle = null;
|
|
2271
|
+
constructor() {
|
|
2272
|
+
super();
|
|
2273
|
+
}
|
|
2274
|
+
calculateTypicalPriceVolume(data) {
|
|
2275
|
+
const hlc3 = (data.high + data.low + data.close) / 3;
|
|
2276
|
+
return hlc3 * data.volume;
|
|
2277
|
+
}
|
|
2278
|
+
update(candle, replace) {
|
|
2279
|
+
if (candle.volume === 0) {
|
|
2280
|
+
return null;
|
|
2281
|
+
}
|
|
2282
|
+
if (replace && this.lastCandle !== null) {
|
|
2283
|
+
const lastTypicalPriceVolume = this.calculateTypicalPriceVolume(this.lastCandle);
|
|
2284
|
+
this.cumulativeTypicalPriceVolume = this.cumulativeTypicalPriceVolume - lastTypicalPriceVolume;
|
|
2285
|
+
this.cumulativeVolume = this.cumulativeVolume - this.lastCandle.volume;
|
|
2286
|
+
}
|
|
2287
|
+
this.lastCandle = candle;
|
|
2288
|
+
const typicalPriceVolume = this.calculateTypicalPriceVolume(candle);
|
|
2289
|
+
this.cumulativeTypicalPriceVolume = this.cumulativeTypicalPriceVolume + typicalPriceVolume;
|
|
2290
|
+
this.cumulativeVolume = this.cumulativeVolume + candle.volume;
|
|
2291
|
+
const vwap = this.cumulativeTypicalPriceVolume / this.cumulativeVolume;
|
|
2292
|
+
return this.setResult(vwap, replace);
|
|
2293
|
+
}
|
|
2294
|
+
};
|
|
2295
|
+
|
|
2296
|
+
// src/WMA/WMA.ts
|
|
2297
|
+
import Big29 from "big.js";
|
|
2238
2298
|
var WMA = class extends MovingAverage {
|
|
2239
2299
|
constructor(interval) {
|
|
2240
2300
|
super(interval);
|
|
@@ -2245,9 +2305,9 @@ var WMA = class extends MovingAverage {
|
|
|
2245
2305
|
pushUpdate(this.prices, replace, price, this.interval);
|
|
2246
2306
|
if (this.prices.length === this.interval) {
|
|
2247
2307
|
const weightedPricesSum = this.prices.reduce((acc, price2, index) => {
|
|
2248
|
-
const weightedPrice = new
|
|
2308
|
+
const weightedPrice = new Big29(price2).mul(index + 1);
|
|
2249
2309
|
return acc.add(weightedPrice);
|
|
2250
|
-
}, new
|
|
2310
|
+
}, new Big29(0));
|
|
2251
2311
|
const weightBase = this.interval * (this.interval + 1) / 2;
|
|
2252
2312
|
const weightedMa = weightedPricesSum.div(weightBase);
|
|
2253
2313
|
return this.setResult(weightedMa, replace);
|
|
@@ -2322,6 +2382,7 @@ export {
|
|
|
2322
2382
|
FasterStochasticRSI,
|
|
2323
2383
|
FasterTDS,
|
|
2324
2384
|
FasterTR,
|
|
2385
|
+
FasterVWAP,
|
|
2325
2386
|
FasterWMA,
|
|
2326
2387
|
FasterWSMA,
|
|
2327
2388
|
IQR,
|
|
@@ -2344,6 +2405,7 @@ export {
|
|
|
2344
2405
|
TDS,
|
|
2345
2406
|
TR,
|
|
2346
2407
|
TechnicalIndicator,
|
|
2408
|
+
VWAP,
|
|
2347
2409
|
WMA,
|
|
2348
2410
|
WSMA,
|
|
2349
2411
|
getAverage,
|
package/package.json
CHANGED
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
"prettier": "^3.5.3",
|
|
23
23
|
"pretty-quick": "^4.1.1",
|
|
24
24
|
"rimraf": "^6.0.1",
|
|
25
|
-
"ts-node": "^10.9.2",
|
|
26
25
|
"tsup": "^8.4.0",
|
|
26
|
+
"tsx": "^4.19.4",
|
|
27
27
|
"typedoc": "^0.28.4",
|
|
28
28
|
"typedoc-plugin-markdown": "^4.6.3",
|
|
29
29
|
"typescript": "^5.8.3",
|
|
@@ -96,13 +96,14 @@
|
|
|
96
96
|
"release:major": "generate-changelog -M -x \"chore,test\" && npm run changelog:commit && npm run docs:release && npm version major",
|
|
97
97
|
"release:minor": "generate-changelog -m -x \"chore,test\" && npm run changelog:commit && npm run docs:release && npm version minor",
|
|
98
98
|
"release:patch": "generate-changelog -p -x \"chore,test\" && npm run changelog:commit && npm run docs:release && npm version patch",
|
|
99
|
-
"start
|
|
99
|
+
"start": "tsx ./src/start/demo.ts",
|
|
100
|
+
"start:benchmark": "tsc --noEmit && tsx ./src/start/startBenchmark.ts",
|
|
100
101
|
"test": "npm run test:types && npm run test:imports && npm run test:units -- --coverage",
|
|
101
|
-
"test:units": "vitest run --passWithNoTests",
|
|
102
102
|
"test:exports": "attw --pack .",
|
|
103
103
|
"test:imports": "depcruise src --include-only \"^src\"",
|
|
104
|
-
"test:types": "npm run lint:types"
|
|
104
|
+
"test:types": "npm run lint:types",
|
|
105
|
+
"test:units": "vitest run --passWithNoTests"
|
|
105
106
|
},
|
|
106
107
|
"type": "module",
|
|
107
|
-
"version": "6.
|
|
108
|
+
"version": "6.8.0"
|
|
108
109
|
}
|