Spaces:
Running
Running
| <html class="default" lang="en" data-base=".."><head><meta charset="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>begin/12_backtest_module_frame_configuration | backtest-kit</title><meta name="description" content="Documentation for backtest-kit"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="../assets/style.css"/><link rel="stylesheet" href="../assets/highlight.css"/><script defer src="../assets/main.js"></script><script async src="../assets/icons.js" id="tsd-icons-script"></script><script async src="../assets/search.js" id="tsd-search-script"></script><script async src="../assets/navigation.js" id="tsd-nav-script"></script><script async src="../assets/hierarchy.js" id="tsd-hierarchy-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os";document.body.style.display="none";setTimeout(() => app?app.showPage():document.body.style.removeProperty("display"),500)</script><header class="tsd-page-toolbar"><div class="tsd-toolbar-contents container"><div class="table-cell" id="tsd-search"><div class="field"><label for="tsd-search-field" class="tsd-widget tsd-toolbar-icon search no-caption"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-search"></use></svg></label><input type="text" id="tsd-search-field" aria-label="Search"/></div><div class="field"><div id="tsd-toolbar-links"></div></div><ul class="results"><li class="state loading">Preparing search index...</li><li class="state failure">The search index is not available</li></ul><a href="../index.html" class="title">backtest-kit</a></div><div class="table-cell" id="tsd-widgets"><a href="#" class="tsd-widget tsd-toolbar-icon menu no-caption" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-menu"></use></svg></a></div></div></header><div class="container container-main"><div class="col-content"><div class="tsd-page-title"><ul class="tsd-breadcrumb"><li><a href="../modules.html">backtest-kit</a></li><li><a href="begin_12_backtest_module_frame_configuration.html">begin/12_backtest_module_frame_configuration</a></li></ul></div><div class="tsd-panel tsd-typography"><a id="backtest-module--frame-configuration" class="tsd-anchor"></a><h1 class="tsd-anchor-link">Backtest Module & Frame Configuration<a href="#backtest-module--frame-configuration" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h1><p>The <code>backtest.module.ts</code> file serves as the configuration bridge between the <code>backtest-kit</code> framework and the specific requirements of the February 2026 trading strategy. It defines the exchange communication protocols, historical data windows, and global framework overrides necessary for executing a high-fidelity backtest.</p> | |
| <a id="configuration-overview" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Configuration Overview<a href="#configuration-overview" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><p>The module utilizes the <code>backtest-kit</code> registry pattern to define how the system interacts with external data and how it segments time during simulation.</p> | |
| <table> | |
| <thead> | |
| <tr> | |
| <th style="text-align:left">Entity</th> | |
| <th style="text-align:left">Code Symbol</th> | |
| <th style="text-align:left">Purpose</th> | |
| </tr> | |
| </thead> | |
| <tbody> | |
| <tr> | |
| <td style="text-align:left"><strong>Exchange Schema</strong></td> | |
| <td style="text-align:left"><code>ccxt-exchange</code></td> | |
| <td style="text-align:left">Standardizes API calls for candles, order books, and precision formatting.</td> | |
| </tr> | |
| <tr> | |
| <td style="text-align:left"><strong>Frame Schema</strong></td> | |
| <td style="text-align:left"><code>feb_2026_frame</code></td> | |
| <td style="text-align:left">Defines the temporal window (Feb 2026) and 1m resolution.</td> | |
| </tr> | |
| <tr> | |
| <td style="text-align:left"><strong>Exchange Instance</strong></td> | |
| <td style="text-align:left"><code>getExchange</code></td> | |
| <td style="text-align:left">A <code>singleshot</code> Binance singleton using CCXT.</td> | |
| </tr> | |
| <tr> | |
| <td style="text-align:left"><strong>Global Override</strong></td> | |
| <td style="text-align:left"><code>CC_MAX_STOPLOSS_DISTANCE_PERCENT</code></td> | |
| <td style="text-align:left">Disables framework-level stop-loss distance constraints.</td> | |
| </tr> | |
| </tbody> | |
| </table> | |
| <ul> | |
| <li></li> | |
| <li></li> | |
| <li></li> | |
| </ul> | |
| <hr> | |
| <a id="ccxt-exchange-integration" class="tsd-anchor"></a><h3 class="tsd-anchor-link">CCXT Exchange Integration<a href="#ccxt-exchange-integration" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><p>The system uses the <code>ccxt-exchange</code> schema to wrap the CCXT library. This allows the strategy to remain agnostic of specific exchange API quirks while benefiting from Binance's liquidity data.</p> | |
| <a id="the-binance-singleton" class="tsd-anchor"></a><h4 class="tsd-anchor-link">The Binance Singleton<a href="#the-binance-singleton" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h4><p>To prevent redundant connections and market loading, the module implements a <code>singleshot</code> (memoized) exchange getter. It configures the Binance spot market with <code>enableRateLimit</code> and time difference adjustments.</p> | |
| <ul> | |
| <li></li> | |
| </ul> | |
| <a id="schema-implementation" class="tsd-anchor"></a><h4 class="tsd-anchor-link">Schema Implementation<a href="#schema-implementation" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h4><p>The <code>addExchangeSchema</code> function registers four primary methods:</p> | |
| <ol> | |
| <li><strong><code>getCandles</code></strong>: Fetches OHLCV data using <code>exchange.fetchOHLCV</code>. It maps the raw array response into the structured objects required by <code>backtest-kit</code>.</li> | |
| <li><strong><code>getOrderBook</code></strong>: Fetches depth data. Note that this method explicitly throws an error if called during a <code>backtest</code> context to prevent unintentional real-time data leakage into historical simulations.</li> | |
| <li><strong><code>formatPrice</code></strong>: Ensures prices adhere to exchange-specific tick sizes. It prefers <code>market.limits.price.min</code> or <code>market.precision.price</code> and utilizes <code>roundTicks</code> for precision.</li> | |
| <li><strong><code>formatQuantity</code></strong>: Similar to price formatting, it ensures order amounts respect the <code>stepSize</code> of the specific trading pair.</li> | |
| </ol> | |
| <ul> | |
| <li></li> | |
| </ul> | |
| <a id="data-flow-exchange-schema-to-framework" class="tsd-anchor"></a><h4 class="tsd-anchor-link">Data Flow: Exchange Schema to Framework<a href="#data-flow-exchange-schema-to-framework" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h4><p>The following diagram illustrates how the <code>backtest-kit</code> framework consumes the registered <code>ccxt-exchange</code> schema during a simulation.</p> | |
| <a id="diagram-exchange-schema-execution-flowmermaid-diagram" class="tsd-anchor"></a><h2 class="tsd-anchor-link"><strong>Diagram: Exchange Schema Execution Flow</strong> | |
| <img src="../media/12-backtest-module-frame-configuration_0.svg" alt="Mermaid Diagram"><a href="#diagram-exchange-schema-execution-flowmermaid-diagram" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h2><ul> | |
| <li></li> | |
| <li></li> | |
| </ul> | |
| <hr> | |
| <a id="temporal-frame-configuration" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Temporal Frame Configuration<a href="#temporal-frame-configuration" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><p>The <code>feb_2026_frame</code> defines the boundaries of the backtest. This configuration is critical for ensuring the <code>Backtest.run()</code> generator produces the correct sequence of timestamps.</p> | |
| <ul> | |
| <li><strong>Interval</strong>: <code>1m</code> (One-minute resolution).</li> | |
| <li><strong>Start Date</strong>: <code>2026-02-01T00:00:00Z</code>.</li> | |
| <li><strong>End Date</strong>: <code>2026-02-28T23:59:59Z</code>.</li> | |
| </ul> | |
| <p>This frame ensures that the strategy is tested against the specific volatile period of February 2026, which includes the macro-events the LLM is trained to analyze.</p> | |
| <ul> | |
| <li></li> | |
| </ul> | |
| <hr> | |
| <a id="global-framework-overrides" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Global Framework Overrides<a href="#global-framework-overrides" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><p>The module sets specific global configurations using <code>setConfig</code>.</p> | |
| <pre><code class="typescript"><span class="hl-0">setConfig</span><span class="hl-1">({</span><br/><span class="hl-1"> </span><span class="hl-4">CC_MAX_STOPLOSS_DISTANCE_PERCENT:</span><span class="hl-1"> </span><span class="hl-7">100</span><span class="hl-1">,</span><br/><span class="hl-1">});</span> | |
| </code><button type="button">Copy</button></pre> | |
| <p>By setting <code>CC_MAX_STOPLOSS_DISTANCE_PERCENT</code> to <code>100</code>, the strategy disables the default safety checks that would otherwise reject signals with very wide stop-losses. This is necessary for the <code>feb_2026_strategy</code> which may utilize wide stops or rely on logic-based exits (like sentiment flips) rather than tight technical stops.</p> | |
| <ul> | |
| <li></li> | |
| </ul> | |
| <hr> | |
| <a id="code-entity-association" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Code Entity Association<a href="#code-entity-association" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><p>The following diagram maps the natural language requirements of a backtest to the specific code entities defined in the module.</p> | |
| <p><strong>Diagram: Backtest Configuration Mapping</strong> | |
| <img src="../media/12-backtest-module-frame-configuration_1.svg" alt="Mermaid Diagram"></p> | |
| <ul> | |
| <li></li> | |
| <li></li> | |
| <li></li> | |
| <li></li> | |
| </ul> | |
| </div></div><div class="col-sidebar"><div class="page-menu"><div class="tsd-navigation settings"><details class="tsd-accordion"><summary class="tsd-accordion-summary"><h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-chevronDown"></use></svg>Settings</h3></summary><div class="tsd-accordion-details"><div class="tsd-filter-visibility"><span class="settings-label">Member Visibility</span><ul id="tsd-filter-options"><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-protected" name="protected"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Protected</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-external" name="external"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>External</span></label></li></ul></div><div class="tsd-theme-toggle"><label class="settings-label" for="tsd-theme">Theme</label><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div><details open class="tsd-accordion tsd-page-navigation"><summary class="tsd-accordion-summary"><h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-chevronDown"></use></svg>On This Page</h3></summary><div class="tsd-accordion-details"><a href="#backtest-module--frame-configuration"><span>Backtest <wbr/>Module & <wbr/>Frame <wbr/>Configuration</span></a><ul><li><ul><li><a href="#configuration-overview"><span>Configuration <wbr/>Overview</span></a></li><li><a href="#ccxt-exchange-integration"><span>CCXT <wbr/>Exchange <wbr/>Integration</span></a></li><li><ul><li><a href="#the-binance-singleton"><span>The <wbr/>Binance <wbr/>Singleton</span></a></li><li><a href="#schema-implementation"><span>Schema <wbr/>Implementation</span></a></li><li><a href="#data-flow-exchange-schema-to-framework"><span>Data <wbr/>Flow: <wbr/>Exchange <wbr/>Schema to <wbr/>Framework</span></a></li></ul></li></ul></li></ul><a href="#diagram-exchange-schema-execution-flowmermaid-diagram"><span>Diagram: <wbr/>Exchange <wbr/>Schema <wbr/>Execution <wbr/>Flow<wbr/>Mermaid <wbr/>Diagram</span></a><ul><li><a href="#temporal-frame-configuration"><span>Temporal <wbr/>Frame <wbr/>Configuration</span></a></li><li><a href="#global-framework-overrides"><span>Global <wbr/>Framework <wbr/>Overrides</span></a></li><li><a href="#code-entity-association"><span>Code <wbr/>Entity <wbr/>Association</span></a></li></ul></div></details></div><div class="site-menu"><nav class="tsd-navigation"><a href="../modules.html">backtest-kit</a><ul class="tsd-small-nested-navigation" id="tsd-nav-container"><li>Loading...</li></ul></nav></div></div></div><footer><p class="tsd-generator">Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></footer><div class="overlay"></div></body></html> | |
| <!-- Yandex.Metrika counter --> | |
| <script type="text/javascript"> | |
| (function(m,e,t,r,i,k,a){ | |
| m[i]=m[i]||function(){(m[i].a=m[i].a||[]).push(arguments)}; | |
| m[i].l=1*new Date(); | |
| for (var j = 0; j < document.scripts.length; j++) {if (document.scripts[j].src === r) { return; }} | |
| k=e.createElement(t),a=e.getElementsByTagName(t)[0],k.async=1,k.src=r,a.parentNode.insertBefore(k,a) | |
| })(window, document,'script','https://mc.yandex.ru/metrika/tag.js?id=105455585', 'ym'); | |
| ym(105455585, 'init', {ssr:true, webvisor:true, clickmap:true, ecommerce:"dataLayer", accurateTrackBounce:true, trackLinks:true}); | |
| </script> | |
| <noscript><div><img src="https://mc.yandex.ru/watch/105455585" style="position:absolute; left:-9999px;" alt="" /></div></noscript> | |
| <!-- /Yandex.Metrika counter --> | |
| <!-- Google tag (gtag.js) --> | |
| <script async src="https://www.googletagmanager.com/gtag/js?id=G-3MQZEBBDDR"></script> | |
| <script> | |
| window.dataLayer = window.dataLayer || []; | |
| function gtag(){dataLayer.push(arguments);} | |
| gtag('js', new Date()); | |
| gtag('config', 'G-3MQZEBBDDR'); | |
| </script> | |