<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Davis Wang</title>
    <description>The latest articles on DEV Community by Davis Wang (@davis_wang).</description>
    <link>https://dev.to/davis_wang</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3895032%2F6b8adcf9-c251-4e69-9d1a-3638c8a39160.png</url>
      <title>DEV Community: Davis Wang</title>
      <link>https://dev.to/davis_wang</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/davis_wang"/>
    <language>en</language>
    <item>
      <title>How I built an AI stock trading system with Claude API (open source)</title>
      <dc:creator>Davis Wang</dc:creator>
      <pubDate>Fri, 24 Apr 2026 17:08:18 +0000</pubDate>
      <link>https://dev.to/davis_wang/how-i-built-an-ai-stock-trading-system-with-claude-api-open-source-5eli</link>
      <guid>https://dev.to/davis_wang/how-i-built-an-ai-stock-trading-system-with-claude-api-open-source-5eli</guid>
      <description>&lt;p&gt;I spent the last few days building a semi-automated stock analysis &lt;br&gt;
system powered by Claude AI. Here's what I built and how it works.&lt;/p&gt;
&lt;h2&gt;
  
  
  The Problem
&lt;/h2&gt;

&lt;p&gt;Most retail traders make emotional decisions. I wanted to build &lt;br&gt;
something that combines the pattern-recognition of technical analysis &lt;br&gt;
with the reasoning ability of a large language model — and forces both &lt;br&gt;
to agree before making any move.&lt;/p&gt;
&lt;h2&gt;
  
  
  System Architecture
&lt;/h2&gt;

&lt;p&gt;The system has 7 core modules:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Stock Scanner&lt;/strong&gt; — scans 14 tech stocks daily, filters by RSI, MA20, MA50, volume&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Strategy Engine&lt;/strong&gt; — generates rule-based signals (BUY / WATCHLIST_BUY / HOLD / SELL)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;News Service&lt;/strong&gt; — fetches real-time news via yfinance, scores relevance&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Claude AI Analyzer&lt;/strong&gt; — independently evaluates each candidate stock&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Decision Engine&lt;/strong&gt; — combines rule signal + AI signal with confidence thresholds&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Risk Manager&lt;/strong&gt; — enforces stop loss (5%), take profit (10%), max hold days (10)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Memory System&lt;/strong&gt; — feeds historical performance back to Claude on each run&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  The Dual Signal Engine
&lt;/h2&gt;

&lt;p&gt;The key insight: neither pure technical analysis nor pure AI is reliable alone.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Only BUY when both agree
&lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;rule_signal&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;WATCHLIST_BUY&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;ai_signal&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;BUY&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;confidence&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Medium&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;final_action&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;BUY&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This filters out most false positives.&lt;/p&gt;

&lt;h2&gt;
  
  
  Memory System
&lt;/h2&gt;

&lt;p&gt;Claude has no memory between API calls. So I built an external memory &lt;br&gt;
layer that summarizes recent performance and injects it into every prompt:&lt;br&gt;
System Memory (last 14 days):&lt;br&gt;
NVDA: RSI&amp;gt;85 observed 12 times without SELL trigger — pullback risk elevated&lt;br&gt;
AAPL: WATCHLIST_BUY + AI HOLD pattern occurred 3 times — low conviction setup&lt;/p&gt;

&lt;p&gt;This makes Claude's analysis context-aware over time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Real Output Example
&lt;/h2&gt;

&lt;p&gt;=== Stock Scanner ===&lt;br&gt;
[WATCHLIST_BUY] AAPL @ $273 | RSI=67 | Score=3&lt;br&gt;
[WATCHLIST_BUY] CRM  @ $189 | RSI=53 | Score=3&lt;br&gt;
Analyzing CRM...&lt;br&gt;
Rule Signal: WATCHLIST_BUY | AI Signal: BUY | Confidence: Medium&lt;br&gt;
Final Action: BUY&lt;br&gt;
[SIMULATED BUY] CRM x5.27 @ $189.80 = $1000&lt;/p&gt;

&lt;h2&gt;
  
  
  Tech Stack
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Python 3.11&lt;/li&gt;
&lt;li&gt;Anthropic Claude API (claude-sonnet-4-6)&lt;/li&gt;
&lt;li&gt;yfinance for price data and news&lt;/li&gt;
&lt;li&gt;Custom news relevance scoring algorithm&lt;/li&gt;
&lt;li&gt;schedule for automated daily runs&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Results So Far
&lt;/h2&gt;

&lt;p&gt;Running in simulation mode with $10,000 virtual capital. &lt;br&gt;
The system correctly identified CRM before a 1.4% gain and avoided &lt;br&gt;
NVDA when RSI hit 91 (extreme overbought).&lt;/p&gt;

&lt;h2&gt;
  
  
  Links
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;GitHub (open source): &lt;a href="https://github.com/Davis-code1126/ai-stock-trading-claude" rel="noopener noreferrer"&gt;https://github.com/Davis-code1126/ai-stock-trading-claude&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Beginner setup guide + starter pack ($5): &lt;a href="https://davisphere42.gumroad.com/l/ai-stock-system-starter-pack" rel="noopener noreferrer"&gt;https://davisphere42.gumroad.com/l/ai-stock-system-starter-pack&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Happy to answer questions about the Claude API integration or the &lt;br&gt;
decision engine logic!&lt;/p&gt;

</description>
      <category>ai</category>
      <category>python</category>
      <category>claude</category>
      <category>algotrading</category>
    </item>
  </channel>
</rss>
