backtest-kit 11.5.2 → 11.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +1996 -1996
- package/build/index.cjs +689 -50
- package/build/index.mjs +689 -50
- package/package.json +86 -86
- package/types.d.ts +72 -0
package/package.json
CHANGED
|
@@ -1,86 +1,86 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "backtest-kit",
|
|
3
|
-
"version": "11.
|
|
4
|
-
"description": "A TypeScript library for trading system backtest",
|
|
5
|
-
"author": {
|
|
6
|
-
"name": "Petr Tripolsky",
|
|
7
|
-
"email": "tripolskypetr@gmail.com",
|
|
8
|
-
"url": "https://github.com/tripolskypetr"
|
|
9
|
-
},
|
|
10
|
-
"funding": {
|
|
11
|
-
"type": "individual",
|
|
12
|
-
"url": "http://paypal.me/tripolskypetr"
|
|
13
|
-
},
|
|
14
|
-
"license": "MIT",
|
|
15
|
-
"homepage": "https://backtest-kit.github.io/documents/article_07_ai_news_trading_signals.html",
|
|
16
|
-
"keywords": [
|
|
17
|
-
"backtesting",
|
|
18
|
-
"backtest",
|
|
19
|
-
"finance",
|
|
20
|
-
"trading",
|
|
21
|
-
"candles",
|
|
22
|
-
"indicators",
|
|
23
|
-
"multi value",
|
|
24
|
-
"multi symbol",
|
|
25
|
-
"framework"
|
|
26
|
-
],
|
|
27
|
-
"files": [
|
|
28
|
-
"build",
|
|
29
|
-
"types.d.ts",
|
|
30
|
-
"README.md"
|
|
31
|
-
],
|
|
32
|
-
"repository": {
|
|
33
|
-
"type": "git",
|
|
34
|
-
"url": "https://github.com/tripolskypetr/backtest-kit",
|
|
35
|
-
"documentation": "https://github.com/tripolskypetr/backtest-kit/tree/master/docs"
|
|
36
|
-
},
|
|
37
|
-
"bugs": {
|
|
38
|
-
"url": "https://github.com/tripolskypetr/backtest-kit/issues"
|
|
39
|
-
},
|
|
40
|
-
"scripts": {
|
|
41
|
-
"build": "rollup -c",
|
|
42
|
-
"test": "npm run build && node ./test/index.mjs",
|
|
43
|
-
"build:docs": "rimraf docs && mkdir docs && node ./scripts/dts-docs.cjs ./types.d.ts ./docs",
|
|
44
|
-
"docs:gpt": "npm run build && node ./tools/gpt-docs/index.mjs",
|
|
45
|
-
"docs:uml": "npm run build && node ./scripts/uml.mjs",
|
|
46
|
-
"docs:www": "rimraf docs/wwwroot && node ./tools/typedoc-packages-docs/index.mjs && typedoc && node ./tools/typedoc-yandex-metrica/index.mjs",
|
|
47
|
-
"repl": "dotenv -e .env -- npm run build && node -e \"import('./scripts/repl.mjs')\" --interactive"
|
|
48
|
-
},
|
|
49
|
-
"main": "build/index.cjs",
|
|
50
|
-
"module": "build/index.mjs",
|
|
51
|
-
"source": "src/index.ts",
|
|
52
|
-
"types": "./types.d.ts",
|
|
53
|
-
"exports": {
|
|
54
|
-
"require": "./build/index.cjs",
|
|
55
|
-
"types": "./types.d.ts",
|
|
56
|
-
"import": "./build/index.mjs",
|
|
57
|
-
"default": "./build/index.cjs"
|
|
58
|
-
},
|
|
59
|
-
"devDependencies": {
|
|
60
|
-
"@rollup/plugin-typescript": "11.1.6",
|
|
61
|
-
"@types/node": "22.9.0",
|
|
62
|
-
"glob": "11.0.1",
|
|
63
|
-
"plantuml": "0.0.2",
|
|
64
|
-
"rimraf": "6.0.1",
|
|
65
|
-
"rollup": "3.29.5",
|
|
66
|
-
"rollup-plugin-dts": "6.1.1",
|
|
67
|
-
"rollup-plugin-peer-deps-external": "2.2.4",
|
|
68
|
-
"ts-morph": "27.0.2",
|
|
69
|
-
"tslib": "2.7.0",
|
|
70
|
-
"typedoc": "0.27.9",
|
|
71
|
-
"worker-testbed": "2.0.0"
|
|
72
|
-
},
|
|
73
|
-
"peerDependencies": {
|
|
74
|
-
"typescript": "^5.0.0"
|
|
75
|
-
},
|
|
76
|
-
"dependencies": {
|
|
77
|
-
"di-kit": "^1.1.1",
|
|
78
|
-
"di-scoped": "^1.0.21",
|
|
79
|
-
"di-singleton": "^1.0.5",
|
|
80
|
-
"functools-kit": "^2.3.0",
|
|
81
|
-
"get-moment-stamp": "^2.0.0"
|
|
82
|
-
},
|
|
83
|
-
"publishConfig": {
|
|
84
|
-
"access": "public"
|
|
85
|
-
}
|
|
86
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "backtest-kit",
|
|
3
|
+
"version": "11.7.0",
|
|
4
|
+
"description": "A TypeScript library for trading system backtest",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "Petr Tripolsky",
|
|
7
|
+
"email": "tripolskypetr@gmail.com",
|
|
8
|
+
"url": "https://github.com/tripolskypetr"
|
|
9
|
+
},
|
|
10
|
+
"funding": {
|
|
11
|
+
"type": "individual",
|
|
12
|
+
"url": "http://paypal.me/tripolskypetr"
|
|
13
|
+
},
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"homepage": "https://backtest-kit.github.io/documents/article_07_ai_news_trading_signals.html",
|
|
16
|
+
"keywords": [
|
|
17
|
+
"backtesting",
|
|
18
|
+
"backtest",
|
|
19
|
+
"finance",
|
|
20
|
+
"trading",
|
|
21
|
+
"candles",
|
|
22
|
+
"indicators",
|
|
23
|
+
"multi value",
|
|
24
|
+
"multi symbol",
|
|
25
|
+
"framework"
|
|
26
|
+
],
|
|
27
|
+
"files": [
|
|
28
|
+
"build",
|
|
29
|
+
"types.d.ts",
|
|
30
|
+
"README.md"
|
|
31
|
+
],
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "https://github.com/tripolskypetr/backtest-kit",
|
|
35
|
+
"documentation": "https://github.com/tripolskypetr/backtest-kit/tree/master/docs"
|
|
36
|
+
},
|
|
37
|
+
"bugs": {
|
|
38
|
+
"url": "https://github.com/tripolskypetr/backtest-kit/issues"
|
|
39
|
+
},
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "rollup -c",
|
|
42
|
+
"test": "npm run build && node ./test/index.mjs",
|
|
43
|
+
"build:docs": "rimraf docs && mkdir docs && node ./scripts/dts-docs.cjs ./types.d.ts ./docs",
|
|
44
|
+
"docs:gpt": "npm run build && node ./tools/gpt-docs/index.mjs",
|
|
45
|
+
"docs:uml": "npm run build && node ./scripts/uml.mjs",
|
|
46
|
+
"docs:www": "rimraf docs/wwwroot && node ./tools/typedoc-packages-docs/index.mjs && typedoc && node ./tools/typedoc-yandex-metrica/index.mjs",
|
|
47
|
+
"repl": "dotenv -e .env -- npm run build && node -e \"import('./scripts/repl.mjs')\" --interactive"
|
|
48
|
+
},
|
|
49
|
+
"main": "build/index.cjs",
|
|
50
|
+
"module": "build/index.mjs",
|
|
51
|
+
"source": "src/index.ts",
|
|
52
|
+
"types": "./types.d.ts",
|
|
53
|
+
"exports": {
|
|
54
|
+
"require": "./build/index.cjs",
|
|
55
|
+
"types": "./types.d.ts",
|
|
56
|
+
"import": "./build/index.mjs",
|
|
57
|
+
"default": "./build/index.cjs"
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"@rollup/plugin-typescript": "11.1.6",
|
|
61
|
+
"@types/node": "22.9.0",
|
|
62
|
+
"glob": "11.0.1",
|
|
63
|
+
"plantuml": "0.0.2",
|
|
64
|
+
"rimraf": "6.0.1",
|
|
65
|
+
"rollup": "3.29.5",
|
|
66
|
+
"rollup-plugin-dts": "6.1.1",
|
|
67
|
+
"rollup-plugin-peer-deps-external": "2.2.4",
|
|
68
|
+
"ts-morph": "27.0.2",
|
|
69
|
+
"tslib": "2.7.0",
|
|
70
|
+
"typedoc": "0.27.9",
|
|
71
|
+
"worker-testbed": "2.0.0"
|
|
72
|
+
},
|
|
73
|
+
"peerDependencies": {
|
|
74
|
+
"typescript": "^5.0.0"
|
|
75
|
+
},
|
|
76
|
+
"dependencies": {
|
|
77
|
+
"di-kit": "^1.1.1",
|
|
78
|
+
"di-scoped": "^1.0.21",
|
|
79
|
+
"di-singleton": "^1.0.5",
|
|
80
|
+
"functools-kit": "^2.3.0",
|
|
81
|
+
"get-moment-stamp": "^2.0.0"
|
|
82
|
+
},
|
|
83
|
+
"publishConfig": {
|
|
84
|
+
"access": "public"
|
|
85
|
+
}
|
|
86
|
+
}
|
package/types.d.ts
CHANGED
|
@@ -4636,6 +4636,18 @@ interface BacktestStatisticsModel {
|
|
|
4636
4636
|
recoveryFactor: number | null;
|
|
4637
4637
|
/** Per-trade Expectancy (winProb*avgWin + lossProb*avgLoss), null if unsafe. Higher is better. */
|
|
4638
4638
|
expectancy: number | null;
|
|
4639
|
+
/** Average trade duration in minutes ((closeTimestamp - pendingAt) / 60_000), null if unsafe. */
|
|
4640
|
+
avgDuration: number | null;
|
|
4641
|
+
/** Median pnlPercentage — robust to outliers; reveals distribution skew when paired with avgPnl. */
|
|
4642
|
+
medianPnl: number | null;
|
|
4643
|
+
/** Average sum of pnlPercentage across consecutive winning streaks. Null if no win streak. */
|
|
4644
|
+
avgConsecutiveWinPnl: number | null;
|
|
4645
|
+
/** Average sum of pnlPercentage across consecutive losing streaks. Null if no loss streak. Closer to 0 is better. */
|
|
4646
|
+
avgConsecutiveLossPnl: number | null;
|
|
4647
|
+
/** Average duration in minutes of winning trades. */
|
|
4648
|
+
avgWinDuration: number | null;
|
|
4649
|
+
/** Average duration in minutes of losing trades. */
|
|
4650
|
+
avgLossDuration: number | null;
|
|
4639
4651
|
}
|
|
4640
4652
|
|
|
4641
4653
|
/**
|
|
@@ -10727,12 +10739,36 @@ interface IHeatmapRow {
|
|
|
10727
10739
|
avgPeakPnl: number | null;
|
|
10728
10740
|
/** Average fall PNL percentage across all trades (_fall.pnlPercentage). Closer to 0 is better. */
|
|
10729
10741
|
avgFallPnl: number | null;
|
|
10742
|
+
/** Maximum peak PNL percentage observed across all trades (best best-case). Higher is better. */
|
|
10743
|
+
peakProfitPnl: number | null;
|
|
10744
|
+
/** Minimum fall PNL percentage observed across all trades (worst worst-case). Closer to 0 is better. */
|
|
10745
|
+
maxDrawdownPnl: number | null;
|
|
10746
|
+
/** Average trade duration in minutes ((closeTimestamp - pendingAt) / 60_000). */
|
|
10747
|
+
avgDuration: number | null;
|
|
10748
|
+
/** Median pnlPercentage — robust to outliers; reveals distribution skew when paired with avgPnl. */
|
|
10749
|
+
medianPnl: number | null;
|
|
10750
|
+
/** Average sum of pnlPercentage across consecutive winning streaks. Null if no win streak. */
|
|
10751
|
+
avgConsecutiveWinPnl: number | null;
|
|
10752
|
+
/** Average sum of pnlPercentage across consecutive losing streaks. Null if no loss streak. Closer to 0 is better. */
|
|
10753
|
+
avgConsecutiveLossPnl: number | null;
|
|
10754
|
+
/** Average duration in minutes of winning trades. */
|
|
10755
|
+
avgWinDuration: number | null;
|
|
10756
|
+
/** Average duration in minutes of losing trades. */
|
|
10757
|
+
avgLossDuration: number | null;
|
|
10730
10758
|
/** Sortino Ratio (avgPnl / downside deviation — RMS of losing trades only). Higher is better. */
|
|
10731
10759
|
sortinoRatio: number | null;
|
|
10732
10760
|
/** Calmar Ratio (totalPnl / maxDrawdown). Higher is better. */
|
|
10733
10761
|
calmarRatio: number | null;
|
|
10734
10762
|
/** Recovery Factor (totalPnl / maxDrawdown). Higher is better. */
|
|
10735
10763
|
recoveryFactor: number | null;
|
|
10764
|
+
/** Annualized Sharpe Ratio (sharpeRatio × √tradesPerYear). Higher is better. */
|
|
10765
|
+
annualizedSharpeRatio: number | null;
|
|
10766
|
+
/** Certainty Ratio (avgWin / |avgLoss|). Higher is better. */
|
|
10767
|
+
certaintyRatio: number | null;
|
|
10768
|
+
/** Expected yearly returns (geometric, capped at ±MAX_EXPECTED_YEARLY_RETURNS). Higher is better. */
|
|
10769
|
+
expectedYearlyReturns: number | null;
|
|
10770
|
+
/** Observed trade frequency extrapolated to one year (signals × 365 / calendarSpanDays). */
|
|
10771
|
+
tradesPerYear: number | null;
|
|
10736
10772
|
}
|
|
10737
10773
|
|
|
10738
10774
|
/**
|
|
@@ -12613,6 +12649,18 @@ interface LiveStatisticsModel {
|
|
|
12613
12649
|
recoveryFactor: number | null;
|
|
12614
12650
|
/** Per-trade Expectancy (winProb*avgWin + lossProb*avgLoss), null if unsafe. Higher is better. */
|
|
12615
12651
|
expectancy: number | null;
|
|
12652
|
+
/** Average trade duration in minutes ((timestamp - pendingAt) / 60_000), null if unsafe. */
|
|
12653
|
+
avgDuration: number | null;
|
|
12654
|
+
/** Median pnl — robust to outliers; reveals distribution skew when paired with avgPnl. */
|
|
12655
|
+
medianPnl: number | null;
|
|
12656
|
+
/** Average sum of pnl across consecutive winning streaks. Null if no win streak. */
|
|
12657
|
+
avgConsecutiveWinPnl: number | null;
|
|
12658
|
+
/** Average sum of pnl across consecutive losing streaks. Null if no loss streak. Closer to 0 is better. */
|
|
12659
|
+
avgConsecutiveLossPnl: number | null;
|
|
12660
|
+
/** Average duration in minutes of winning trades. */
|
|
12661
|
+
avgWinDuration: number | null;
|
|
12662
|
+
/** Average duration in minutes of losing trades. */
|
|
12663
|
+
avgLossDuration: number | null;
|
|
12616
12664
|
}
|
|
12617
12665
|
|
|
12618
12666
|
/**
|
|
@@ -12634,6 +12682,22 @@ interface HeatmapStatisticsModel {
|
|
|
12634
12682
|
portfolioAvgPeakPnl: number | null;
|
|
12635
12683
|
/** Trade-count-weighted average fall PNL across all symbols. Closer to 0 is better. */
|
|
12636
12684
|
portfolioAvgFallPnl: number | null;
|
|
12685
|
+
/** Maximum peak PNL across all trades of all symbols (best best-case). Higher is better. */
|
|
12686
|
+
portfolioPeakProfitPnl: number | null;
|
|
12687
|
+
/** Minimum fall PNL across all trades of all symbols (worst worst-case). Closer to 0 is better. */
|
|
12688
|
+
portfolioMaxDrawdownPnl: number | null;
|
|
12689
|
+
/** Pooled average trade duration in minutes across all trades of all symbols. */
|
|
12690
|
+
portfolioAvgDuration: number | null;
|
|
12691
|
+
/** Pooled median pnlPercentage across all trades of all symbols. */
|
|
12692
|
+
portfolioMedianPnl: number | null;
|
|
12693
|
+
/** Trade-count-weighted mean of per-symbol avgConsecutiveWinPnl. Null if no symbol has a win streak. */
|
|
12694
|
+
portfolioAvgConsecutiveWinPnl: number | null;
|
|
12695
|
+
/** Trade-count-weighted mean of per-symbol avgConsecutiveLossPnl. Null if no symbol has a loss streak. */
|
|
12696
|
+
portfolioAvgConsecutiveLossPnl: number | null;
|
|
12697
|
+
/** Pooled average duration in minutes of winning trades. */
|
|
12698
|
+
portfolioAvgWinDuration: number | null;
|
|
12699
|
+
/** Pooled average duration in minutes of losing trades. */
|
|
12700
|
+
portfolioAvgLossDuration: number | null;
|
|
12637
12701
|
/** Pooled sample standard deviation of returns across all symbols. */
|
|
12638
12702
|
portfolioStdDev: number | null;
|
|
12639
12703
|
/** Pooled Sortino Ratio over all trades. Same canonical formula as per-symbol. */
|
|
@@ -12644,6 +12708,14 @@ interface HeatmapStatisticsModel {
|
|
|
12644
12708
|
portfolioRecoveryFactor: number | null;
|
|
12645
12709
|
/** Pooled Expectancy: winProb*avgWin + lossProb*avgLoss (per-trade expected %). */
|
|
12646
12710
|
portfolioExpectancy: number | null;
|
|
12711
|
+
/** Pooled Annualized Sharpe Ratio (portfolioSharpeRatio × √portfolioTradesPerYear). Higher is better. */
|
|
12712
|
+
portfolioAnnualizedSharpeRatio: number | null;
|
|
12713
|
+
/** Pooled Certainty Ratio (pooledAvgWin / |pooledAvgLoss|). Higher is better. */
|
|
12714
|
+
portfolioCertaintyRatio: number | null;
|
|
12715
|
+
/** Pooled expected yearly returns (geometric annualization of pooled equity, capped at ±MAX_EXPECTED_YEARLY_RETURNS). */
|
|
12716
|
+
portfolioExpectedYearlyReturns: number | null;
|
|
12717
|
+
/** Pooled observed trade frequency extrapolated to one year. */
|
|
12718
|
+
portfolioTradesPerYear: number | null;
|
|
12647
12719
|
}
|
|
12648
12720
|
|
|
12649
12721
|
/**
|