@tradejs/core 1.0.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/README.md +60 -0
- package/dist/api.d.mts +7 -0
- package/dist/api.d.ts +7 -0
- package/dist/api.js +64 -0
- package/dist/api.mjs +39 -0
- package/dist/async.d.mts +4 -0
- package/dist/async.d.ts +4 -0
- package/dist/async.js +48 -0
- package/dist/async.mjs +20 -0
- package/dist/backtest.d.mts +45 -0
- package/dist/backtest.d.ts +45 -0
- package/dist/backtest.js +574 -0
- package/dist/backtest.mjs +355 -0
- package/dist/chunk-AYC2QVKI.mjs +35 -0
- package/dist/chunk-JG2QPVAV.mjs +190 -0
- package/dist/chunk-LIGD3WWX.mjs +1545 -0
- package/dist/chunk-M7QGVZ3J.mjs +61 -0
- package/dist/chunk-NQ7D3T4E.mjs +10 -0
- package/dist/chunk-PXLXXXLA.mjs +67 -0
- package/dist/config.d.mts +14 -0
- package/dist/config.d.ts +14 -0
- package/dist/config.js +49 -0
- package/dist/config.mjs +21 -0
- package/dist/constants.d.mts +41 -0
- package/dist/constants.d.ts +41 -0
- package/dist/constants.js +238 -0
- package/dist/constants.mjs +50 -0
- package/dist/data.d.mts +9 -0
- package/dist/data.d.ts +9 -0
- package/dist/data.js +100 -0
- package/dist/data.mjs +12 -0
- package/dist/figures.d.mts +103 -0
- package/dist/figures.d.ts +103 -0
- package/dist/figures.js +274 -0
- package/dist/figures.mjs +239 -0
- package/dist/indicators-x3xKl3_W.d.mts +90 -0
- package/dist/indicators-x3xKl3_W.d.ts +90 -0
- package/dist/indicators.d.mts +124 -0
- package/dist/indicators.d.ts +124 -0
- package/dist/indicators.js +1631 -0
- package/dist/indicators.mjs +66 -0
- package/dist/json.d.mts +3 -0
- package/dist/json.d.ts +3 -0
- package/dist/json.js +34 -0
- package/dist/json.mjs +7 -0
- package/dist/math.d.mts +35 -0
- package/dist/math.d.ts +35 -0
- package/dist/math.js +98 -0
- package/dist/math.mjs +38 -0
- package/dist/pine.d.mts +29 -0
- package/dist/pine.d.ts +29 -0
- package/dist/pine.js +59 -0
- package/dist/pine.mjs +29 -0
- package/dist/strategies.d.mts +104 -0
- package/dist/strategies.d.ts +104 -0
- package/dist/strategies.js +1080 -0
- package/dist/strategies.mjs +390 -0
- package/dist/tickers.d.mts +7 -0
- package/dist/tickers.d.ts +7 -0
- package/dist/tickers.js +166 -0
- package/dist/tickers.mjs +125 -0
- package/dist/time-DEyFa2vI.d.mts +11 -0
- package/dist/time-DEyFa2vI.d.ts +11 -0
- package/dist/time.d.mts +2 -0
- package/dist/time.d.ts +2 -0
- package/dist/time.js +58 -0
- package/dist/time.mjs +15 -0
- package/package.json +99 -0
package/README.md
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# @tradejs/core
|
|
2
|
+
|
|
3
|
+
Browser-safe TradeJS public API for config, strategy authoring helpers, indicators, figures, math, and shared utilities.
|
|
4
|
+
|
|
5
|
+
- Homepage: https://tradejs.dev
|
|
6
|
+
- Documentation: https://docs.tradejs.dev
|
|
7
|
+
- Quickstart: https://docs.tradejs.dev/getting-started/quickstart
|
|
8
|
+
- Core API docs: https://docs.tradejs.dev/api/framework
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm i @tradejs/core @tradejs/types
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Add `@tradejs/node` when you need server/runtime execution helpers.
|
|
17
|
+
|
|
18
|
+
## Public Surface
|
|
19
|
+
|
|
20
|
+
Import only explicit public subpaths:
|
|
21
|
+
|
|
22
|
+
- `@tradejs/core/config`
|
|
23
|
+
- `@tradejs/core/strategies`
|
|
24
|
+
- `@tradejs/core/indicators`
|
|
25
|
+
- `@tradejs/core/backtest`
|
|
26
|
+
- `@tradejs/core/math`
|
|
27
|
+
- `@tradejs/core/time`
|
|
28
|
+
- `@tradejs/core/api`
|
|
29
|
+
- `@tradejs/core/figures`
|
|
30
|
+
- `@tradejs/core/constants`
|
|
31
|
+
- `@tradejs/core/data`
|
|
32
|
+
- `@tradejs/core/json`
|
|
33
|
+
- `@tradejs/core/async`
|
|
34
|
+
- `@tradejs/core/pine`
|
|
35
|
+
- `@tradejs/core/tickers`
|
|
36
|
+
|
|
37
|
+
There is no root `@tradejs/core` import surface.
|
|
38
|
+
|
|
39
|
+
## Minimal Example
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
import { defineConfig } from '@tradejs/core/config';
|
|
43
|
+
import { basePreset } from '@tradejs/base';
|
|
44
|
+
|
|
45
|
+
export default defineConfig(basePreset, {
|
|
46
|
+
strategies: ['@your-scope/tradejs-strategies'],
|
|
47
|
+
indicators: ['@your-scope/tradejs-indicators'],
|
|
48
|
+
connectors: ['@your-scope/tradejs-connectors'],
|
|
49
|
+
});
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Import Rules
|
|
53
|
+
|
|
54
|
+
- import plugin/config helpers from `@tradejs/core/config`
|
|
55
|
+
- import browser-safe authoring helpers from explicit `@tradejs/core/*` subpaths
|
|
56
|
+
- import shared contracts from `@tradejs/types`
|
|
57
|
+
- do not use internal aliases like `@utils` / `@constants`
|
|
58
|
+
- do not use non-public deep imports like `@tradejs/core/src/*`
|
|
59
|
+
|
|
60
|
+
For runtime execution, Pine loading, plugin registries, and backtest orchestration, use `@tradejs/node`.
|
package/dist/api.d.mts
ADDED
package/dist/api.d.ts
ADDED
package/dist/api.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/api.ts
|
|
21
|
+
var api_exports = {};
|
|
22
|
+
__export(api_exports, {
|
|
23
|
+
API: () => API
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(api_exports);
|
|
26
|
+
var handleResponse = async (response) => {
|
|
27
|
+
if (!response.ok) {
|
|
28
|
+
const text = await response.text();
|
|
29
|
+
throw new Error(text || "API request failed");
|
|
30
|
+
}
|
|
31
|
+
return response.json();
|
|
32
|
+
};
|
|
33
|
+
var get = async (url) => {
|
|
34
|
+
const response = await fetch(url, {
|
|
35
|
+
method: "GET",
|
|
36
|
+
cache: "no-store"
|
|
37
|
+
});
|
|
38
|
+
return handleResponse(response);
|
|
39
|
+
};
|
|
40
|
+
var post = async (url, body) => {
|
|
41
|
+
const response = await fetch(url, {
|
|
42
|
+
method: "POST",
|
|
43
|
+
headers: {
|
|
44
|
+
"Content-Type": "application/json"
|
|
45
|
+
},
|
|
46
|
+
body: JSON.stringify(body)
|
|
47
|
+
});
|
|
48
|
+
return handleResponse(response);
|
|
49
|
+
};
|
|
50
|
+
var remove = async (url) => {
|
|
51
|
+
const response = await fetch(url, {
|
|
52
|
+
method: "DELETE"
|
|
53
|
+
});
|
|
54
|
+
return handleResponse(response);
|
|
55
|
+
};
|
|
56
|
+
var API = {
|
|
57
|
+
get,
|
|
58
|
+
post,
|
|
59
|
+
delete: remove
|
|
60
|
+
};
|
|
61
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
62
|
+
0 && (module.exports = {
|
|
63
|
+
API
|
|
64
|
+
});
|
package/dist/api.mjs
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// src/api.ts
|
|
2
|
+
var handleResponse = async (response) => {
|
|
3
|
+
if (!response.ok) {
|
|
4
|
+
const text = await response.text();
|
|
5
|
+
throw new Error(text || "API request failed");
|
|
6
|
+
}
|
|
7
|
+
return response.json();
|
|
8
|
+
};
|
|
9
|
+
var get = async (url) => {
|
|
10
|
+
const response = await fetch(url, {
|
|
11
|
+
method: "GET",
|
|
12
|
+
cache: "no-store"
|
|
13
|
+
});
|
|
14
|
+
return handleResponse(response);
|
|
15
|
+
};
|
|
16
|
+
var post = async (url, body) => {
|
|
17
|
+
const response = await fetch(url, {
|
|
18
|
+
method: "POST",
|
|
19
|
+
headers: {
|
|
20
|
+
"Content-Type": "application/json"
|
|
21
|
+
},
|
|
22
|
+
body: JSON.stringify(body)
|
|
23
|
+
});
|
|
24
|
+
return handleResponse(response);
|
|
25
|
+
};
|
|
26
|
+
var remove = async (url) => {
|
|
27
|
+
const response = await fetch(url, {
|
|
28
|
+
method: "DELETE"
|
|
29
|
+
});
|
|
30
|
+
return handleResponse(response);
|
|
31
|
+
};
|
|
32
|
+
var API = {
|
|
33
|
+
get,
|
|
34
|
+
post,
|
|
35
|
+
delete: remove
|
|
36
|
+
};
|
|
37
|
+
export {
|
|
38
|
+
API
|
|
39
|
+
};
|
package/dist/async.d.mts
ADDED
package/dist/async.d.ts
ADDED
package/dist/async.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/async.ts
|
|
21
|
+
var async_exports = {};
|
|
22
|
+
__export(async_exports, {
|
|
23
|
+
delay: () => delay,
|
|
24
|
+
runWithConcurrency: () => runWithConcurrency
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(async_exports);
|
|
27
|
+
|
|
28
|
+
// src/utils/async.ts
|
|
29
|
+
var runWithConcurrency = async (items, concurrency, workerFn) => {
|
|
30
|
+
const queue = items.slice();
|
|
31
|
+
const worker = async () => {
|
|
32
|
+
while (queue.length > 0) {
|
|
33
|
+
const item = queue.shift();
|
|
34
|
+
const index = items.length - queue.length - 1;
|
|
35
|
+
await workerFn(item, index);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
const workers = Array.from({ length: concurrency }, worker);
|
|
39
|
+
await Promise.all(workers);
|
|
40
|
+
};
|
|
41
|
+
var delay = async (delayMs = 1e3) => {
|
|
42
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
43
|
+
};
|
|
44
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
45
|
+
0 && (module.exports = {
|
|
46
|
+
delay,
|
|
47
|
+
runWithConcurrency
|
|
48
|
+
});
|
package/dist/async.mjs
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// src/utils/async.ts
|
|
2
|
+
var runWithConcurrency = async (items, concurrency, workerFn) => {
|
|
3
|
+
const queue = items.slice();
|
|
4
|
+
const worker = async () => {
|
|
5
|
+
while (queue.length > 0) {
|
|
6
|
+
const item = queue.shift();
|
|
7
|
+
const index = items.length - queue.length - 1;
|
|
8
|
+
await workerFn(item, index);
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
const workers = Array.from({ length: concurrency }, worker);
|
|
12
|
+
await Promise.all(workers);
|
|
13
|
+
};
|
|
14
|
+
var delay = async (delayMs = 1e3) => {
|
|
15
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
16
|
+
};
|
|
17
|
+
export {
|
|
18
|
+
delay,
|
|
19
|
+
runWithConcurrency
|
|
20
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { StrategyConfigGrid, TestSuite, StrategyConfig, PositionLogData, TestStat, TestThresholdsKey, ThresholdLevel, TestWorkerResult } from '@tradejs/types';
|
|
2
|
+
export { c as compactOrderLog, g as getTimeline } from './time-DEyFa2vI.mjs';
|
|
3
|
+
|
|
4
|
+
type GenericConfig = StrategyConfig;
|
|
5
|
+
declare const generateParamGrid: <T extends StrategyConfig>(paramOptions: StrategyConfigGrid) => T[];
|
|
6
|
+
declare const generateName: (prefix: string) => string;
|
|
7
|
+
declare const mergeConfigs: (configs: GenericConfig[]) => Record<string, unknown[]>;
|
|
8
|
+
declare const createTestSuite: (userName: string, tickers: string[], strategyName: string, backtestConfig: StrategyConfigGrid, connectorName: string) => TestSuite;
|
|
9
|
+
|
|
10
|
+
declare const parseTestName: (testName: string) => {
|
|
11
|
+
symbol: string;
|
|
12
|
+
testSuiteId: string;
|
|
13
|
+
testId: string;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Максимальная просадка (Max Drawdown) в процентах от бегающего пика.
|
|
18
|
+
* Формула по точкам amount_t:
|
|
19
|
+
* peak_t = max(amount_0..t)
|
|
20
|
+
* drawdown_t = (peak_t - amount_t) / peak_t * 100
|
|
21
|
+
* MaxDD = max_t(drawdown_t)
|
|
22
|
+
* Ожидается, что amounts — это последовательные значения equity и > 0.
|
|
23
|
+
*/
|
|
24
|
+
declare const calculateMaxDrawdown: (amounts: number[]) => number;
|
|
25
|
+
/**
|
|
26
|
+
* Рассчитывает компактный набор действительно полезных метрик:
|
|
27
|
+
* - Период и частота (periodDays/Months, trades, tradesPerMonth, exposure)
|
|
28
|
+
* - Доходность (final amount, netProfit, totalReturn %, CAGR %)
|
|
29
|
+
* - Риск (MaxDD %) и Calmar (CAGR / MaxDD)
|
|
30
|
+
* - Качество сделок (winRate %, payoff, expectancyPerTrade %, streaks)
|
|
31
|
+
* - Sharpe (годовой) — по месячным ретёрнам equity (EOM)
|
|
32
|
+
*
|
|
33
|
+
* Возвратные проценты (totalReturn, cagr, exposure, maxDrawdown, expectancyPerTrade) — уже в %.
|
|
34
|
+
* Шарп — безразмерная величина (annualized).
|
|
35
|
+
*/
|
|
36
|
+
declare const calculateStatsFull: (positionLogData: PositionLogData) => TestStat | null;
|
|
37
|
+
declare const classifyMetric: (name: TestThresholdsKey, value: number) => ThresholdLevel;
|
|
38
|
+
declare const getBacktestScore: (stat: Partial<TestStat>) => number;
|
|
39
|
+
declare const sortBestTests: (results: TestWorkerResult[], limit?: number) => TestWorkerResult[];
|
|
40
|
+
declare const getFormatted: (stat: Partial<TestStat> | undefined, key: TestThresholdsKey) => {
|
|
41
|
+
formatted: string;
|
|
42
|
+
level: ThresholdLevel;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export { calculateMaxDrawdown, calculateStatsFull, classifyMetric, createTestSuite, generateName, generateParamGrid, getBacktestScore, getFormatted, mergeConfigs, parseTestName, sortBestTests };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { StrategyConfigGrid, TestSuite, StrategyConfig, PositionLogData, TestStat, TestThresholdsKey, ThresholdLevel, TestWorkerResult } from '@tradejs/types';
|
|
2
|
+
export { c as compactOrderLog, g as getTimeline } from './time-DEyFa2vI.js';
|
|
3
|
+
|
|
4
|
+
type GenericConfig = StrategyConfig;
|
|
5
|
+
declare const generateParamGrid: <T extends StrategyConfig>(paramOptions: StrategyConfigGrid) => T[];
|
|
6
|
+
declare const generateName: (prefix: string) => string;
|
|
7
|
+
declare const mergeConfigs: (configs: GenericConfig[]) => Record<string, unknown[]>;
|
|
8
|
+
declare const createTestSuite: (userName: string, tickers: string[], strategyName: string, backtestConfig: StrategyConfigGrid, connectorName: string) => TestSuite;
|
|
9
|
+
|
|
10
|
+
declare const parseTestName: (testName: string) => {
|
|
11
|
+
symbol: string;
|
|
12
|
+
testSuiteId: string;
|
|
13
|
+
testId: string;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Максимальная просадка (Max Drawdown) в процентах от бегающего пика.
|
|
18
|
+
* Формула по точкам amount_t:
|
|
19
|
+
* peak_t = max(amount_0..t)
|
|
20
|
+
* drawdown_t = (peak_t - amount_t) / peak_t * 100
|
|
21
|
+
* MaxDD = max_t(drawdown_t)
|
|
22
|
+
* Ожидается, что amounts — это последовательные значения equity и > 0.
|
|
23
|
+
*/
|
|
24
|
+
declare const calculateMaxDrawdown: (amounts: number[]) => number;
|
|
25
|
+
/**
|
|
26
|
+
* Рассчитывает компактный набор действительно полезных метрик:
|
|
27
|
+
* - Период и частота (periodDays/Months, trades, tradesPerMonth, exposure)
|
|
28
|
+
* - Доходность (final amount, netProfit, totalReturn %, CAGR %)
|
|
29
|
+
* - Риск (MaxDD %) и Calmar (CAGR / MaxDD)
|
|
30
|
+
* - Качество сделок (winRate %, payoff, expectancyPerTrade %, streaks)
|
|
31
|
+
* - Sharpe (годовой) — по месячным ретёрнам equity (EOM)
|
|
32
|
+
*
|
|
33
|
+
* Возвратные проценты (totalReturn, cagr, exposure, maxDrawdown, expectancyPerTrade) — уже в %.
|
|
34
|
+
* Шарп — безразмерная величина (annualized).
|
|
35
|
+
*/
|
|
36
|
+
declare const calculateStatsFull: (positionLogData: PositionLogData) => TestStat | null;
|
|
37
|
+
declare const classifyMetric: (name: TestThresholdsKey, value: number) => ThresholdLevel;
|
|
38
|
+
declare const getBacktestScore: (stat: Partial<TestStat>) => number;
|
|
39
|
+
declare const sortBestTests: (results: TestWorkerResult[], limit?: number) => TestWorkerResult[];
|
|
40
|
+
declare const getFormatted: (stat: Partial<TestStat> | undefined, key: TestThresholdsKey) => {
|
|
41
|
+
formatted: string;
|
|
42
|
+
level: ThresholdLevel;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export { calculateMaxDrawdown, calculateStatsFull, classifyMetric, createTestSuite, generateName, generateParamGrid, getBacktestScore, getFormatted, mergeConfigs, parseTestName, sortBestTests };
|