Skip to content
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: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
},
"homepage": "https://github.com/fugle-dev/fugle-backtest-node#readme",
"dependencies": {
"danfojs-node": "^1.1.2",
"html-minifier": "^4.0.0",
"lodash": "^4.17.21",
"luxon": "^3.2.1",
Expand Down
9 changes: 5 additions & 4 deletions src/backtest.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { DataFrame, Series, toJSON } from 'danfojs-node';
import { intersection, maxBy } from 'lodash';
import { Strategy as BaseStrategy } from './strategy';
import { Broker } from './broker';
Expand All @@ -7,6 +6,9 @@ import { Stats } from './stats';
import { HistoricalData, BacktestOptions, Context } from './interfaces';
import { StatsIndex } from './enums';

import DataFrame from './ndframe/dataframe';
import Series from './ndframe/series';

export class Backtest {
private _data: DataFrame;
private _stats?: Stats;
Expand Down Expand Up @@ -65,8 +67,7 @@ export class Backtest {
});
const strategy = new this.Strategy(data, broker);

// @ts-ignore
if (options?.params) strategy.params = options.params;
if (options?.params) (strategy as any).params = options.params;

strategy.init();

Expand Down Expand Up @@ -161,7 +162,7 @@ export class Backtest {

const data = {
date: rows.index[0],
...(toJSON(rows) as Record<string, number>[])[0],
...(rows.toJSON() as Record<string, number>[])[0],
};

const indicators = new Map(
Expand Down
4 changes: 3 additions & 1 deletion src/broker.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import * as assert from 'assert';
import { DataFrame } from 'danfojs-node';
import { last, first, sumBy, remove } from 'lodash';
import { Order } from './order';
import { Trade } from './trade';
import { Position } from './position';
import { BrokerOptions, OrderOptions } from './interfaces';

import DataFrame from './ndframe/dataframe';

export class Broker {
private _i: number;
private _cash: number;
Expand Down Expand Up @@ -135,6 +136,7 @@ export class Broker {
const isStopHit = order.isLong ? (high > stopPrice) : (low < stopPrice);
/* istanbul ignore if */
if (!isStopHit) continue;
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
delete order._stopPrice;
}
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/context.interface.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DataFrame } from 'danfojs-node';
import DataFrame from '../ndframe/dataframe';

export interface Context {
index: number;
Expand Down
Loading
Loading