Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add Momentum to Accelerator Oscillator #290

Merged
merged 1 commit into from
Aug 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/AC/AC.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ describe('AC', () => {
// https://github.com/jesse-ai/jesse/blob/53297462d48ebf43f9df46ab5005076d25073e5e/tests/test_indicators.py#L14
expect(ac.isStable).toBeTrue();
expect(ac.getResult().toFixed(2)).toBe('-21.97');
expect(ac.momentum.getResult().toFixed(2)).toBe('-9.22');
});

it('throws an error when there is not enough input data', () => {
Expand Down
4 changes: 4 additions & 0 deletions src/AC/AC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Big, {BigSource} from 'big.js';
import {NotEnoughDataError} from '../error';
import {AO} from '../AO/AO';
import {SMA} from '../SMA/SMA';
import {MOM} from '../MOM/MOM';

/**
* The Accelerator Oscillator (AC) is an indicator used to detect when a momentum changes. It has been developed by
Expand All @@ -12,13 +13,15 @@ import {SMA} from '../SMA/SMA';
* change of momentum.
*/
export class AC implements SimpleIndicator {
public readonly momentum: MOM;
private readonly ao: AO;
private result: Big | undefined;
private readonly signalSMA: SMA;

constructor(public readonly shortAO: number, public readonly longAO: number, public readonly signalInterval: number) {
this.ao = new AO(shortAO, longAO);
this.signalSMA = new SMA(signalInterval);
this.momentum = new MOM(1);
}

get isStable(): boolean {
Expand All @@ -40,6 +43,7 @@ export class AC implements SimpleIndicator {
this.signalSMA.update(ao);
if (this.signalSMA.isStable) {
this.result = ao.sub(this.signalSMA.getResult());
this.momentum.update(this.result);
}
}
}
Expand Down