Skip to content

Commit 4b701bf

Browse files
committed
refactor(LINREG): Expose Linear Regression
1 parent 6ae426c commit 4b701bf

File tree

5 files changed

+11
-3
lines changed

5 files changed

+11
-3
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ It is very important to do your own analysis before making any investment based
202202

203203
- [Cloud9Trader Indicators (JavaScript)](https://github.com/Cloud9Trader/TechnicalIndicators)
204204
- [Crypto Trading Hub Indicators (TypeScript)](https://github.com/anandanand84/technicalindicators)
205+
- [Indicator TS](https://github.com/cinar/indicatorts)
205206
- [Jesse Trading Bot Indicators (Python)](https://docs.jesse.trade/docs/indicators/reference.html)
206207
- [LEAN Indicators](https://github.com/QuantConnect/Lean/tree/master/Indicators)
207208
- [libindicators (C#)](https://github.com/mgfx/libindicators)

src/BBANDS/BollingerBands.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ describe('BollingerBands', () => {
6363
it('is compatible with results from Tulip Indicators (TI)', () => {
6464
// Test data verified with:
6565
// https://tulipindicators.org/bbands
66+
// https://github.com/TulipCharts/tulipindicators/blob/v0.9.1/tests/untest.txt#L86
6667
const inputs = [
6768
81.59, 81.06, 82.87, 83.0, 83.61, 83.15, 82.84, 83.99, 84.55, 84.36, 85.53, 86.54, 86.89, 87.77, 87.29,
6869
];

src/LINEAR_REGRESSION/LinearRegression.test.ts src/LINREG/LinearRegression.test.ts

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import {NotEnoughDataError} from '../error/index.js';
55
describe('LinearRegression', () => {
66
describe('prediction (linreg)', () => {
77
it('calculates the prediction values correctly', () => {
8+
// Test data verified with:
9+
// https://github.com/TulipCharts/tulipindicators/blob/v0.9.1/tests/untest.txt#L222
810
const period = 5;
911
const prices = [
1012
81.59, 81.06, 82.87, 83.0, 83.61, 83.15, 82.84, 83.99, 84.55, 84.36, 85.53, 86.54, 86.89, 87.77, 87.29,
@@ -24,6 +26,8 @@ describe('LinearRegression', () => {
2426

2527
describe('intercept (linregintercept)', () => {
2628
it('calculates the intercept values correctly', () => {
29+
// Test data verified with:
30+
// https://github.com/TulipCharts/tulipindicators/blob/v0.9.1/tests/untest.txt#L226
2731
const period = 5;
2832
const prices = [
2933
81.59, 81.06, 82.87, 83.0, 83.61, 83.15, 82.84, 83.99, 84.55, 84.36, 85.53, 86.54, 86.89, 87.77, 87.29,
@@ -43,6 +47,8 @@ describe('LinearRegression', () => {
4347

4448
describe('slope (linregslope)', () => {
4549
it('calculates the slope values correctly', () => {
50+
// Test data verified with:
51+
// https://github.com/TulipCharts/tulipindicators/blob/v0.9.1/tests/untest.txt#L230
4652
const period = 5;
4753
const prices = [
4854
81.59, 81.06, 82.87, 83.0, 83.61, 83.15, 82.84, 83.99, 84.55, 84.36, 85.53, 86.54, 86.89, 87.77, 87.29,

src/LINEAR_REGRESSION/LinearRegression.ts src/LINREG/LinearRegression.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,10 @@ export class FasterLinearRegression extends TechnicalIndicator<FasterLinearRegre
150150
}
151151

152152
override getResultOrThrow(): FasterLinearRegressionResult {
153-
if (this.prices.length < this.period) {
153+
if (!this.result) {
154154
throw new NotEnoughDataError();
155155
}
156-
return this.result!;
156+
return this.result;
157157
}
158158

159159
override get isStable(): boolean {

src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export * from './SMA/SMA.js';
2929
export * from './STOCH/StochasticOscillator.js';
3030
export * from './STOCH/StochasticRSI.js';
3131
export * from './TR/TR.js';
32-
export * from './LINEAR_REGRESSION/LinearRegression.js';
32+
export * from './LINREG/LinearRegression.js';
3333
export * from './util/index.js';
3434
export * from './WMA/WMA.js';
3535
export * from './WSMA/WSMA.js';

0 commit comments

Comments
 (0)