oakscriptjs 0.15.3 → 0.16.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/dist/cjs/check/format.d.ts.map +1 -1
- package/dist/cjs/check/format.js +5 -0
- package/dist/cjs/check/format.js.map +2 -2
- package/dist/cjs/check/harness.d.ts +24 -0
- package/dist/cjs/check/harness.d.ts.map +1 -1
- package/dist/cjs/check/harness.js +33 -0
- package/dist/cjs/check/harness.js.map +2 -2
- package/dist/cjs/check/index.d.ts +9 -0
- package/dist/cjs/check/index.d.ts.map +1 -1
- package/dist/cjs/check/index.js +7 -0
- package/dist/cjs/check/index.js.map +2 -2
- package/dist/cjs/color/index.d.ts.map +1 -1
- package/dist/cjs/color/index.js +19 -2
- package/dist/cjs/color/index.js.map +2 -2
- package/dist/cjs/color/parse.d.ts +8 -6
- package/dist/cjs/color/parse.d.ts.map +1 -1
- package/dist/cjs/color/parse.js +15 -2
- package/dist/cjs/color/parse.js.map +2 -2
- package/dist/cjs/drawing/registry.d.ts +68 -0
- package/dist/cjs/drawing/registry.d.ts.map +1 -1
- package/dist/cjs/drawing/registry.js +99 -9
- package/dist/cjs/drawing/registry.js.map +2 -2
- package/dist/cjs/index.d.ts +3 -2
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +5 -1
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/runtime/series.d.ts +16 -0
- package/dist/cjs/runtime/series.d.ts.map +1 -1
- package/dist/cjs/runtime/series.js +19 -2
- package/dist/cjs/runtime/series.js.map +2 -2
- package/dist/cjs/script/closure-writes.d.ts +16 -0
- package/dist/cjs/script/closure-writes.d.ts.map +1 -0
- package/dist/cjs/script/closure-writes.js +435 -0
- package/dist/cjs/script/closure-writes.js.map +7 -0
- package/dist/cjs/script/globals.d.ts +2 -0
- package/dist/cjs/script/globals.d.ts.map +1 -1
- package/dist/cjs/script/globals.js.map +1 -1
- package/dist/cjs/script/incremental.d.ts +140 -0
- package/dist/cjs/script/incremental.d.ts.map +1 -0
- package/dist/cjs/script/incremental.js +142 -0
- package/dist/cjs/script/incremental.js.map +7 -0
- package/dist/cjs/script/index.d.ts +116 -31
- package/dist/cjs/script/index.d.ts.map +1 -1
- package/dist/cjs/script/index.js +471 -25
- package/dist/cjs/script/index.js.map +3 -3
- package/dist/cjs/str/numberformat.d.ts.map +1 -1
- package/dist/cjs/str/numberformat.js +23 -0
- package/dist/cjs/str/numberformat.js.map +2 -2
- package/dist/cjs/strategy/index.d.ts +8 -0
- package/dist/cjs/strategy/index.d.ts.map +1 -1
- package/dist/cjs/strategy/index.js.map +1 -1
- package/dist/cjs/ta/running-sum.d.ts.map +1 -1
- package/dist/cjs/ta/running-sum.js +72 -3
- package/dist/cjs/ta/running-sum.js.map +2 -2
- package/dist/cjs/ta/step.d.ts +476 -0
- package/dist/cjs/ta/step.d.ts.map +1 -0
- package/dist/cjs/ta/step.js +1000 -0
- package/dist/cjs/ta/step.js.map +7 -0
- package/dist/cjs/ta-series.d.ts +1 -1
- package/dist/cjs/ta-series.js +3 -3
- package/dist/cjs/ta-series.js.map +1 -1
- package/dist/esm/check/format.d.ts.map +1 -1
- package/dist/esm/check/format.js +5 -0
- package/dist/esm/check/format.js.map +1 -1
- package/dist/esm/check/harness.d.ts +24 -0
- package/dist/esm/check/harness.d.ts.map +1 -1
- package/dist/esm/check/harness.js +40 -6
- package/dist/esm/check/harness.js.map +1 -1
- package/dist/esm/check/index.d.ts +9 -0
- package/dist/esm/check/index.d.ts.map +1 -1
- package/dist/esm/check/index.js +11 -1
- package/dist/esm/check/index.js.map +1 -1
- package/dist/esm/color/index.d.ts.map +1 -1
- package/dist/esm/color/index.js +23 -3
- package/dist/esm/color/index.js.map +1 -1
- package/dist/esm/color/parse.d.ts +8 -6
- package/dist/esm/color/parse.d.ts.map +1 -1
- package/dist/esm/color/parse.js +19 -2
- package/dist/esm/color/parse.js.map +1 -1
- package/dist/esm/drawing/registry.d.ts +68 -0
- package/dist/esm/drawing/registry.d.ts.map +1 -1
- package/dist/esm/drawing/registry.js +156 -10
- package/dist/esm/drawing/registry.js.map +1 -1
- package/dist/esm/index.d.ts +3 -2
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +6 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/runtime/series.d.ts +16 -0
- package/dist/esm/runtime/series.d.ts.map +1 -1
- package/dist/esm/runtime/series.js +21 -1
- package/dist/esm/runtime/series.js.map +1 -1
- package/dist/esm/script/closure-writes.d.ts +16 -0
- package/dist/esm/script/closure-writes.d.ts.map +1 -0
- package/dist/esm/script/closure-writes.js +323 -0
- package/dist/esm/script/closure-writes.js.map +1 -0
- package/dist/esm/script/globals.d.ts +2 -0
- package/dist/esm/script/globals.d.ts.map +1 -1
- package/dist/esm/script/globals.js.map +1 -1
- package/dist/esm/script/incremental.d.ts +140 -0
- package/dist/esm/script/incremental.d.ts.map +1 -0
- package/dist/esm/script/incremental.js +173 -0
- package/dist/esm/script/incremental.js.map +1 -0
- package/dist/esm/script/index.d.ts +116 -31
- package/dist/esm/script/index.d.ts.map +1 -1
- package/dist/esm/script/index.js +561 -24
- package/dist/esm/script/index.js.map +1 -1
- package/dist/esm/str/numberformat.d.ts.map +1 -1
- package/dist/esm/str/numberformat.js +30 -0
- package/dist/esm/str/numberformat.js.map +1 -1
- package/dist/esm/strategy/index.d.ts +8 -0
- package/dist/esm/strategy/index.d.ts.map +1 -1
- package/dist/esm/ta/running-sum.d.ts.map +1 -1
- package/dist/esm/ta/running-sum.js +79 -4
- package/dist/esm/ta/running-sum.js.map +1 -1
- package/dist/esm/ta/step.d.ts +476 -0
- package/dist/esm/ta/step.d.ts.map +1 -0
- package/dist/esm/ta/step.js +1089 -0
- package/dist/esm/ta/step.js.map +1 -0
- package/dist/esm/ta-series.d.ts +1 -1
- package/dist/esm/ta-series.js +4 -4
- package/package.json +1 -1
- package/skills/oakscript/SKILL.md +2 -2
- package/skills/oakscript/reference/check.md +5 -0
- package/skills/oakscript/reference/errors.md +0 -1
- package/skills/oakscript/reference/pine-differences.md +1 -2
- package/skills/oakscript/reference/plotting.md +5 -7
- package/skills/oakscript/reference/script-structure.md +6 -0
- package/src/check/format.ts +7 -0
- package/src/check/harness.ts +57 -0
- package/src/check/index.ts +16 -0
- package/src/color/index.ts +22 -3
- package/src/color/parse.ts +28 -3
- package/src/drawing/registry.ts +172 -10
- package/src/index.ts +9 -2
- package/src/runtime/series.ts +33 -1
- package/src/script/closure-writes.ts +279 -0
- package/src/script/globals.ts +2 -0
- package/src/script/incremental.ts +246 -0
- package/src/script/index.ts +695 -26
- package/src/str/numberformat.ts +29 -0
- package/src/strategy/index.ts +8 -0
- package/src/ta/running-sum.ts +78 -3
- package/src/ta/step.ts +1145 -0
- package/src/ta-series.ts +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../../src/check/format.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAO9C,uGAAuG;AACvG,wBAAgB,YAAY,CAAC,CAAC,EAAE,WAAW,GAAG;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../../src/check/format.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAO9C,uGAAuG;AACvG,wBAAgB,YAAY,CAAC,CAAC,EAAE,WAAW,GAAG;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CA2F9F;AAED;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,WAAW,EAAE,OAAO,GAAE;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAO,GAAG,IAAI,CAM3F"}
|
package/dist/cjs/check/format.js
CHANGED
|
@@ -70,6 +70,11 @@ function formatReport(r) {
|
|
|
70
70
|
out.push("warnings:");
|
|
71
71
|
for (const w of r.warnings) out.push(` [${w.code}] ${w.message}`);
|
|
72
72
|
}
|
|
73
|
+
if (r.liveUpdates) {
|
|
74
|
+
out.push(
|
|
75
|
+
r.liveUpdates.resumed ? "live updates: resumed (the newest bars only)" : `live updates: full runs (same results, more time): ${r.liveUpdates.reason}`
|
|
76
|
+
);
|
|
77
|
+
}
|
|
73
78
|
if (r.spec) {
|
|
74
79
|
out.push(`spec and checks: ${r.spec.passed} passed, ${r.spec.failed} failed`);
|
|
75
80
|
for (const i of r.spec.items.filter((x) => !x.ok)) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/check/format.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * @fileoverview The check report as text (the output of `oakscript check`) and {@link assertCheck}, which throws it\n * from a test of any test runner.\n *\n * @module check/format\n */\nimport type { CheckReport } from './index.js';\n\nconst fmt = (v: number | null | undefined): string =>\n v === null || v === undefined ? 'na' : Number.isInteger(v) ? String(v) : Number(v.toPrecision(6)).toString();\n\nconst shown = (v: unknown): string => (v === undefined ? 'nothing' : JSON.stringify(v));\n\n/** The report as text, for a terminal or an agent. `file` and `typesSkipped` come from the command. */\nexport function formatReport(r: CheckReport & { file?: string; typesSkipped?: string }): string {\n const file = r.file ?? 'script';\n const out: string[] = [];\n out.push(`oakscript check ${file}: ${r.bars.count} ${r.bars.synthetic ? 'synthetic ' : ''}bars, timeframe ${r.bars.timeframe}`);\n const d = r.declaration;\n if (d) {\n out.push(`${d.kind} \"${d.title}\"${d.overlay ? ' (overlay)' : ' (own pane)'}`);\n if (d.inputs.length) {\n out.push('inputs:');\n for (const i of d.inputs) {\n const extra = [i.options ? `options ${i.options.join(' | ')}` : '', i.min !== undefined ? `min ${i.min}` : '', i.max !== undefined ? `max ${i.max}` : '']\n .filter(Boolean)\n .join(', ');\n out.push(` ${i.id} (${i.type}) = ${JSON.stringify(i.defval)}${i.title ? ` \"${i.title}\"` : ''}${extra ? ` ${extra}` : ''}`);\n }\n }\n }\n if (r.plots.length || r.signals.length) out.push('outputs:');\n for (const p of r.plots) {\n out.push(\n p.values\n ? ` plot \"${p.title}\": ${p.values} values from bar ${p.firstBar}, ${fmt(p.min)} .. ${fmt(p.max)}, last ${p.last.map(fmt).join(' ')}${p.colours ? `, ${p.colours} colours` : ''}`\n : ` plot \"${p.title}\": no value`\n );\n }\n for (const s of r.signals) {\n out.push(` ${s.kind.padEnd(6)} \"${s.title}\": ${s.count} bars (${(s.share * 100).toFixed(1)} %)${s.count ? `, first ${s.firstBar}, last ${s.lastBar}` : ''}`);\n }\n const dr = Object.entries(r.drawings).filter(([, n]) => n > 0);\n if (dr.length) out.push(`drawings: ${dr.map(([k, n]) => `${n} ${k}`).join(', ')}`);\n if (r.alertCalls) out.push(`alert() calls: ${r.alertCalls}`);\n if (r.strategy) {\n const s = r.strategy;\n out.push(`strategy: ${s.closedTrades} closed trades${s.openTrade ? ' + 1 open' : ''}, ${s.wins} wins, net profit ${fmt(s.netProfit)}`);\n for (const t of s.first) {\n out.push(` ${t.direction} \"${t.entry}\" bar ${t.entryBar} @ ${fmt(t.entryPrice)} -> bar ${t.exitBar ?? '-'} @ ${fmt(t.exitPrice)}: ${fmt(t.profit)}`);\n }\n }\n if (r.errors.length) {\n out.push('errors:');\n for (const e of r.errors) {\n const at = e.line ? `${file}:${e.line}${e.column ? `:${e.column}` : ''} ` : '';\n out.push(` ${at}[${e.stage}${e.code ? ` ${e.code}` : ''}] ${e.message}`);\n }\n }\n if (r.typesSkipped) out.push(`types: not checked (${r.typesSkipped})`);\n if (r.warnings.length) {\n out.push('warnings:');\n for (const w of r.warnings) out.push(` [${w.code}] ${w.message}`);\n }\n if (r.spec) {\n out.push(`spec and checks: ${r.spec.passed} passed, ${r.spec.failed} failed`);\n for (const i of r.spec.items.filter((x) => !x.ok)) {\n out.push(` FAIL ${i.check}${i.expected !== undefined ? `: expected ${shown(i.expected)}, got ${shown(i.actual)}` : i.actual !== undefined ? `: ${typeof i.actual === 'string' ? i.actual : shown(i.actual)}` : ''}`);\n }\n }\n for (const c of r.reference ?? []) {\n const m = c.firstMismatch;\n out.push(\n c.ignored\n ? `reference \"${c.column}\": ignored (no plot with this id or title)`\n : c.output === undefined\n ? `reference \"${c.column}\": FAIL no plot with this id or title`\n : `reference \"${c.column}\": ${c.equal} / ${c.total} bars equal${m ? `, first difference on bar ${m.bar}: expected ${fmt(m.expected)}, got ${fmt(m.actual)}` : ''}`\n );\n }\n if (r.scenarios) {\n out.push('scenarios:');\n for (const s of r.scenarios) {\n const notes = [...s.errors.map((e) => `ERROR ${e.message}`), ...s.warnings.map((w) => `[${w.code}] ${w.message}`)];\n out.push(` ${s.name} (${s.description}): ${notes.length ? '' : 'ok'}`);\n for (const n of notes) out.push(` ${n}`);\n }\n }\n const failed =\n (r.spec?.failed ?? 0) + (r.reference ?? []).filter((c) => !c.ignored && (c.equal !== c.total || c.output === undefined)).length;\n out.push(\n r.ok\n ? r.warnings.length\n ? `result: OK with ${r.warnings.length} warning(s)`\n : 'result: OK'\n : `result: FAIL (${r.errors.length} error(s), ${failed} failed check(s), ${r.warnings.length} warning(s))`\n );\n return out.join('\\n');\n}\n\n/**\n * Throws the report as text when the check failed (an error, a failed spec item, check or reference column), or with\n * `{ warnings: false }` when it has warnings. For the tests of a project:\n *\n * ```ts\n * it('my indicator follows its spec', () => {\n * assertCheck(checkScript(source, { spec, checks: (t) => { ... } }));\n * });\n * ```\n */\nexport function assertCheck(report: CheckReport, options: { warnings?: boolean } = {}): void {\n if (!report.ok || (options.warnings === false && report.warnings.length > 0)) {\n const error = new Error(formatReport(report));\n error.name = 'CheckError';\n throw error;\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;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AK,MAAM,EAAE,KAAK,cAAc,IAAI,6BAA6B,EAAE,GAAG,cAAc,IAAI,EAAE,QAAQ,CAAC,SAAS,IAAI,EAAE,MAAM,CAAC,KAAK,EAAE;AAAA,IACtK;AAAA,EACF;AACA,MAAI,EAAE,WAAW;AACf,QAAI,KAAK,YAAY;AACrB,eAAW,KAAK,EAAE,WAAW;AAC3B,YAAM,QAAQ,CAAC,GAAG,EAAE,OAAO,IAAI,CAAC,MAAM,SAAS,EAAE,OAAO,EAAE,GAAG,GAAG,EAAE,SAAS,IAAI,CAAC,MAAM,IAAI,EAAE,IAAI,KAAK,EAAE,OAAO,EAAE,CAAC;AACjH,UAAI,KAAK,KAAK,EAAE,IAAI,KAAK,EAAE,WAAW,MAAM,MAAM,SAAS,KAAK,IAAI,EAAE;AACtE,iBAAW,KAAK,MAAO,KAAI,KAAK,OAAO,CAAC,EAAE;AAAA,IAC5C;AAAA,EACF;AACA,QAAM,UACH,EAAE,MAAM,UAAU,MAAM,EAAE,aAAa,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,EAAE,YAAY,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,OAAU,EAAE;AAC3H,MAAI;AAAA,IACF,EAAE,KACE,EAAE,SAAS,SACT,mBAAmB,EAAE,SAAS,MAAM,gBACpC,eACF,iBAAiB,EAAE,OAAO,MAAM,cAAc,MAAM,qBAAqB,EAAE,SAAS,MAAM;AAAA,EAChG;AACA,SAAO,IAAI,KAAK,IAAI;AACtB;AAYO,SAAS,YAAY,QAAqB,UAAkC,CAAC,GAAS;AAC3F,MAAI,CAAC,OAAO,MAAO,QAAQ,aAAa,SAAS,OAAO,SAAS,SAAS,GAAI;AAC5E,UAAM,QAAQ,IAAI,MAAM,aAAa,MAAM,CAAC;AAC5C,UAAM,OAAO;AACb,UAAM;AAAA,EACR;AACF;",
|
|
4
|
+
"sourcesContent": ["/**\n * @fileoverview The check report as text (the output of `oakscript check`) and {@link assertCheck}, which throws it\n * from a test of any test runner.\n *\n * @module check/format\n */\nimport type { CheckReport } from './index.js';\n\nconst fmt = (v: number | null | undefined): string =>\n v === null || v === undefined ? 'na' : Number.isInteger(v) ? String(v) : Number(v.toPrecision(6)).toString();\n\nconst shown = (v: unknown): string => (v === undefined ? 'nothing' : JSON.stringify(v));\n\n/** The report as text, for a terminal or an agent. `file` and `typesSkipped` come from the command. */\nexport function formatReport(r: CheckReport & { file?: string; typesSkipped?: string }): string {\n const file = r.file ?? 'script';\n const out: string[] = [];\n out.push(`oakscript check ${file}: ${r.bars.count} ${r.bars.synthetic ? 'synthetic ' : ''}bars, timeframe ${r.bars.timeframe}`);\n const d = r.declaration;\n if (d) {\n out.push(`${d.kind} \"${d.title}\"${d.overlay ? ' (overlay)' : ' (own pane)'}`);\n if (d.inputs.length) {\n out.push('inputs:');\n for (const i of d.inputs) {\n const extra = [i.options ? `options ${i.options.join(' | ')}` : '', i.min !== undefined ? `min ${i.min}` : '', i.max !== undefined ? `max ${i.max}` : '']\n .filter(Boolean)\n .join(', ');\n out.push(` ${i.id} (${i.type}) = ${JSON.stringify(i.defval)}${i.title ? ` \"${i.title}\"` : ''}${extra ? ` ${extra}` : ''}`);\n }\n }\n }\n if (r.plots.length || r.signals.length) out.push('outputs:');\n for (const p of r.plots) {\n out.push(\n p.values\n ? ` plot \"${p.title}\": ${p.values} values from bar ${p.firstBar}, ${fmt(p.min)} .. ${fmt(p.max)}, last ${p.last.map(fmt).join(' ')}${p.colours ? `, ${p.colours} colours` : ''}`\n : ` plot \"${p.title}\": no value`\n );\n }\n for (const s of r.signals) {\n out.push(` ${s.kind.padEnd(6)} \"${s.title}\": ${s.count} bars (${(s.share * 100).toFixed(1)} %)${s.count ? `, first ${s.firstBar}, last ${s.lastBar}` : ''}`);\n }\n const dr = Object.entries(r.drawings).filter(([, n]) => n > 0);\n if (dr.length) out.push(`drawings: ${dr.map(([k, n]) => `${n} ${k}`).join(', ')}`);\n if (r.alertCalls) out.push(`alert() calls: ${r.alertCalls}`);\n if (r.strategy) {\n const s = r.strategy;\n out.push(`strategy: ${s.closedTrades} closed trades${s.openTrade ? ' + 1 open' : ''}, ${s.wins} wins, net profit ${fmt(s.netProfit)}`);\n for (const t of s.first) {\n out.push(` ${t.direction} \"${t.entry}\" bar ${t.entryBar} @ ${fmt(t.entryPrice)} -> bar ${t.exitBar ?? '-'} @ ${fmt(t.exitPrice)}: ${fmt(t.profit)}`);\n }\n }\n if (r.errors.length) {\n out.push('errors:');\n for (const e of r.errors) {\n const at = e.line ? `${file}:${e.line}${e.column ? `:${e.column}` : ''} ` : '';\n out.push(` ${at}[${e.stage}${e.code ? ` ${e.code}` : ''}] ${e.message}`);\n }\n }\n if (r.typesSkipped) out.push(`types: not checked (${r.typesSkipped})`);\n if (r.warnings.length) {\n out.push('warnings:');\n for (const w of r.warnings) out.push(` [${w.code}] ${w.message}`);\n }\n if (r.liveUpdates) {\n out.push(\n r.liveUpdates.resumed\n ? 'live updates: resumed (the newest bars only)'\n : `live updates: full runs (same results, more time): ${r.liveUpdates.reason}`\n );\n }\n if (r.spec) {\n out.push(`spec and checks: ${r.spec.passed} passed, ${r.spec.failed} failed`);\n for (const i of r.spec.items.filter((x) => !x.ok)) {\n out.push(` FAIL ${i.check}${i.expected !== undefined ? `: expected ${shown(i.expected)}, got ${shown(i.actual)}` : i.actual !== undefined ? `: ${typeof i.actual === 'string' ? i.actual : shown(i.actual)}` : ''}`);\n }\n }\n for (const c of r.reference ?? []) {\n const m = c.firstMismatch;\n out.push(\n c.ignored\n ? `reference \"${c.column}\": ignored (no plot with this id or title)`\n : c.output === undefined\n ? `reference \"${c.column}\": FAIL no plot with this id or title`\n : `reference \"${c.column}\": ${c.equal} / ${c.total} bars equal${m ? `, first difference on bar ${m.bar}: expected ${fmt(m.expected)}, got ${fmt(m.actual)}` : ''}`\n );\n }\n if (r.scenarios) {\n out.push('scenarios:');\n for (const s of r.scenarios) {\n const notes = [...s.errors.map((e) => `ERROR ${e.message}`), ...s.warnings.map((w) => `[${w.code}] ${w.message}`)];\n out.push(` ${s.name} (${s.description}): ${notes.length ? '' : 'ok'}`);\n for (const n of notes) out.push(` ${n}`);\n }\n }\n const failed =\n (r.spec?.failed ?? 0) + (r.reference ?? []).filter((c) => !c.ignored && (c.equal !== c.total || c.output === undefined)).length;\n out.push(\n r.ok\n ? r.warnings.length\n ? `result: OK with ${r.warnings.length} warning(s)`\n : 'result: OK'\n : `result: FAIL (${r.errors.length} error(s), ${failed} failed check(s), ${r.warnings.length} warning(s))`\n );\n return out.join('\\n');\n}\n\n/**\n * Throws the report as text when the check failed (an error, a failed spec item, check or reference column), or with\n * `{ warnings: false }` when it has warnings. For the tests of a project:\n *\n * ```ts\n * it('my indicator follows its spec', () => {\n * assertCheck(checkScript(source, { spec, checks: (t) => { ... } }));\n * });\n * ```\n */\nexport function assertCheck(report: CheckReport, options: { warnings?: boolean } = {}): void {\n if (!report.ok || (options.warnings === false && report.warnings.length > 0)) {\n const error = new Error(formatReport(report));\n error.name = 'CheckError';\n throw error;\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,MAAM,MAAM,CAAC,MACX,MAAM,QAAQ,MAAM,SAAY,OAAO,OAAO,UAAU,CAAC,IAAI,OAAO,CAAC,IAAI,OAAO,EAAE,YAAY,CAAC,CAAC,EAAE,SAAS;AAE7G,MAAM,QAAQ,CAAC,MAAwB,MAAM,SAAY,YAAY,KAAK,UAAU,CAAC;AAG9E,SAAS,aAAa,GAAmE;AAC9F,QAAM,OAAO,EAAE,QAAQ;AACvB,QAAM,MAAgB,CAAC;AACvB,MAAI,KAAK,mBAAmB,IAAI,KAAK,EAAE,KAAK,KAAK,IAAI,EAAE,KAAK,YAAY,eAAe,EAAE,mBAAmB,EAAE,KAAK,SAAS,EAAE;AAC9H,QAAM,IAAI,EAAE;AACZ,MAAI,GAAG;AACL,QAAI,KAAK,GAAG,EAAE,IAAI,KAAK,EAAE,KAAK,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AE,WAAW,MAAM,MAAM,SAAS,KAAK,IAAI,EAAE;AACtE,iBAAW,KAAK,MAAO,KAAI,KAAK,OAAO,CAAC,EAAE;AAAA,IAC5C;AAAA,EACF;AACA,QAAM,UACH,EAAE,MAAM,UAAU,MAAM,EAAE,aAAa,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,EAAE,YAAY,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,OAAU,EAAE;AAC3H,MAAI;AAAA,IACF,EAAE,KACE,EAAE,SAAS,SACT,mBAAmB,EAAE,SAAS,MAAM,gBACpC,eACF,iBAAiB,EAAE,OAAO,MAAM,cAAc,MAAM,qBAAqB,EAAE,SAAS,MAAM;AAAA,EAChG;AACA,SAAO,IAAI,KAAK,IAAI;AACtB;AAYO,SAAS,YAAY,QAAqB,UAAkC,CAAC,GAAS;AAC3F,MAAI,CAAC,OAAO,MAAO,QAAQ,aAAa,SAAS,OAAO,SAAS,SAAS,GAAI;AAC5E,UAAM,QAAQ,IAAI,MAAM,aAAa,MAAM,CAAC;AAC5C,UAAM,OAAO;AACb,UAAM;AAAA,EACR;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -49,6 +49,20 @@ export declare function testChart(bars: Bar[], options?: TestChartOptions): Char
|
|
|
49
49
|
* next bar open; `strategy.exit` stop / limit levels are checked inside each bar (stop first when both are hit).
|
|
50
50
|
* Entry limit / stop prices, pyramiding and process_orders_on_close are not simulated.
|
|
51
51
|
*/
|
|
52
|
+
/** A saved state of {@link TestEngine} */
|
|
53
|
+
interface TestEngineState {
|
|
54
|
+
closed: StrategyTrade[];
|
|
55
|
+
open: StrategyTrade | null;
|
|
56
|
+
pendingEntry: {
|
|
57
|
+
id: string;
|
|
58
|
+
direction: StrategyDirection;
|
|
59
|
+
qty?: number;
|
|
60
|
+
} | null;
|
|
61
|
+
pendingClose: boolean;
|
|
62
|
+
exits: Map<string, StrategyExitOptions>;
|
|
63
|
+
net: number;
|
|
64
|
+
bar: number;
|
|
65
|
+
}
|
|
52
66
|
export declare class TestEngine implements StrategyEngine {
|
|
53
67
|
readonly setup: StrategySetup;
|
|
54
68
|
readonly closed: StrategyTrade[];
|
|
@@ -59,6 +73,9 @@ export declare class TestEngine implements StrategyEngine {
|
|
|
59
73
|
private net;
|
|
60
74
|
private bar;
|
|
61
75
|
constructor(setup: StrategySetup);
|
|
76
|
+
/** The engine state at the end of a bar, for incremental runs (#196) */
|
|
77
|
+
save(): TestEngineState;
|
|
78
|
+
restore(state: unknown): void;
|
|
62
79
|
private get bars();
|
|
63
80
|
private equity;
|
|
64
81
|
private openProfit;
|
|
@@ -91,4 +108,11 @@ export interface RunScriptOptions extends TestChartOptions {
|
|
|
91
108
|
}
|
|
92
109
|
/** Runs a script source on `bars` with the test chart context and, for a strategy, the test engine. */
|
|
93
110
|
export declare function runScript(source: string, bars: Bar[], inputs?: Record<string, unknown>, options?: RunScriptOptions): ScriptRun;
|
|
111
|
+
/**
|
|
112
|
+
* Why a live chart would calculate the script in full on every update (#196), or null when its updates are resumed:
|
|
113
|
+
* the script runs as on a live chart, on the bars but the last one, then once more with the last bar (a resumed update,
|
|
114
|
+
* compared with a full run).
|
|
115
|
+
*/
|
|
116
|
+
export declare function incrementalReason(source: string, bars: Bar[], inputs?: Record<string, unknown>, options?: RunScriptOptions): string | null;
|
|
117
|
+
export {};
|
|
94
118
|
//# sourceMappingURL=harness.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"harness.d.ts","sourceRoot":"","sources":["../../../src/check/harness.ts"],"names":[],"mappings":"AAUA,OAAO,
|
|
1
|
+
{"version":3,"file":"harness.d.ts","sourceRoot":"","sources":["../../../src/check/harness.ts"],"names":[],"mappings":"AAUA,OAAO,EAGL,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,oBAAoB,EACzB,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACnB,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EACxB,KAAK,gBA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,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,EACpC,OAAO,GAAE,gBAAqB,GAC7B,MAAM,GAAG,IAAI,CAQf"}
|
|
@@ -34,6 +34,7 @@ __export(harness_exports, {
|
|
|
34
34
|
SCRIPT_SUFFIX: () => SCRIPT_SUFFIX,
|
|
35
35
|
TestEngine: () => TestEngine,
|
|
36
36
|
compileScript: () => compileScript,
|
|
37
|
+
incrementalReason: () => incrementalReason,
|
|
37
38
|
inferTimeframe: () => inferTimeframe,
|
|
38
39
|
rewriteImports: () => rewriteImports,
|
|
39
40
|
runScript: () => runScript,
|
|
@@ -158,6 +159,29 @@ class TestEngine {
|
|
|
158
159
|
exits = /* @__PURE__ */ new Map();
|
|
159
160
|
net = 0;
|
|
160
161
|
bar = 0;
|
|
162
|
+
/** The engine state at the end of a bar, for incremental runs (#196) */
|
|
163
|
+
save() {
|
|
164
|
+
return {
|
|
165
|
+
closed: this.closed.map((t) => ({ ...t })),
|
|
166
|
+
open: this.open ? { ...this.open } : null,
|
|
167
|
+
pendingEntry: this.pendingEntry ? { ...this.pendingEntry } : null,
|
|
168
|
+
pendingClose: this.pendingClose,
|
|
169
|
+
exits: new Map([...this.exits].map(([k, v]) => [k, { ...v }])),
|
|
170
|
+
net: this.net,
|
|
171
|
+
bar: this.bar
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
restore(state) {
|
|
175
|
+
const s = state;
|
|
176
|
+
this.closed.length = 0;
|
|
177
|
+
for (const t of s.closed) this.closed.push({ ...t });
|
|
178
|
+
this.open = s.open ? { ...s.open } : null;
|
|
179
|
+
this.pendingEntry = s.pendingEntry ? { ...s.pendingEntry } : null;
|
|
180
|
+
this.pendingClose = s.pendingClose;
|
|
181
|
+
this.exits = new Map([...s.exits].map(([k, v]) => [k, { ...v }]));
|
|
182
|
+
this.net = s.net;
|
|
183
|
+
this.bar = s.bar;
|
|
184
|
+
}
|
|
161
185
|
get bars() {
|
|
162
186
|
return this.setup.bars;
|
|
163
187
|
}
|
|
@@ -299,4 +323,13 @@ function runScript(source, bars, inputs = {}, options = {}) {
|
|
|
299
323
|
});
|
|
300
324
|
return { run, engine };
|
|
301
325
|
}
|
|
326
|
+
function incrementalReason(source, bars, inputs = {}, options = {}) {
|
|
327
|
+
if (bars.length < 2) return null;
|
|
328
|
+
const body = (options.compile ?? compileScript)(source);
|
|
329
|
+
const chart = testChart(bars, options);
|
|
330
|
+
const run = (0, import_script.createScriptRun)(body, inputs, chart, { strategyEngine: (setup) => new TestEngine(setup), verify: 1 });
|
|
331
|
+
run.update(bars.slice(0, -1), chart);
|
|
332
|
+
run.update(bars, chart);
|
|
333
|
+
return run.fullRunReason;
|
|
334
|
+
}
|
|
302
335
|
//# sourceMappingURL=harness.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/check/harness.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * @fileoverview Runs a script source the way a host app runs a script written in its editor: the source is the body\n * of the script, with every value export of `oakscriptjs/script` but `executeScript` as an implicit global, on\n * deterministic synthetic bars (or given bars), with a chart context and, for a strategy, a small order engine.\n * Used by {@link checkScript}, the `oakscript check` command and the tests of the agent guide.\n *\n * @module check/harness\n */\nimport * as lib from '../index.js';\nimport * as api from '../script/index.js';\nimport {\n executeScript,\n type ChartContext,\n type ScriptRunResult,\n type StrategyCloseOptions,\n type StrategyDirection,\n type StrategyEngine,\n type StrategyEntryOptions,\n type StrategyExitOptions,\n type StrategyRiskRule,\n type StrategySetup,\n type StrategyTrade,\n type StrategyVariable,\n} from '../script/index.js';\nimport type { Bar } from '../types/index.js';\n\n/** The implicit globals of a script: every value export of the script API but the host entry. */\nexport const SCRIPT_GLOBALS: readonly string[] = Object.keys(api).filter(\n (k) => k !== 'default' && k !== 'executeScript' && /^[A-Za-z_$][\\w$]*$/.test(k)\n);\n\n/** Name of the parameter that receives the `oakscriptjs` module in a compiled script (its `import` statements). */\nexport const LIBRARY_PARAMETER = '__oakscriptjs';\n\n/** The values of {@link SCRIPT_GLOBALS}, then the `oakscriptjs` module, in the order of the compiled parameters. */\nexport function scriptArguments(): unknown[] {\n return [...SCRIPT_GLOBALS.map((k) => (api as Record<string, unknown>)[k]), lib];\n}\n\n/**\n * Rewrites the `import { a, b as c } from \"oakscriptjs\"` statements of a script into `const { a, b: c } = ...` on the\n * same lines (the line numbers of the source do not change). Throws on an import of another module: a script runs\n * self-contained.\n */\nexport function rewriteImports(source: string): string {\n return source.replace(/^([ \\t]*)import\\s*(\\{[^}]*\\}|\\*\\s+as\\s+[A-Za-z_$][\\w$]*)\\s*from\\s*(['\"])([^'\"]+)\\3\\s*;?/gm, (all, indent, what, _q, from) => {\n if (from !== 'oakscriptjs' && from !== 'oakscriptjs/script') {\n throw new SyntaxError(`A script can only import from \"oakscriptjs\" (found \"${from}\").`);\n }\n const lines = all.split('\\n').length - 1;\n const binding = what.startsWith('*')\n ? what.replace(/^\\*\\s+as\\s+/, '')\n : what.replace(/\\s+as\\s+/g, ': ').replace(/\\s+/g, ' ');\n return `${indent}const ${binding} = ${LIBRARY_PARAMETER};${'\\n'.repeat(lines)}`;\n });\n}\n\n/**\n * Start and end of the function the script source is wrapped in. The globals are the parameters of an outer function\n * and the source is the body of an inner one, so a script can declare a name of a global (`const size = 2`), as in an\n * app that imports the globals at the top of a module. The start goes on the first line of the source.\n */\nexport const SCRIPT_PREFIX = '\"use strict\"; return (function () { ';\nexport const SCRIPT_SUFFIX = '\\n})();';\n\n/** The source of the function body of a compiled script (imports rewritten, lines kept). */\nexport function wrapSource(source: string): string {\n return SCRIPT_PREFIX + rewriteImports(source) + SCRIPT_SUFFIX;\n}\n\n/** Compiles a script source into a body for executeScript(); throws a SyntaxError on invalid code. */\nexport function compileScript(source: string): () => void {\n const fn = new Function(...SCRIPT_GLOBALS, LIBRARY_PARAMETER, wrapSource(source)) as (...args: unknown[]) => void;\n const values = scriptArguments();\n return () => fn(...values);\n}\n\nconst HOUR = 3600;\n/** 2024-01-01 00:00 UTC, in seconds. */\nconst START = 1704067200;\n\n/** Deterministic synthetic bars: two waves, a slow trend and seeded noise. `step`: seconds between bars. */\nexport function syntheticBars(count: number, step = HOUR, seed = 1): Bar[] {\n let s = seed >>> 0 || 1;\n const rand = (): number => {\n s = (Math.imul(s, 1664525) + 1013904223) >>> 0;\n return s / 2 ** 32;\n };\n const scale = Math.sqrt(step / HOUR);\n const bars: Bar[] = [];\n let prev = 100;\n for (let i = 0; i < count; i++) {\n const t = (i * step) / HOUR;\n const close = 100 + 12 * Math.sin(t / 60) + 4 * Math.sin(t / 11) + t * 0.004 + (rand() - 0.5) * 1.5 * scale;\n const open = prev;\n const high = Math.max(open, close) + rand() * 0.8 * scale;\n const low = Math.min(open, close) - rand() * 0.8 * scale;\n bars.push({ time: START + i * step, open, high, low, close, volume: Math.round(1000 + rand() * 4000) });\n prev = close;\n }\n return bars;\n}\n\n/** Seconds of a timeframe string (\"1\", \"60\", \"240\", \"D\", \"1D\", \"W\", \"M\"); NaN when it is not one. */\nexport function timeframeSeconds(timeframe: string): number {\n const m = /^(\\d*)([SDWM]?)$/.exec(timeframe.trim().toUpperCase());\n if (!m) return NaN;\n const n = m[1] ? Number(m[1]) : 1;\n const unit = { '': 60, S: 1, D: 86400, W: 7 * 86400, M: 30 * 86400 }[m[2] as '' | 'S' | 'D' | 'W' | 'M'];\n return n * unit;\n}\n\n/** The timeframe of bars from the most common spacing of their times (\"60\", \"D\", \"W\"...); \"60\" for fewer than 2 bars. */\nexport function inferTimeframe(bars: readonly Bar[]): string {\n const counts = new Map<number, number>();\n for (let i = 1; i < bars.length; i++) {\n const d = bars[i]!.time - bars[i - 1]!.time;\n if (d > 0) counts.set(d, (counts.get(d) ?? 0) + 1);\n }\n let step = 0;\n let best = 0;\n for (const [d, c] of counts) if (c > best) [step, best] = [d, c];\n if (!step) return '60';\n if (step >= 28 * 86400) return 'M';\n if (step >= 7 * 86400) return 'W';\n if (step >= 86400) return 'D';\n if (step < 60) return `${step}S`;\n return String(Math.round(step / 60));\n}\n\nexport interface TestChartOptions {\n /** Chart timeframe (default \"60\"). */\n timeframe?: string;\n /** Chart ticker id (default \"TEST:SYN\"). */\n tickerid?: string;\n /** Time zone of the chart and of the other symbols (default \"Etc/UTC\"). */\n timezone?: string;\n /** Session of the chart and of the other symbols (default \"24x7\"). */\n session?: string;\n}\n\n/**\n * Chart context of the test runs: a 24x7 symbol in UTC. Higher timeframes of the chart symbol are resampled from the\n * chart bars by the library; other symbols get synthetic bars of their own (seeded by the symbol name).\n */\nexport function testChart(bars: Bar[], options: TestChartOptions = {}): ChartContext {\n const timezone = options.timezone ?? 'Etc/UTC';\n const session = options.session ?? '24x7';\n const chartStep = timeframeSeconds(options.timeframe ?? '60') || HOUR;\n const span = bars.length ? bars[bars.length - 1]!.time - bars[0]!.time + chartStep : 0;\n return {\n tickerid: options.tickerid ?? 'TEST:SYN',\n timeframe: options.timeframe ?? '60',\n timezone,\n session,\n mintick: 0.01,\n pointvalue: 1,\n mincontract: 1,\n currency: 'USD',\n bars: (symbol, timeframe) => {\n const step = timeframeSeconds(timeframe);\n if (!step) return [];\n // a run on zero bars (the declaration run of a host) gets one empty bar: no bars at all is an invalid symbol\n if (!bars.length) return [{ time: 0, open: 0, high: 0, low: 0, close: 0, volume: 0 }];\n const first = bars[0]!.time;\n return syntheticBars(Math.ceil(span / step), step, symbol.length + 7).map((b) => ({\n ...b,\n time: first + (b.time - START),\n }));\n },\n symbolInfo: () => ({ timezone, session, mintick: 0.01, currency: 'USD' }),\n };\n}\n\n/**\n * A small order engine for checks and tests (the library does not fill orders). Market entries and closes fill at the\n * next bar open; `strategy.exit` stop / limit levels are checked inside each bar (stop first when both are hit).\n * Entry limit / stop prices, pyramiding and process_orders_on_close are not simulated.\n */\nexport class TestEngine implements StrategyEngine {\n readonly closed: StrategyTrade[] = [];\n private open: StrategyTrade | null = null;\n private pendingEntry: { id: string; direction: StrategyDirection; qty?: number } | null = null;\n private pendingClose = false;\n private exits = new Map<string, StrategyExitOptions>();\n private net = 0;\n private bar = 0;\n\n constructor(readonly setup: StrategySetup) {}\n\n private get bars(): readonly Bar[] {\n return this.setup.bars;\n }\n\n private equity(price: number): number {\n return this.setup.properties.initial_capital + this.net + this.openProfit(price);\n }\n\n private openProfit(price: number): number {\n return this.open ? (price - this.open.entry_price) * this.open.size : 0;\n }\n\n private commission(value: number): number {\n const p = this.setup.properties;\n return p.commission_type === 'percent' ? (Math.abs(value) * p.commission_value) / 100 : 0;\n }\n\n private closeAt(price: number, exitId: string): void {\n const t = this.open;\n if (!t) return;\n const commission = t.commission + this.commission(price * t.size);\n const profit = (price - t.entry_price) * t.size - commission;\n this.net += profit;\n this.closed.push({\n ...t,\n commission,\n profit,\n profit_percent: (profit / Math.abs(t.entry_price * t.size)) * 100,\n exit_id: exitId,\n exit_price: price,\n exit_bar_index: this.bar,\n exit_time: this.bars[this.bar]!.time * 1000,\n });\n this.open = null;\n this.exits.clear();\n }\n\n /** The open trade, if any. */\n get openTradeNow(): StrategyTrade | null {\n return this.open;\n }\n\n processBar(bar: number): void {\n this.bar = bar;\n const b = this.bars[bar]!;\n if (this.pendingClose) this.closeAt(b.open, 'Close');\n this.pendingClose = false;\n const e = this.pendingEntry;\n this.pendingEntry = null;\n if (e && !(this.open && Math.sign(this.open.size) === (e.direction === 'long' ? 1 : -1))) {\n if (this.open) this.closeAt(b.open, e.id);\n const p = this.setup.properties;\n const equity = this.equity(b.open);\n const qty =\n e.qty ??\n (p.default_qty_type === 'fixed'\n ? p.default_qty_value\n : p.default_qty_type === 'cash'\n ? p.default_qty_value / b.open\n : (equity * p.default_qty_value) / 100 / b.open);\n const size = e.direction === 'long' ? qty : -qty;\n this.open = {\n entry_id: e.id,\n entry_price: b.open,\n entry_bar_index: bar,\n entry_time: b.time * 1000,\n size,\n profit: 0,\n profit_percent: 0,\n commission: this.commission(b.open * size),\n max_runup: 0,\n max_runup_percent: 0,\n max_drawdown: 0,\n max_drawdown_percent: 0,\n };\n }\n const t = this.open;\n if (!t) return;\n for (const [id, x] of this.exits) {\n if (x.from_entry !== undefined && x.from_entry !== t.entry_id) continue;\n const long = t.size > 0;\n if (x.stop !== undefined && (long ? b.low <= x.stop : b.high >= x.stop)) {\n this.closeAt(long ? Math.min(b.open, x.stop) : Math.max(b.open, x.stop), id);\n return;\n }\n if (x.limit !== undefined && (long ? b.high >= x.limit : b.low <= x.limit)) {\n this.closeAt(long ? Math.max(b.open, x.limit) : Math.min(b.open, x.limit), id);\n return;\n }\n }\n }\n\n processClose(): void {}\n\n entry(id: string, direction: StrategyDirection, options: StrategyEntryOptions): void {\n this.pendingEntry = { id, direction, qty: options.qty };\n }\n\n order(id: string, direction: StrategyDirection, options: StrategyEntryOptions): void {\n this.entry(id, direction, options);\n }\n\n exit(id: string, options: StrategyExitOptions): void {\n this.exits.set(id, options);\n }\n\n close(id: string, _options: StrategyCloseOptions): void {\n if (this.open?.entry_id === id) this.pendingClose = true;\n }\n\n close_all(): void {\n if (this.open) this.pendingClose = true;\n }\n\n cancel(id: string): void {\n this.exits.delete(id);\n if (this.pendingEntry?.id === id) this.pendingEntry = null;\n }\n\n cancel_all(): void {\n this.exits.clear();\n this.pendingEntry = null;\n }\n\n readonly rules: StrategyRiskRule[] = [];\n\n risk(rule: StrategyRiskRule): void {\n this.rules.push(rule);\n }\n\n get(variable: StrategyVariable): number | string | undefined {\n const price = this.bars[this.bar]?.close ?? NaN;\n const wins = this.closed.filter((t) => t.profit > 0).length;\n const values: Partial<Record<StrategyVariable, number | string>> = {\n position_size: this.open?.size ?? 0,\n position_avg_price: this.open?.entry_price ?? NaN,\n initial_capital: this.setup.properties.initial_capital,\n equity: this.equity(price),\n netprofit: this.net,\n openprofit: this.openProfit(price),\n opentrades: this.open ? 1 : 0,\n closedtrades: this.closed.length,\n wintrades: wins,\n losstrades: this.closed.length - wins,\n account_currency: 'USD',\n };\n return values[variable];\n }\n\n openTrade(index: number): StrategyTrade | undefined {\n return index === 0 && this.open ? this.open : undefined;\n }\n\n closedTrade(index: number): StrategyTrade | undefined {\n return this.closed[index];\n }\n}\n\nexport interface ScriptRun {\n run: ScriptRunResult;\n engine?: TestEngine;\n}\n\nexport interface RunScriptOptions extends TestChartOptions {\n /** Compiles the source (default {@link compileScript}); the CLI compiles with file lines. */\n compile?: (source: string) => () => void;\n}\n\n/** Runs a script source on `bars` with the test chart context and, for a strategy, the test engine. */\nexport function runScript(\n source: string,\n bars: Bar[],\n inputs: Record<string, unknown> = {},\n options: RunScriptOptions = {}\n): ScriptRun {\n let engine: TestEngine | undefined;\n const body = (options.compile ?? compileScript)(source);\n const run = executeScript(body, bars, inputs, testChart(bars, options), {\n strategyEngine: (setup) => (engine = new TestEngine(setup)),\n });\n return { run, engine };\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,UAAqB;AACrB,UAAqB;AACrB,
|
|
4
|
+
"sourcesContent": ["/**\n * @fileoverview Runs a script source the way a host app runs a script written in its editor: the source is the body\n * of the script, with every value export of `oakscriptjs/script` but `executeScript` as an implicit global, on\n * deterministic synthetic bars (or given bars), with a chart context and, for a strategy, a small order engine.\n * Used by {@link checkScript}, the `oakscript check` command and the tests of the agent guide.\n *\n * @module check/harness\n */\nimport * as lib from '../index.js';\nimport * as api from '../script/index.js';\nimport {\n createScriptRun,\n executeScript,\n type ChartContext,\n type ScriptRunResult,\n type StrategyCloseOptions,\n type StrategyDirection,\n type StrategyEngine,\n type StrategyEntryOptions,\n type StrategyExitOptions,\n type StrategyRiskRule,\n type StrategySetup,\n type StrategyTrade,\n type StrategyVariable,\n} from '../script/index.js';\nimport type { Bar } from '../types/index.js';\n\n/** The implicit globals of a script: every value export of the script API but the host entry. */\nexport const SCRIPT_GLOBALS: readonly string[] = Object.keys(api).filter(\n (k) => k !== 'default' && k !== 'executeScript' && /^[A-Za-z_$][\\w$]*$/.test(k)\n);\n\n/** Name of the parameter that receives the `oakscriptjs` module in a compiled script (its `import` statements). */\nexport const LIBRARY_PARAMETER = '__oakscriptjs';\n\n/** The values of {@link SCRIPT_GLOBALS}, then the `oakscriptjs` module, in the order of the compiled parameters. */\nexport function scriptArguments(): unknown[] {\n return [...SCRIPT_GLOBALS.map((k) => (api as Record<string, unknown>)[k]), lib];\n}\n\n/**\n * Rewrites the `import { a, b as c } from \"oakscriptjs\"` statements of a script into `const { a, b: c } = ...` on the\n * same lines (the line numbers of the source do not change). Throws on an import of another module: a script runs\n * self-contained.\n */\nexport function rewriteImports(source: string): string {\n return source.replace(/^([ \\t]*)import\\s*(\\{[^}]*\\}|\\*\\s+as\\s+[A-Za-z_$][\\w$]*)\\s*from\\s*(['\"])([^'\"]+)\\3\\s*;?/gm, (all, indent, what, _q, from) => {\n if (from !== 'oakscriptjs' && from !== 'oakscriptjs/script') {\n throw new SyntaxError(`A script can only import from \"oakscriptjs\" (found \"${from}\").`);\n }\n const lines = all.split('\\n').length - 1;\n const binding = what.startsWith('*')\n ? what.replace(/^\\*\\s+as\\s+/, '')\n : what.replace(/\\s+as\\s+/g, ': ').replace(/\\s+/g, ' ');\n return `${indent}const ${binding} = ${LIBRARY_PARAMETER};${'\\n'.repeat(lines)}`;\n });\n}\n\n/**\n * Start and end of the function the script source is wrapped in. The globals are the parameters of an outer function\n * and the source is the body of an inner one, so a script can declare a name of a global (`const size = 2`), as in an\n * app that imports the globals at the top of a module. The start goes on the first line of the source.\n */\nexport const SCRIPT_PREFIX = '\"use strict\"; return (function () { ';\nexport const SCRIPT_SUFFIX = '\\n})();';\n\n/** The source of the function body of a compiled script (imports rewritten, lines kept). */\nexport function wrapSource(source: string): string {\n return SCRIPT_PREFIX + rewriteImports(source) + SCRIPT_SUFFIX;\n}\n\n/** Compiles a script source into a body for executeScript(); throws a SyntaxError on invalid code. */\nexport function compileScript(source: string): () => void {\n const fn = new Function(...SCRIPT_GLOBALS, LIBRARY_PARAMETER, wrapSource(source)) as (...args: unknown[]) => void;\n const values = scriptArguments();\n return () => fn(...values);\n}\n\nconst HOUR = 3600;\n/** 2024-01-01 00:00 UTC, in seconds. */\nconst START = 1704067200;\n\n/** Deterministic synthetic bars: two waves, a slow trend and seeded noise. `step`: seconds between bars. */\nexport function syntheticBars(count: number, step = HOUR, seed = 1): Bar[] {\n let s = seed >>> 0 || 1;\n const rand = (): number => {\n s = (Math.imul(s, 1664525) + 1013904223) >>> 0;\n return s / 2 ** 32;\n };\n const scale = Math.sqrt(step / HOUR);\n const bars: Bar[] = [];\n let prev = 100;\n for (let i = 0; i < count; i++) {\n const t = (i * step) / HOUR;\n const close = 100 + 12 * Math.sin(t / 60) + 4 * Math.sin(t / 11) + t * 0.004 + (rand() - 0.5) * 1.5 * scale;\n const open = prev;\n const high = Math.max(open, close) + rand() * 0.8 * scale;\n const low = Math.min(open, close) - rand() * 0.8 * scale;\n bars.push({ time: START + i * step, open, high, low, close, volume: Math.round(1000 + rand() * 4000) });\n prev = close;\n }\n return bars;\n}\n\n/** Seconds of a timeframe string (\"1\", \"60\", \"240\", \"D\", \"1D\", \"W\", \"M\"); NaN when it is not one. */\nexport function timeframeSeconds(timeframe: string): number {\n const m = /^(\\d*)([SDWM]?)$/.exec(timeframe.trim().toUpperCase());\n if (!m) return NaN;\n const n = m[1] ? Number(m[1]) : 1;\n const unit = { '': 60, S: 1, D: 86400, W: 7 * 86400, M: 30 * 86400 }[m[2] as '' | 'S' | 'D' | 'W' | 'M'];\n return n * unit;\n}\n\n/** The timeframe of bars from the most common spacing of their times (\"60\", \"D\", \"W\"...); \"60\" for fewer than 2 bars. */\nexport function inferTimeframe(bars: readonly Bar[]): string {\n const counts = new Map<number, number>();\n for (let i = 1; i < bars.length; i++) {\n const d = bars[i]!.time - bars[i - 1]!.time;\n if (d > 0) counts.set(d, (counts.get(d) ?? 0) + 1);\n }\n let step = 0;\n let best = 0;\n for (const [d, c] of counts) if (c > best) [step, best] = [d, c];\n if (!step) return '60';\n if (step >= 28 * 86400) return 'M';\n if (step >= 7 * 86400) return 'W';\n if (step >= 86400) return 'D';\n if (step < 60) return `${step}S`;\n return String(Math.round(step / 60));\n}\n\nexport interface TestChartOptions {\n /** Chart timeframe (default \"60\"). */\n timeframe?: string;\n /** Chart ticker id (default \"TEST:SYN\"). */\n tickerid?: string;\n /** Time zone of the chart and of the other symbols (default \"Etc/UTC\"). */\n timezone?: string;\n /** Session of the chart and of the other symbols (default \"24x7\"). */\n session?: string;\n}\n\n/**\n * Chart context of the test runs: a 24x7 symbol in UTC. Higher timeframes of the chart symbol are resampled from the\n * chart bars by the library; other symbols get synthetic bars of their own (seeded by the symbol name).\n */\nexport function testChart(bars: Bar[], options: TestChartOptions = {}): ChartContext {\n const timezone = options.timezone ?? 'Etc/UTC';\n const session = options.session ?? '24x7';\n const chartStep = timeframeSeconds(options.timeframe ?? '60') || HOUR;\n const span = bars.length ? bars[bars.length - 1]!.time - bars[0]!.time + chartStep : 0;\n return {\n tickerid: options.tickerid ?? 'TEST:SYN',\n timeframe: options.timeframe ?? '60',\n timezone,\n session,\n mintick: 0.01,\n pointvalue: 1,\n mincontract: 1,\n currency: 'USD',\n bars: (symbol, timeframe) => {\n const step = timeframeSeconds(timeframe);\n if (!step) return [];\n // a run on zero bars (the declaration run of a host) gets one empty bar: no bars at all is an invalid symbol\n if (!bars.length) return [{ time: 0, open: 0, high: 0, low: 0, close: 0, volume: 0 }];\n const first = bars[0]!.time;\n return syntheticBars(Math.ceil(span / step), step, symbol.length + 7).map((b) => ({\n ...b,\n time: first + (b.time - START),\n }));\n },\n symbolInfo: () => ({ timezone, session, mintick: 0.01, currency: 'USD' }),\n };\n}\n\n/**\n * A small order engine for checks and tests (the library does not fill orders). Market entries and closes fill at the\n * next bar open; `strategy.exit` stop / limit levels are checked inside each bar (stop first when both are hit).\n * Entry limit / stop prices, pyramiding and process_orders_on_close are not simulated.\n */\n/** A saved state of {@link TestEngine} */\ninterface TestEngineState {\n closed: StrategyTrade[];\n open: StrategyTrade | null;\n pendingEntry: { id: string; direction: StrategyDirection; qty?: number } | null;\n pendingClose: boolean;\n exits: Map<string, StrategyExitOptions>;\n net: number;\n bar: number;\n}\n\nexport class TestEngine implements StrategyEngine {\n readonly closed: StrategyTrade[] = [];\n private open: StrategyTrade | null = null;\n private pendingEntry: { id: string; direction: StrategyDirection; qty?: number } | null = null;\n private pendingClose = false;\n private exits = new Map<string, StrategyExitOptions>();\n private net = 0;\n private bar = 0;\n\n constructor(readonly setup: StrategySetup) {}\n\n /** The engine state at the end of a bar, for incremental runs (#196) */\n save(): TestEngineState {\n return {\n closed: this.closed.map((t) => ({ ...t })),\n open: this.open ? { ...this.open } : null,\n pendingEntry: this.pendingEntry ? { ...this.pendingEntry } : null,\n pendingClose: this.pendingClose,\n exits: new Map([...this.exits].map(([k, v]) => [k, { ...v }])),\n net: this.net,\n bar: this.bar,\n };\n }\n\n restore(state: unknown): void {\n const s = state as TestEngineState;\n this.closed.length = 0;\n for (const t of s.closed) this.closed.push({ ...t });\n this.open = s.open ? { ...s.open } : null;\n this.pendingEntry = s.pendingEntry ? { ...s.pendingEntry } : null;\n this.pendingClose = s.pendingClose;\n this.exits = new Map([...s.exits].map(([k, v]) => [k, { ...v }]));\n this.net = s.net;\n this.bar = s.bar;\n }\n\n private get bars(): readonly Bar[] {\n return this.setup.bars;\n }\n\n private equity(price: number): number {\n return this.setup.properties.initial_capital + this.net + this.openProfit(price);\n }\n\n private openProfit(price: number): number {\n return this.open ? (price - this.open.entry_price) * this.open.size : 0;\n }\n\n private commission(value: number): number {\n const p = this.setup.properties;\n return p.commission_type === 'percent' ? (Math.abs(value) * p.commission_value) / 100 : 0;\n }\n\n private closeAt(price: number, exitId: string): void {\n const t = this.open;\n if (!t) return;\n const commission = t.commission + this.commission(price * t.size);\n const profit = (price - t.entry_price) * t.size - commission;\n this.net += profit;\n this.closed.push({\n ...t,\n commission,\n profit,\n profit_percent: (profit / Math.abs(t.entry_price * t.size)) * 100,\n exit_id: exitId,\n exit_price: price,\n exit_bar_index: this.bar,\n exit_time: this.bars[this.bar]!.time * 1000,\n });\n this.open = null;\n this.exits.clear();\n }\n\n /** The open trade, if any. */\n get openTradeNow(): StrategyTrade | null {\n return this.open;\n }\n\n processBar(bar: number): void {\n this.bar = bar;\n const b = this.bars[bar]!;\n if (this.pendingClose) this.closeAt(b.open, 'Close');\n this.pendingClose = false;\n const e = this.pendingEntry;\n this.pendingEntry = null;\n if (e && !(this.open && Math.sign(this.open.size) === (e.direction === 'long' ? 1 : -1))) {\n if (this.open) this.closeAt(b.open, e.id);\n const p = this.setup.properties;\n const equity = this.equity(b.open);\n const qty =\n e.qty ??\n (p.default_qty_type === 'fixed'\n ? p.default_qty_value\n : p.default_qty_type === 'cash'\n ? p.default_qty_value / b.open\n : (equity * p.default_qty_value) / 100 / b.open);\n const size = e.direction === 'long' ? qty : -qty;\n this.open = {\n entry_id: e.id,\n entry_price: b.open,\n entry_bar_index: bar,\n entry_time: b.time * 1000,\n size,\n profit: 0,\n profit_percent: 0,\n commission: this.commission(b.open * size),\n max_runup: 0,\n max_runup_percent: 0,\n max_drawdown: 0,\n max_drawdown_percent: 0,\n };\n }\n const t = this.open;\n if (!t) return;\n for (const [id, x] of this.exits) {\n if (x.from_entry !== undefined && x.from_entry !== t.entry_id) continue;\n const long = t.size > 0;\n if (x.stop !== undefined && (long ? b.low <= x.stop : b.high >= x.stop)) {\n this.closeAt(long ? Math.min(b.open, x.stop) : Math.max(b.open, x.stop), id);\n return;\n }\n if (x.limit !== undefined && (long ? b.high >= x.limit : b.low <= x.limit)) {\n this.closeAt(long ? Math.max(b.open, x.limit) : Math.min(b.open, x.limit), id);\n return;\n }\n }\n }\n\n processClose(): void {}\n\n entry(id: string, direction: StrategyDirection, options: StrategyEntryOptions): void {\n this.pendingEntry = { id, direction, qty: options.qty };\n }\n\n order(id: string, direction: StrategyDirection, options: StrategyEntryOptions): void {\n this.entry(id, direction, options);\n }\n\n exit(id: string, options: StrategyExitOptions): void {\n this.exits.set(id, options);\n }\n\n close(id: string, _options: StrategyCloseOptions): void {\n if (this.open?.entry_id === id) this.pendingClose = true;\n }\n\n close_all(): void {\n if (this.open) this.pendingClose = true;\n }\n\n cancel(id: string): void {\n this.exits.delete(id);\n if (this.pendingEntry?.id === id) this.pendingEntry = null;\n }\n\n cancel_all(): void {\n this.exits.clear();\n this.pendingEntry = null;\n }\n\n readonly rules: StrategyRiskRule[] = [];\n\n risk(rule: StrategyRiskRule): void {\n this.rules.push(rule);\n }\n\n get(variable: StrategyVariable): number | string | undefined {\n const price = this.bars[this.bar]?.close ?? NaN;\n const wins = this.closed.filter((t) => t.profit > 0).length;\n const values: Partial<Record<StrategyVariable, number | string>> = {\n position_size: this.open?.size ?? 0,\n position_avg_price: this.open?.entry_price ?? NaN,\n initial_capital: this.setup.properties.initial_capital,\n equity: this.equity(price),\n netprofit: this.net,\n openprofit: this.openProfit(price),\n opentrades: this.open ? 1 : 0,\n closedtrades: this.closed.length,\n wintrades: wins,\n losstrades: this.closed.length - wins,\n account_currency: 'USD',\n };\n return values[variable];\n }\n\n openTrade(index: number): StrategyTrade | undefined {\n return index === 0 && this.open ? this.open : undefined;\n }\n\n closedTrade(index: number): StrategyTrade | undefined {\n return this.closed[index];\n }\n}\n\nexport interface ScriptRun {\n run: ScriptRunResult;\n engine?: TestEngine;\n}\n\nexport interface RunScriptOptions extends TestChartOptions {\n /** Compiles the source (default {@link compileScript}); the CLI compiles with file lines. */\n compile?: (source: string) => () => void;\n}\n\n/** Runs a script source on `bars` with the test chart context and, for a strategy, the test engine. */\nexport function runScript(\n source: string,\n bars: Bar[],\n inputs: Record<string, unknown> = {},\n options: RunScriptOptions = {}\n): ScriptRun {\n let engine: TestEngine | undefined;\n const body = (options.compile ?? compileScript)(source);\n const run = executeScript(body, bars, inputs, testChart(bars, options), {\n strategyEngine: (setup) => (engine = new TestEngine(setup)),\n });\n return { run, engine };\n}\n\n/**\n * Why a live chart would calculate the script in full on every update (#196), or null when its updates are resumed:\n * the script runs as on a live chart, on the bars but the last one, then once more with the last bar (a resumed update,\n * compared with a full run).\n */\nexport function incrementalReason(\n source: string,\n bars: Bar[],\n inputs: Record<string, unknown> = {},\n options: RunScriptOptions = {}\n): string | null {\n if (bars.length < 2) return null;\n const body = (options.compile ?? compileScript)(source);\n const chart = testChart(bars, options);\n const run = createScriptRun(body, inputs, chart, { strategyEngine: (setup) => new TestEngine(setup), verify: 1 });\n run.update(bars.slice(0, -1), chart);\n run.update(bars, chart);\n return run.fullRunReason;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,UAAqB;AACrB,UAAqB;AACrB,oBAcO;AAIA,MAAM,iBAAoC,OAAO,KAAK,GAAG,EAAE;AAAA,EAChE,CAAC,MAAM,MAAM,aAAa,MAAM,mBAAmB,qBAAqB,KAAK,CAAC;AAChF;AAGO,MAAM,oBAAoB;AAG1B,SAAS,kBAA6B;AAC3C,SAAO,CAAC,GAAG,eAAe,IAAI,CAAC,MAAO,IAAgC,CAAC,CAAC,GAAG,GAAG;AAChF;AAOO,SAAS,eAAe,QAAwB;AACrD,SAAO,OAAO,QAAQ,6FAA6F,CAAC,KAAK,QAAQ,MAAM,IAAI,SAAS;AAClJ,QAAI,SAAS,iBAAiB,SAAS,sBAAsB;AAC3D,YAAM,IAAI,YAAY,uDAAuD,IAAI,KAAK;AAAA,IACxF;AACA,UAAM,QAAQ,IAAI,MAAM,IAAI,EAAE,SAAS;AACvC,UAAM,UAAU,KAAK,WAAW,GAAG,IAC/B,KAAK,QAAQ,eAAe,EAAE,IAC9B,KAAK,QAAQ,aAAa,IAAI,EAAE,QAAQ,QAAQ,GAAG;AACvD,WAAO,GAAG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AAK;AAAA,EAC3D,CAAC;AACD,SAAO,EAAE,KAAK,OAAO;AACvB;AAOO,SAAS,kBACd,QACA,MACA,SAAkC,CAAC,GACnC,UAA4B,CAAC,GACd;AACf,MAAI,KAAK,SAAS,EAAG,QAAO;AAC5B,QAAM,QAAQ,QAAQ,WAAW,eAAe,MAAM;AACtD,QAAM,QAAQ,UAAU,MAAM,OAAO;AACrC,QAAM,UAAM,+BAAgB,MAAM,QAAQ,OAAO,EAAE,gBAAgB,CAAC,UAAU,IAAI,WAAW,KAAK,GAAG,QAAQ,EAAE,CAAC;AAChH,MAAI,OAAO,KAAK,MAAM,GAAG,EAAE,GAAG,KAAK;AACnC,MAAI,OAAO,MAAM,KAAK;AACtB,SAAO,IAAI;AACb;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -199,6 +199,15 @@ export interface CheckReport {
|
|
|
199
199
|
};
|
|
200
200
|
/** alert() calls of the script (all bars). */
|
|
201
201
|
alertCalls: number;
|
|
202
|
+
/**
|
|
203
|
+
* Live updates on a chart that runs the script with createScriptRun (#196): resumed (the newest bars only) or full
|
|
204
|
+
* runs, with the reason (state outside persist(), drawings in two blocks, request.security...). Not a warning: the
|
|
205
|
+
* results are the same.
|
|
206
|
+
*/
|
|
207
|
+
liveUpdates?: {
|
|
208
|
+
resumed: boolean;
|
|
209
|
+
reason: string | null;
|
|
210
|
+
};
|
|
202
211
|
strategy?: {
|
|
203
212
|
closedTrades: number;
|
|
204
213
|
openTrade: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/check/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAE7C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src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AE,QAAQ,CAAC,EAAE,MAAM,GAAG;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAOnG;AA6PD,mDAAmD;AACnD,eAAO,MAAM,UAAU,OAAO,CAAC;AAI/B,+CAA+C;AAC/C,eAAO,MAAM,SAAS,EAAE,SAAS,aAAa,EAsB7C,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,YAAiB,GAAG,WAAW,CAsKnF"}
|
package/dist/cjs/check/index.js
CHANGED
|
@@ -390,6 +390,13 @@ function checkScript(source, options = {}) {
|
|
|
390
390
|
report.alertCalls = r.alertCalls?.length ?? 0;
|
|
391
391
|
if (main.engine) report.strategy = summarizeStrategy(main.engine);
|
|
392
392
|
report.warnings = warningsOf(report, bars);
|
|
393
|
+
if (!main.engine) {
|
|
394
|
+
try {
|
|
395
|
+
const reason = wrap(() => (0, import_harness.incrementalReason)(source, bars, inputs, runOptions));
|
|
396
|
+
report.liveUpdates = { resumed: reason === null, reason };
|
|
397
|
+
} catch {
|
|
398
|
+
}
|
|
399
|
+
}
|
|
393
400
|
if (options.inputSweep !== false) {
|
|
394
401
|
const base = fingerprint(run, main.engine);
|
|
395
402
|
for (const input of run.inputConfig) {
|