Skip to content

Commit

Permalink
fixing compile issues
Browse files Browse the repository at this point in the history
  • Loading branch information
bennycode committed Jan 2, 2025
1 parent 0862e77 commit a747ac8
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 21 deletions.
9 changes: 5 additions & 4 deletions src/ABANDS/AccelerationBands.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import {Big} from '../index.js';
import {Big, TechnicalIndicator} from '../index.js';
import {FasterSMA, SMA} from '../SMA/SMA.js';
import {NotEnoughDataError} from '../error/index.js';
import type {BandsResult, FasterBandsResult} from '../util/BandsResult.js';
import type {Indicator} from '../Indicator.js';
import type {FasterMovingAverageTypes, MovingAverageTypes} from '../MA/MovingAverageTypes.js';
import type {FasterMovingAverage, MovingAverage} from '../MA/MovingAverage.js';
import type {HighLowClose, HighLowCloseNumber} from '../util/index.js';

export class AccelerationBands implements Indicator<BandsResult, HighLowClose> {
export class AccelerationBands extends TechnicalIndicator<BandsResult, HighLowClose> {
private readonly lowerBand: MovingAverage;
private readonly middleBand: MovingAverage;
private readonly upperBand: MovingAverage;
Expand Down Expand Up @@ -37,6 +36,7 @@ export class AccelerationBands implements Indicator<BandsResult, HighLowClose> {
public readonly width: number,
SmoothingIndicator: MovingAverageTypes = SMA
) {
super();
this.lowerBand = new SmoothingIndicator(interval);
this.middleBand = new SmoothingIndicator(interval);
this.upperBand = new SmoothingIndicator(interval);
Expand Down Expand Up @@ -75,7 +75,7 @@ export class AccelerationBands implements Indicator<BandsResult, HighLowClose> {
}
}

export class FasterAccelerationBands implements Indicator<FasterBandsResult, HighLowCloseNumber> {
export class FasterAccelerationBands extends TechnicalIndicator<FasterBandsResult, HighLowCloseNumber> {
private readonly lowerBand: FasterMovingAverage;
private readonly middleBand: FasterMovingAverage;
private readonly upperBand: FasterMovingAverage;
Expand All @@ -85,6 +85,7 @@ export class FasterAccelerationBands implements Indicator<FasterBandsResult, Hig
public readonly width: number,
SmoothingIndicator: FasterMovingAverageTypes = FasterSMA
) {
super();
this.lowerBand = new SmoothingIndicator(interval);
this.middleBand = new SmoothingIndicator(interval);
this.upperBand = new SmoothingIndicator(interval);
Expand Down
15 changes: 9 additions & 6 deletions src/BBANDS/BollingerBands.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import {Big, type BigSource} from '../index.js';
import {Big, TechnicalIndicator, type BigSource} from '../index.js';
import {SMA} from '../SMA/SMA.js';
import {NotEnoughDataError} from '../error/index.js';
import type {BandsResult, FasterBandsResult} from '../util/BandsResult.js';
import type {Indicator} from '../Indicator.js';
import {getFasterAverage, getFasterStandardDeviation, getStandardDeviation} from '../util/index.js';

/**
Expand All @@ -20,7 +19,7 @@ import {getFasterAverage, getFasterStandardDeviation, getStandardDeviation} from
*
* @see https://www.investopedia.com/terms/b/bollingerbands.asp
*/
export class BollingerBands implements Indicator<BandsResult> {
export class BollingerBands extends TechnicalIndicator<BandsResult, BigSource> {
public readonly prices: Big[] = [];
private result: BandsResult | undefined;

Expand All @@ -32,7 +31,9 @@ export class BollingerBands implements Indicator<BandsResult> {
constructor(
public readonly interval: number,
public readonly deviationMultiplier: number = 2
) {}
) {
super();
}

get isStable(): boolean {
return this.result !== undefined;
Expand Down Expand Up @@ -69,14 +70,16 @@ export class BollingerBands implements Indicator<BandsResult> {
}
}

export class FasterBollingerBands implements Indicator<FasterBandsResult> {
export class FasterBollingerBands extends TechnicalIndicator<FasterBandsResult, BigSource> {
public readonly prices: number[] = [];
private result: FasterBandsResult | undefined;

constructor(
public readonly interval: number,
public readonly deviationMultiplier: number = 2
) {}
) {
super();
}

updates(prices: number[]) {
prices.forEach(price => this.update(price));
Expand Down
4 changes: 2 additions & 2 deletions src/DMA/DMA.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type {Big, BigSource} from '../index.js';
import {TechnicalIndicator} from '../index.js';
import type {Indicator} from '../Indicator.js';
import type {FasterMovingAverage, MovingAverage} from '../MA/MovingAverage.js';
import type {FasterMovingAverageTypes, MovingAverageTypes} from '../MA/MovingAverageTypes.js';
import {FasterSMA, SMA} from '../SMA/SMA.js';
Expand Down Expand Up @@ -55,11 +54,12 @@ export class DMA extends TechnicalIndicator<DMAResult, BigSource> {
}
}

export class FasterDMA implements Indicator<FasterDMAResult, number> {
export class FasterDMA extends TechnicalIndicator<FasterDMAResult, number> {
public readonly short: FasterMovingAverage;
public readonly long: FasterMovingAverage;

constructor(short: number, long: number, SmoothingIndicator: FasterMovingAverageTypes = FasterSMA) {
super();
this.short = new SmoothingIndicator(short);
this.long = new SmoothingIndicator(long);
}
Expand Down
9 changes: 5 additions & 4 deletions src/STOCH/StochasticOscillator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type {Indicator} from '../Indicator.js';
import {Big} from '../index.js';
import {Big, TechnicalIndicator} from '../index.js';
import {FasterSMA, SMA} from '../SMA/SMA.js';
import {getMaximum} from '../util/getMaximum.js';
import {getMinimum} from '../util/getMinimum.js';
Expand Down Expand Up @@ -37,7 +36,7 @@ export interface FasterStochasticResult {
* @see https://en.wikipedia.org/wiki/Stochastic_oscillator
* @see https://www.investopedia.com/terms/s/stochasticoscillator.asp
*/
export class StochasticOscillator implements Indicator<StochasticResult, HighLowClose> {
export class StochasticOscillator extends TechnicalIndicator<StochasticResult, HighLowClose> {
private readonly periodM: SMA;
private readonly periodP: SMA;

Expand All @@ -56,6 +55,7 @@ export class StochasticOscillator implements Indicator<StochasticResult, HighLow
public readonly m: number,
public readonly p: number
) {
super();
this.periodM = new SMA(m);
this.periodP = new SMA(p);
}
Expand Down Expand Up @@ -103,7 +103,7 @@ export class StochasticOscillator implements Indicator<StochasticResult, HighLow
}
}

export class FasterStochasticOscillator implements Indicator<FasterStochasticResult, HighLowCloseNumber> {
export class FasterStochasticOscillator extends TechnicalIndicator<FasterStochasticResult, HighLowCloseNumber> {
public readonly candles: HighLowCloseNumber[] = [];
private result: FasterStochasticResult | undefined;
private readonly periodM: FasterSMA;
Expand All @@ -119,6 +119,7 @@ export class FasterStochasticOscillator implements Indicator<FasterStochasticRes
public m: number,
public p: number
) {
super();
this.periodM = new FasterSMA(m);
this.periodP = new FasterSMA(p);
}
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export {default as Big, type BigSource} from 'big.js';
export * from './Indicator.js';
export * from './MA/MovingAverage.js';
export * from './MA/MovingAverageTypes.js';
export * from './ABANDS/AccelerationBands.js';
export * from './AC/AC.js';
export * from './ADX/ADX.js';
Expand All @@ -13,9 +16,6 @@ export * from './DMA/DMA.js';
export * from './DX/DX.js';
export * from './EMA/EMA.js';
export * from './error/index.js';
export * from './Indicator.js';
export * from './MA/MovingAverage.js';
export * from './MA/MovingAverageTypes.js';
export * from './MACD/MACD.js';
export * from './MAD/MAD.js';
export * from './MOM/MOM.js';
Expand Down
4 changes: 2 additions & 2 deletions src/util/Period.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ describe('Period', () => {
if (period.isStable) {
const expected = lowest.shift();
expect(period.lowest?.toFixed(2)).toBe(expected);
expect(fasterPeriod._lowest?.toFixed(2)).toBe(expected);
expect(fasterPeriod.lowest?.toFixed(2)).toBe(expected);
}
}
expect(period.highest?.toFixed(2)).toBe('87.77');
expect(fasterPeriod._highest?.toFixed(2)).toBe('87.77');
expect(fasterPeriod.highest?.toFixed(2)).toBe('87.77');
});
});
});
3 changes: 3 additions & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import {defineConfig} from 'vitest/config';

export default defineConfig({
esbuild: {
target: 'es2022',
},
test: {
bail: 1,
coverage: {
Expand Down

0 comments on commit a747ac8

Please sign in to comment.