backtest-kit-docs / documents /begin_01_project_overview.html
tripolskypetr's picture
patch
d99335f
Raw
History Blame Contribute Delete
16.9 kB
<!DOCTYPE html><html class="default" lang="en" data-base=".."><head><meta charset="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>begin/01_project_overview | 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_01_project_overview.html">begin/01_project_overview</a></li></ul></div><div class="tsd-panel tsd-typography"><a id="project-overview" class="tsd-anchor"></a><h1 class="tsd-anchor-link">Project Overview<a href="#project-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></h1><p>The <strong>news-sentiment-ai-trader</strong> is an automated trading system that leverages Large Language Models (LLMs) to perform sentiment analysis on real-time news data and execute trades based on qualitative market drivers. By integrating news retrieval, AI-driven forecasting, and a robust backtesting framework, the system attempts to capture market movements driven by macroeconomic events, geopolitical shifts, and sector-specific news.</p>
<a id="purpose-and-scope" class="tsd-anchor"></a><h2 class="tsd-anchor-link">Purpose and Scope<a href="#purpose-and-scope" 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><p>The system is designed to bridge the gap between &quot;Natural Language Space&quot; (news articles, Fed announcements, social sentiment) and &quot;Code Entity Space&quot; (trade signals, price candles, order execution). It uses a &quot;swarm&quot; of AI agents to digest complex information into a structured <code>ForecastResponseContract</code>, which is then mapped to trading actions within the <code>backtest-kit</code> framework.</p>
<a id="core-capabilities" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Core Capabilities<a href="#core-capabilities" 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><ul>
<li><strong>Automated News Retrieval</strong>: Fetches and filters news using the Tavily API.</li>
<li><strong>AI Sentiment Engine</strong>: Processes news and market data via Ollama to generate directional forecasts.</li>
<li><strong>Backtesting &amp; Live Execution</strong>: Supports both historical simulation and live trading modes with persistence and risk management.</li>
<li><strong>Strategy Case Studies</strong>: Includes pre-configured strategies like <code>feb_2026_strategy</code> for performance benchmarking.</li>
</ul>
<hr>
<a id="high-level-system-workflow" class="tsd-anchor"></a><h2 class="tsd-anchor-link">High-Level System Workflow<a href="#high-level-system-workflow" 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><p>The following diagram illustrates how news data is transformed into a financial position.</p>
<p><strong>Data Flow: News to Trade</strong>
<img src="../media/01-project-overview_0.svg" alt="Mermaid Diagram"></p>
<hr>
<a id="major-components" class="tsd-anchor"></a><h2 class="tsd-anchor-link">Major Components<a href="#major-components" 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><p>The system is organized into three primary layers:</p>
<a id="1-llm-forecast-engine-logic" class="tsd-anchor"></a><h3 class="tsd-anchor-link">1. LLM Forecast Engine (<code>logic/</code>)<a href="#1-llm-forecast-engine-logic" 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>This module handles the intelligence of the system. It uses <code>agent-swarm-kit</code> to manage specialized advisors that provide the LLM with context. The engine produces a forecast containing a sentiment (bullish, bearish, or neutral), a confidence score, and a detailed reasoning string.</p>
<ul>
<li><strong>Key Entities</strong>: <code>TavilyNewsAdvisor</code>, <code>OllamaOutlineToolCompletion</code>, <code>ForecastResponseContract</code>.</li>
<li><strong>For details, see <a href="begin_04_llm_forecast_engine_logic.html">LLM Forecast Engine (logic/)</a></strong>.</li>
</ul>
<a id="2-trading-strategy-content" class="tsd-anchor"></a><h3 class="tsd-anchor-link">2. Trading Strategy (<code>content/</code>)<a href="#2-trading-strategy-content" 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>Strategies define how forecast data is translated into market positions. For example, the <code>feb_2026_strategy</code> maps LLM sentiment labels to LONG/SHORT signals and manages the position lifecycle using trailing take-profits and hard stop-losses.</p>
<ul>
<li><strong>Key Entities</strong>: <code>POSITION_LABEL_MAP</code>, <code>TRAILING_TAKE</code>, <code>HARD_STOP</code>.</li>
<li><strong>For details, see <a href="begin_09_trading_strategy_feb_2026_strategy.html">Trading Strategy: feb_2026_strategy</a></strong>.</li>
</ul>
<a id="3-execution-framework-backtest-kit" class="tsd-anchor"></a><h3 class="tsd-anchor-link">3. Execution Framework (<code>backtest-kit</code>)<a href="#3-execution-framework-backtest-kit" 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 underlying engine that manages the signal state machine, backtesting logic, and exchange connectivity. It ensures that trades are executed according to the strategy's rules while preventing look-ahead bias during simulations.</p>
<ul>
<li><strong>Key Entities</strong>: <code>Backtest.run()</code>, <code>Live.background()</code>, <code>ccxt-exchange</code>.</li>
<li><strong>For details, see <a href="begin_14_backtest_kit_framework.html">backtest-kit Framework</a></strong>.</li>
</ul>
<hr>
<a id="system-entity-mapping" class="tsd-anchor"></a><h2 class="tsd-anchor-link">System Entity Mapping<a href="#system-entity-mapping" 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><p>This diagram maps the conceptual components to the specific code implementations and files.</p>
<p><strong>System Entity Map</strong>
<img src="../media/01-project-overview_1.svg" alt="Mermaid Diagram"></p>
<hr>
<a id="getting-started" class="tsd-anchor"></a><h2 class="tsd-anchor-link">Getting Started<a href="#getting-started" 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><p>To get the system running, you must configure environment variables for the AI services and use the <code>@backtest-kit/cli</code>.</p>
<ol>
<li><strong>Installation</strong>: Clone the repository and install dependencies via <code>npm install</code>.</li>
<li><strong>Configuration</strong>: Rename <code>.env.example</code> to <code>.env</code> and provide your <code>OLLAMA_TOKEN</code> and <code>TAVILY_TOKEN</code>.</li>
<li><strong>Execution</strong>: Run a backtest using the following command:<pre><code class="bash"><span class="hl-1">npm</span><span class="hl-2"> </span><span class="hl-3">start</span><span class="hl-2"> </span><span class="hl-4">--</span><span class="hl-2"> </span><span class="hl-4">--backtest</span><span class="hl-2"> </span><span class="hl-4">--symbol</span><span class="hl-2"> </span><span class="hl-3">BTCUSDT</span><span class="hl-2"> </span><span class="hl-13">\</span><br/><span class="hl-2"> </span><span class="hl-4">--strategy</span><span class="hl-2"> </span><span class="hl-3">feb_2026_strategy</span><span class="hl-2"> </span><span class="hl-13">\</span><br/><span class="hl-2"> </span><span class="hl-4">--exchange</span><span class="hl-2"> </span><span class="hl-3">ccxt-exchange</span><span class="hl-2"> </span><span class="hl-13">\</span><br/><span class="hl-2"> </span><span class="hl-4">--frame</span><span class="hl-2"> </span><span class="hl-3">feb_2026_frame</span><span class="hl-2"> </span><span class="hl-13">\</span><br/><span class="hl-2"> </span><span class="hl-3">./content/feb_2026.strategy/feb_2026.strategy.ts</span>
</code><button type="button">Copy</button></pre>
</li>
</ol>
<p><strong>For a detailed step-by-step guide, see <a href="begin_02_getting_started_configuration.html">Getting Started &amp; Configuration</a>.</strong></p>
<hr>
<a id="architecture-overview" class="tsd-anchor"></a><h2 class="tsd-anchor-link">Architecture Overview<a href="#architecture-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></h2><p>The system follows a modular architecture where the forecasting logic is decoupled from the trading execution. This allows for swapping LLM models or news providers without modifying the core trading strategy.</p>
<ul>
<li><strong>News Retrieval Layer</strong>: Uses <code>fetchNews</code> with a 24-hour window to ensure only relevant information is processed.</li>
<li><strong>Signal State Machine</strong>: Signals transition through states (idle -&gt; scheduled -&gt; active -&gt; closed) managed by the <code>backtest-kit</code> core.</li>
<li><strong>Persistence</strong>: Live trading state is persisted to <code>data/signals/</code> to allow for crash recovery.</li>
</ul>
<p><strong>For a deep dive into the internal mechanics, see <a href="begin_03_system_architecture_overview.html">System Architecture Overview</a>.</strong></p>
</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="#project-overview"><span>Project <wbr/>Overview</span></a><ul><li><a href="#purpose-and-scope"><span>Purpose and <wbr/>Scope</span></a></li><li><ul><li><a href="#core-capabilities"><span>Core <wbr/>Capabilities</span></a></li></ul></li><li><a href="#high-level-system-workflow"><span>High-<wbr/>Level <wbr/>System <wbr/>Workflow</span></a></li><li><a href="#major-components"><span>Major <wbr/>Components</span></a></li><li><ul><li><a href="#1-llm-forecast-engine-logic"><span>1. LLM <wbr/>Forecast <wbr/>Engine (logic/)</span></a></li><li><a href="#2-trading-strategy-content"><span>2. <wbr/>Trading <wbr/>Strategy (content/)</span></a></li><li><a href="#3-execution-framework-backtest-kit"><span>3. <wbr/>Execution <wbr/>Framework (backtest-<wbr/>kit)</span></a></li></ul></li><li><a href="#system-entity-mapping"><span>System <wbr/>Entity <wbr/>Mapping</span></a></li><li><a href="#getting-started"><span>Getting <wbr/>Started</span></a></li><li><a href="#architecture-overview"><span>Architecture <wbr/>Overview</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>