Skip to content

Commit

Permalink
Warning: "substract" is a misspelling of "subtract" (misspell) (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
cinar authored Jun 20, 2022
1 parent 76f548a commit fa5c4f4
Show file tree
Hide file tree
Showing 33 changed files with 87 additions and 87 deletions.
8 changes: 4 additions & 4 deletions src/helper/numArray.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,21 @@ describe('Number Array', () => {
deepStrictEqual(actual, expected);
});

it('should be able to substract values', () => {
it('should be able to subtract values', () => {
const values1 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100];
const values2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
const expected = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90];

const actual = NumArray.substract(values1, values2);
const actual = NumArray.subtract(values1, values2);
deepStrictEqual(actual, expected);
});

it('should be able to substract by', () => {
it('should be able to subtract by', () => {
const values = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100];
const expected = [9, 19, 29, 39, 49, 59, 69, 79, 89, 99];
const n = 1;

const actual = NumArray.substractBy(n, values);
const actual = NumArray.subtractBy(n, values);
deepStrictEqual(actual, expected);
});

Expand Down
12 changes: 6 additions & 6 deletions src/helper/numArray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,12 @@ export function multiplyBy(n: number, values: number[]): number[] {
}

/**
* Substracts values2 from values1.
* Subtracts values2 from values1.
* @param values1 values one.
* @param values2 values two.
* @return result array.
*/
export function substract(values1: number[], values2: number[]): number[] {
export function subtract(values1: number[], values2: number[]): number[] {
checkSameLength(values1, values2);

const result = new Array<number>(values1.length);
Expand All @@ -147,12 +147,12 @@ export function substract(values1: number[], values2: number[]): number[] {
}

/**
* Substractes n from values.
* @param n substract value.
* Subtractes n from values.
* @param n subtract value.
* @param values values array.
* @return result array.
*/
export function substractBy(n: number, values: number[]): number[] {
export function subtractBy(n: number, values: number[]): number[] {
const result = new Array<number>(values.length);

for (let i = 0; i < values.length; i++) {
Expand Down Expand Up @@ -204,7 +204,7 @@ export function shiftRightBy(n: number, values: number[]): number[] {
* @returns changes array.
*/
export function changes(n: number, values: number[]): number[] {
return substract(values, shiftRightBy(n, values));
return subtract(values, shiftRightBy(n, values));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/indicator/momentum/awesomeOscillator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2022 Onur Cinar. All Rights Reserved.
// https://github.com/cinar/indicatorts

import { add, divideBy, substract } from '../../helper/numArray';
import { add, divideBy, subtract } from '../../helper/numArray';
import { sma } from '../trend/sma';

/**
Expand All @@ -18,6 +18,6 @@ export function awesomeOscillator(highs: number[], lows: number[]): number[] {
const medianPrice = divideBy(2, add(lows, highs));
const sma5 = sma(5, medianPrice);
const sma34 = sma(34, medianPrice);
const ao = substract(sma5, sma34);
const ao = subtract(sma5, sma34);
return ao;
}
4 changes: 2 additions & 2 deletions src/indicator/momentum/chaikinOscillator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2022 Onur Cinar. All Rights Reserved.
// https://github.com/cinar/indicatorts

import { substract } from '../../helper/numArray';
import { subtract } from '../../helper/numArray';
import { ema } from '../trend/ema';
import { accumulationDistribution } from '../volume/accumulationDistribution';

Expand Down Expand Up @@ -39,7 +39,7 @@ export function chaikinOscillator(
volumes: number[]
): ChaikinOscillator {
const ad = accumulationDistribution(highs, lows, closings, volumes);
const co = substract(ema(fastPeriod, ad), ema(slowPeriod, ad));
const co = subtract(ema(fastPeriod, ad), ema(slowPeriod, ad));

return {
ad,
Expand Down
6 changes: 3 additions & 3 deletions src/indicator/momentum/percentagePriceOscillator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2022 Onur Cinar. All Rights Reserved.
// https://github.com/cinar/indicatorts

import { divide, multiplyBy, substract } from '../../helper/numArray';
import { divide, multiplyBy, subtract } from '../../helper/numArray';
import { ema } from '../trend/ema';

/** Default fast period value. */
Expand Down Expand Up @@ -46,9 +46,9 @@ export function percentagePriceOscillator(
const fastEma = ema(fastPeriod, prices);
const slowEma = ema(slowPeriod, prices);

const ppo = multiplyBy(100, divide(substract(fastEma, slowEma), slowEma));
const ppo = multiplyBy(100, divide(subtract(fastEma, slowEma), slowEma));
const signal = ema(signalPeriod, ppo);
const histogram = substract(ppo, signal);
const histogram = subtract(ppo, signal);

return {
ppo,
Expand Down
6 changes: 3 additions & 3 deletions src/indicator/momentum/percentageVolumeOscillator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2022 Onur Cinar. All Rights Reserved.
// https://github.com/cinar/indicatorts

import { divide, multiplyBy, substract } from '../../helper/numArray';
import { divide, multiplyBy, subtract } from '../../helper/numArray';
import { ema } from '../trend/ema';

/** Default fast period value. */
Expand Down Expand Up @@ -46,9 +46,9 @@ export function percentageVolumeOscillator(
const fastEma = ema(fastPeriod, volumes);
const slowEma = ema(slowPeriod, volumes);

const pvo = multiplyBy(100, divide(substract(fastEma, slowEma), slowEma));
const pvo = multiplyBy(100, divide(subtract(fastEma, slowEma), slowEma));
const signal = ema(signalPeriod, pvo);
const histogram = substract(pvo, signal);
const histogram = subtract(pvo, signal);

return {
pvo,
Expand Down
6 changes: 3 additions & 3 deletions src/indicator/momentum/stochasticOscillator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2022 Onur Cinar. All Rights Reserved.
// https://github.com/cinar/indicatorts

import { divide, multiplyBy, substract } from '../../helper/numArray';
import { divide, multiplyBy, subtract } from '../../helper/numArray';
import { mmin } from '../trend/mmin';
import { mmax } from '../trend/mmax';
import { sma } from '../trend/sma';
Expand Down Expand Up @@ -38,8 +38,8 @@ export function stochasticOscillator(
const k = multiplyBy(
100,
divide(
substract(closings, lowestLow14),
substract(highestHigh14, lowestLow14)
subtract(closings, lowestLow14),
subtract(highestHigh14, lowestLow14)
)
);

Expand Down
4 changes: 2 additions & 2 deletions src/indicator/momentum/williamsR.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2022 Onur Cinar. All Rights Reserved.
// https://github.com/cinar/indicatorts

import { divide, multiplyBy, substract } from '../../helper/numArray';
import { divide, multiplyBy, subtract } from '../../helper/numArray';
import { mmax } from '../trend/mmax';
import { mmin } from '../trend/mmin';

Expand All @@ -28,6 +28,6 @@ export function williamsR(
const lowestLow = mmin(PERIOD, lows);
return multiplyBy(
-100,
divide(substract(highestHigh, closings), substract(highestHigh, lowestLow))
divide(subtract(highestHigh, closings), subtract(highestHigh, lowestLow))
);
}
4 changes: 2 additions & 2 deletions src/indicator/trend/absolutePriceOscillator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2022 Onur Cinar. All Rights Reserved.
// https://github.com/cinar/indicatorts

import { substract } from '../../helper/numArray';
import { subtract } from '../../helper/numArray';
import { ema } from './ema';

/**
Expand All @@ -26,7 +26,7 @@ export function absolutePriceOscillator(
): number[] {
const fast = ema(fastPeriod, values);
const slow = ema(slowPeriod, values);
const apo = substract(fast, slow);
const apo = subtract(fast, slow);
return apo;
}

Expand Down
4 changes: 2 additions & 2 deletions src/indicator/trend/balanceOfPower.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2022 Onur Cinar. All Rights Reserved.
// https://github.com/cinar/indicatorts

import { divide, substract } from '../../helper/numArray';
import { divide, subtract } from '../../helper/numArray';

/**
* The Balance of Power (BOP) function calculates the strength of buying and
Expand All @@ -23,5 +23,5 @@ export function balanceOfPower(
lows: number[],
closings: number[]
): number[] {
return divide(substract(closings, openings), substract(highs, lows));
return divide(subtract(closings, openings), subtract(highs, lows));
}
6 changes: 3 additions & 3 deletions src/indicator/trend/chandeForecastOscillator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
divide,
generateNumbers,
multiplyBy,
substract,
subtract,
} from '../../helper/numArray';
import {
linearRegressionUsingLeastSquare,
Expand All @@ -28,7 +28,7 @@ import {
export function chandeForecastOscillator(closings: number[]): number[] {
const x = generateNumbers(0, closings.length, 1);
const r = linearRegressionUsingLeastSquare(x, closings);
const cfo = multiplyBy(100, divide(substract(closings, r), closings));
const cfo = multiplyBy(100, divide(subtract(closings, r), closings));
return cfo;
}

Expand All @@ -55,6 +55,6 @@ export function movingChandeForecastOscillator(
): number[] {
const x = generateNumbers(0, closings.length, 1);
const r = movingLinearRegressionUsingLeastSquare(period, x, closings);
const cfo = multiplyBy(100, divide(substract(closings, r), closings));
const cfo = multiplyBy(100, divide(subtract(closings, r), closings));
return cfo;
}
6 changes: 3 additions & 3 deletions src/indicator/trend/communityChannelIndex.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2022 Onur Cinar. All Rights Reserved.
// https://github.com/cinar/indicatorts

import { abs, divide, multiplyBy, substract } from '../../helper/numArray';
import { abs, divide, multiplyBy, subtract } from '../../helper/numArray';
import { sma } from './sma';
import { typicalPrice } from './typicalPrice';

Expand Down Expand Up @@ -33,8 +33,8 @@ export function communityChannelIndex(
): number[] {
const tp = typicalPrice(highs, lows, closings);
const ma = sma(period, tp);
const md = sma(period, abs(substract(tp, ma)));
const cci = divide(substract(tp, ma), multiplyBy(0.015, md));
const md = sma(period, abs(subtract(tp, ma)));
const cci = divide(subtract(tp, ma), multiplyBy(0.015, md));
return cci;
}

Expand Down
4 changes: 2 additions & 2 deletions src/indicator/trend/dema.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2022 Onur Cinar. All Rights Reserved.
// https://github.com/cinar/indicatorts

import { multiplyBy, substract } from '../../helper/numArray';
import { multiplyBy, subtract } from '../../helper/numArray';
import { ema } from './ema';

/**
Expand All @@ -17,7 +17,7 @@ export function dema(period: number, values: number[]): number[] {
const ema1 = ema(period, values);
const ema2 = ema(period, ema1);

const dema = substract(multiplyBy(2, ema1), ema2);
const dema = subtract(multiplyBy(2, ema1), ema2);

return dema;
}
6 changes: 3 additions & 3 deletions src/indicator/trend/kdj.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2022 Onur Cinar. All Rights Reserved.
// https://github.com/cinar/indicatorts

import { divide, multiplyBy, substract } from '../../helper/numArray';
import { divide, multiplyBy, subtract } from '../../helper/numArray';
import { mmin } from './mmin';
import { mmax } from './mmax';
import { sma } from './sma';
Expand Down Expand Up @@ -52,12 +52,12 @@ export function kdj(

const rsv = multiplyBy(
100,
divide(substract(closings, lowest), substract(highest, lowest))
divide(subtract(closings, lowest), subtract(highest, lowest))
);

const k = sma(kPeriod, rsv);
const d = sma(dPeriod, k);
const j = substract(multiplyBy(3, k), multiplyBy(2, d));
const j = subtract(multiplyBy(3, k), multiplyBy(2, d));

return {
k,
Expand Down
4 changes: 2 additions & 2 deletions src/indicator/trend/macd.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2022 Onur Cinar. All Rights Reserved.
// https://github.com/cinar/indicatorts

import { substract } from '../../helper/numArray';
import { subtract } from '../../helper/numArray';
import { ema } from './ema';

export interface MacdResult {
Expand All @@ -22,7 +22,7 @@ export function macd(closings: number[]): MacdResult {
const ema12 = ema(12, closings);
const ema26 = ema(26, closings);

const macdLine = substract(ema12, ema26);
const macdLine = subtract(ema12, ema26);
const signalLine = ema(9, macdLine);

return {
Expand Down
4 changes: 2 additions & 2 deletions src/indicator/trend/massIndex.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2022 Onur Cinar. All Rights Reserved.
// https://github.com/cinar/indicatorts

import { divide, substract } from '../../helper/numArray';
import { divide, subtract } from '../../helper/numArray';
import { ema } from './ema';
import { msum } from './msum';

Expand All @@ -19,7 +19,7 @@ import { msum } from './msum';
* @returns mi values.
*/
export function massIndex(highs: number[], lows: number[]): number[] {
const ema1 = ema(9, substract(highs, lows));
const ema1 = ema(9, subtract(highs, lows));
const ema2 = ema(9, ema1);
const ratio = divide(ema1, ema2);
const mi = msum(25, ratio);
Expand Down
4 changes: 2 additions & 2 deletions src/indicator/trend/qstick.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2022 Onur Cinar. All Rights Reserved.
// https://github.com/cinar/indicatorts

import { substract } from '../../helper/numArray';
import { subtract } from '../../helper/numArray';
import { sma } from './sma';

/**
Expand All @@ -19,5 +19,5 @@ export function qstick(
openings: number[],
closings: number[]
): number[] {
return sma(period, substract(closings, openings));
return sma(period, subtract(closings, openings));
}
4 changes: 2 additions & 2 deletions src/indicator/trend/tema.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2022 Onur Cinar. All Rights Reserved.
// https://github.com/cinar/indicatorts

import { add, multiplyBy, substract } from '../../helper/numArray';
import { add, multiplyBy, subtract } from '../../helper/numArray';
import { ema } from './ema';

/**
Expand All @@ -22,7 +22,7 @@ export function tema(period: number, values: number[]): number[] {
const ema3 = ema(period, ema2);

const temaLine = add(
substract(multiplyBy(3, ema1), multiplyBy(3, ema2)),
subtract(multiplyBy(3, ema1), multiplyBy(3, ema2)),
ema3
);

Expand Down
4 changes: 2 additions & 2 deletions src/indicator/trend/trix.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2022 Onur Cinar. All Rights Reserved.
// https://github.com/cinar/indicatorts

import { divide, shiftRightAndFillBy, substract } from '../../helper/numArray';
import { divide, shiftRightAndFillBy, subtract } from '../../helper/numArray';
import { ema } from './ema';

/**
Expand All @@ -24,6 +24,6 @@ export function trix(period: number, values: number[]): number[] {
const ema2 = ema(period, ema1);
const ema3 = ema(period, ema2);
const previous = shiftRightAndFillBy(1, ema3[0], ema3);
const trix = divide(substract(ema3, previous), previous);
const trix = divide(subtract(ema3, previous), previous);
return trix;
}
Loading

0 comments on commit fa5c4f4

Please sign in to comment.