backtest-kit 9.7.0 → 9.8.1

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.
Files changed (6) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +1871 -1871
  3. package/build/index.cjs +283 -180
  4. package/build/index.mjs +284 -181
  5. package/package.json +86 -86
  6. package/types.d.ts +100 -28
package/package.json CHANGED
@@ -1,86 +1,86 @@
1
- {
2
- "name": "backtest-kit",
3
- "version": "9.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": "^1.1.2"
82
- },
83
- "publishConfig": {
84
- "access": "public"
85
- }
86
- }
1
+ {
2
+ "name": "backtest-kit",
3
+ "version": "9.8.1",
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": "^1.1.2"
82
+ },
83
+ "publishConfig": {
84
+ "access": "public"
85
+ }
86
+ }
package/types.d.ts CHANGED
@@ -4406,8 +4406,8 @@ interface ICacheCandlesParams {
4406
4406
  to: Date;
4407
4407
  }
4408
4408
  /**
4409
- * Parameters for validating cached candle timestamps.
4410
- * Reads JSON files directly from persist storage directory.
4409
+ * Parameters for validating cached candle presence.
4410
+ * Queries persist storage adapter without scanning files.
4411
4411
  */
4412
4412
  interface ICheckCandlesParams {
4413
4413
  /** Trading pair symbol (e.g., "BTCUSDT") */
@@ -4420,12 +4420,11 @@ interface ICheckCandlesParams {
4420
4420
  from: Date;
4421
4421
  /** End date of the validation range (inclusive) */
4422
4422
  to: Date;
4423
- /** Base directory of candle persist storage (default: "./dump/data/candle") */
4424
- baseDir?: string;
4425
4423
  }
4426
4424
  /**
4427
- * Checks cached candle timestamps for correct interval alignment.
4428
- * Reads JSON files directly from persist storage without using abstractions.
4425
+ * Checks cached candle presence via the persist adapter.
4426
+ * Issues one ranged read; adapter-side `hasValue` covers each expected timestamp,
4427
+ * so a single missing or unaligned candle yields a miss without loading the whole dataset.
4429
4428
  *
4430
4429
  * @param params - Validation parameters
4431
4430
  */
@@ -16683,8 +16682,17 @@ type TLogCtor = new () => Partial<ILog>;
16683
16682
  * - Convenience methods: usePersist(), useMemory(), useDummy()
16684
16683
  */
16685
16684
  declare class LogAdapter implements ILog {
16686
- /** Internal log utils instance */
16687
- private _log;
16685
+ /** Factory producing the active log utils instance */
16686
+ private _logFactory;
16687
+ /**
16688
+ * Lazily constructs the log utils from the registered factory and memoizes
16689
+ * the result via `singleshot`.
16690
+ *
16691
+ * The instance is built on the first call and cached for all subsequent calls.
16692
+ * Reset via `clear()` so the next call rebuilds from the current factory
16693
+ * (e.g. when `process.cwd()` changes between strategy iterations).
16694
+ */
16695
+ private getInstance;
16688
16696
  /**
16689
16697
  * Lists all stored log entries.
16690
16698
  * Proxies call to the underlying log adapter.
@@ -16750,7 +16758,7 @@ declare class LogAdapter implements ILog {
16750
16758
  */
16751
16759
  useJsonl: (fileName?: string, dirName?: string) => void;
16752
16760
  /**
16753
- * Clears the cached log instance by resetting to the default in-memory adapter.
16761
+ * Clears the memoized log instance.
16754
16762
  * Call this when process.cwd() changes between strategy iterations
16755
16763
  * so a new adapter instance is created with the updated base path.
16756
16764
  */
@@ -23669,8 +23677,16 @@ type TStorageUtilsCtor = new () => IStorageUtils;
23669
23677
  * - Convenience methods: usePersist(), useMemory(), useDummy()
23670
23678
  */
23671
23679
  declare class StorageBacktestAdapter implements IStorageUtils {
23672
- /** Internal storage utils instance */
23673
- private _signalBacktestUtils;
23680
+ /** Factory producing the active storage utils instance */
23681
+ private _signalBacktestFactory;
23682
+ /**
23683
+ * Lazily constructs the storage utils from the registered factory and memoizes
23684
+ * the result via `singleshot`.
23685
+ *
23686
+ * The instance is built on the first call and cached for all subsequent calls.
23687
+ * Reset via `clear()` so the next call rebuilds from the current factory.
23688
+ */
23689
+ private getInstance;
23674
23690
  /**
23675
23691
  * Handles signal opened event.
23676
23692
  * Proxies call to the underlying storage adapter.
@@ -23733,7 +23749,7 @@ declare class StorageBacktestAdapter implements IStorageUtils {
23733
23749
  */
23734
23750
  useMemory: () => void;
23735
23751
  /**
23736
- * Clears the cached utils instance by resetting to the default in-memory adapter.
23752
+ * Clears the memoized utils instance.
23737
23753
  * Call this when process.cwd() changes between strategy iterations
23738
23754
  * so a new instance is created with the updated base path.
23739
23755
  */
@@ -23749,8 +23765,16 @@ declare class StorageBacktestAdapter implements IStorageUtils {
23749
23765
  * - Convenience methods: usePersist(), useMemory(), useDummy()
23750
23766
  */
23751
23767
  declare class StorageLiveAdapter implements IStorageUtils {
23752
- /** Internal storage utils instance */
23753
- private _signalLiveUtils;
23768
+ /** Factory producing the active storage utils instance */
23769
+ private _signalLiveFactory;
23770
+ /**
23771
+ * Lazily constructs the storage utils from the registered factory and memoizes
23772
+ * the result via `singleshot`.
23773
+ *
23774
+ * The instance is built on the first call and cached for all subsequent calls.
23775
+ * Reset via `clear()` so the next call rebuilds from the current factory.
23776
+ */
23777
+ private getInstance;
23754
23778
  /**
23755
23779
  * Handles signal opened event.
23756
23780
  * Proxies call to the underlying storage adapter.
@@ -23813,7 +23837,7 @@ declare class StorageLiveAdapter implements IStorageUtils {
23813
23837
  */
23814
23838
  useMemory: () => void;
23815
23839
  /**
23816
- * Clears the cached utils instance by resetting to the default persistent adapter.
23840
+ * Clears the memoized utils instance.
23817
23841
  * Call this when process.cwd() changes between strategy iterations
23818
23842
  * so a new instance is created with the updated base path.
23819
23843
  */
@@ -23931,8 +23955,16 @@ type TRecentUtilsCtor = new () => IRecentUtils;
23931
23955
  * - Convenience methods: usePersist(), useMemory()
23932
23956
  */
23933
23957
  declare class RecentBacktestAdapter implements IRecentUtils {
23934
- /** Internal storage utils instance */
23935
- private _recentBacktestUtils;
23958
+ /** Factory producing the active storage utils instance */
23959
+ private _recentBacktestFactory;
23960
+ /**
23961
+ * Lazily constructs the storage utils from the registered factory and memoizes
23962
+ * the result via `singleshot`.
23963
+ *
23964
+ * The instance is built on the first call and cached for all subsequent calls.
23965
+ * Reset via `clear()` so the next call rebuilds from the current factory.
23966
+ */
23967
+ private getInstance;
23936
23968
  /**
23937
23969
  * Handles active ping event.
23938
23970
  * Proxies call to the underlying storage adapter.
@@ -23982,7 +24014,9 @@ declare class RecentBacktestAdapter implements IRecentUtils {
23982
24014
  */
23983
24015
  useMemory: () => void;
23984
24016
  /**
23985
- * Clears the cached utils instance by resetting to the default in-memory adapter.
24017
+ * Clears the memoized utils instance.
24018
+ * Call this when process.cwd() changes between strategy iterations
24019
+ * so a new instance is created with the updated base path.
23986
24020
  */
23987
24021
  clear: () => void;
23988
24022
  }
@@ -23996,8 +24030,16 @@ declare class RecentBacktestAdapter implements IRecentUtils {
23996
24030
  * - Convenience methods: usePersist(), useMemory()
23997
24031
  */
23998
24032
  declare class RecentLiveAdapter implements IRecentUtils {
23999
- /** Internal storage utils instance */
24000
- private _recentLiveUtils;
24033
+ /** Factory producing the active storage utils instance */
24034
+ private _recentLiveFactory;
24035
+ /**
24036
+ * Lazily constructs the storage utils from the registered factory and memoizes
24037
+ * the result via `singleshot`.
24038
+ *
24039
+ * The instance is built on the first call and cached for all subsequent calls.
24040
+ * Reset via `clear()` so the next call rebuilds from the current factory.
24041
+ */
24042
+ private getInstance;
24001
24043
  /**
24002
24044
  * Handles active ping event.
24003
24045
  * Proxies call to the underlying storage adapter.
@@ -24047,7 +24089,9 @@ declare class RecentLiveAdapter implements IRecentUtils {
24047
24089
  */
24048
24090
  useMemory: () => void;
24049
24091
  /**
24050
- * Clears the cached utils instance by resetting to the default persistent adapter.
24092
+ * Clears the memoized utils instance.
24093
+ * Call this when process.cwd() changes between strategy iterations
24094
+ * so a new instance is created with the updated base path.
24051
24095
  */
24052
24096
  clear: () => void;
24053
24097
  }
@@ -24293,8 +24337,16 @@ type TNotificationUtilsCtor = new () => INotificationUtils;
24293
24337
  * - Convenience methods: usePersist(), useMemory(), useDummy()
24294
24338
  */
24295
24339
  declare class NotificationBacktestAdapter implements INotificationUtils {
24296
- /** Internal notification utils instance */
24297
- private _notificationBacktestUtils;
24340
+ /** Factory producing the active notification utils instance */
24341
+ private _notificationBacktestFactory;
24342
+ /**
24343
+ * Lazily constructs the notification utils from the registered factory and
24344
+ * memoizes the result via `singleshot`.
24345
+ *
24346
+ * The instance is built on the first call and cached for all subsequent calls.
24347
+ * Reset via `clear()` so the next call rebuilds from the current factory.
24348
+ */
24349
+ private getInstance;
24298
24350
  /**
24299
24351
  * Handles signal events.
24300
24352
  * Proxies call to the underlying notification adapter.
@@ -24390,7 +24442,7 @@ declare class NotificationBacktestAdapter implements INotificationUtils {
24390
24442
  */
24391
24443
  usePersist: () => void;
24392
24444
  /**
24393
- * Resets the cached utils instance to the default in-memory adapter.
24445
+ * Clears the memoized utils instance.
24394
24446
  * Call this when process.cwd() changes between strategy iterations
24395
24447
  * so a new instance is created with the updated base path.
24396
24448
  */
@@ -24406,8 +24458,16 @@ declare class NotificationBacktestAdapter implements INotificationUtils {
24406
24458
  * - Convenience methods: usePersist(), useMemory(), useDummy()
24407
24459
  */
24408
24460
  declare class NotificationLiveAdapter implements INotificationUtils {
24409
- /** Internal notification utils instance */
24410
- private _notificationLiveUtils;
24461
+ /** Factory producing the active notification utils instance */
24462
+ private _notificationLiveFactory;
24463
+ /**
24464
+ * Lazily constructs the notification utils from the registered factory and
24465
+ * memoizes the result via `singleshot`.
24466
+ *
24467
+ * The instance is built on the first call and cached for all subsequent calls.
24468
+ * Reset via `clear()` so the next call rebuilds from the current factory.
24469
+ */
24470
+ private getInstance;
24411
24471
  /**
24412
24472
  * Handles signal events.
24413
24473
  * Proxies call to the underlying notification adapter.
@@ -24503,7 +24563,7 @@ declare class NotificationLiveAdapter implements INotificationUtils {
24503
24563
  */
24504
24564
  usePersist: () => void;
24505
24565
  /**
24506
- * Resets the cached utils instance to the default in-memory adapter.
24566
+ * Clears the memoized utils instance.
24507
24567
  * Call this when process.cwd() changes between strategy iterations
24508
24568
  * so a new instance is created with the updated base path.
24509
24569
  */
@@ -27477,7 +27537,19 @@ type TBrokerCtor = new () => Partial<IBroker>;
27477
27537
  * ```
27478
27538
  */
27479
27539
  declare class BrokerAdapter {
27480
- private _brokerInstance;
27540
+ /** Factory producing the active `BrokerProxy` instance */
27541
+ private _brokerFactory;
27542
+ /**
27543
+ * Lazily constructs the `BrokerProxy` from the registered factory and
27544
+ * memoizes the result via `singleshot`.
27545
+ *
27546
+ * The proxy is built on the first call and cached for all subsequent calls.
27547
+ * Returns `null` when no adapter has been registered via `useBrokerAdapter()`.
27548
+ *
27549
+ * Reset via `clear()` so the next call rebuilds from the current factory
27550
+ * (e.g. when `process.cwd()` changes between strategy iterations).
27551
+ */
27552
+ private getInstance;
27481
27553
  /**
27482
27554
  * Forwards a signal-open event to the registered broker adapter.
27483
27555
  *