<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Tanmay Kaper on Medium]]></title>
        <description><![CDATA[Stories by Tanmay Kaper on Medium]]></description>
        <link>https://medium.com/@tanmay.kaper1401?source=rss-397216753879------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*_o-EUViI9i1mMDpj</url>
            <title>Stories by Tanmay Kaper on Medium</title>
            <link>https://medium.com/@tanmay.kaper1401?source=rss-397216753879------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 22:06:18 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tanmay.kaper1401/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Why Generic Sentiment Analysis Doesn’t Work for Trading — and What I Built Instead]]></title>
            <link>https://medium.com/@tanmay.kaper1401/why-generic-sentiment-analysis-doesnt-work-for-trading-and-what-i-built-instead-b6992ae0654a?source=rss-397216753879------2</link>
            <guid isPermaLink="false">https://medium.com/p/b6992ae0654a</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[trading-bot]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[trading-algorithms]]></category>
            <category><![CDATA[sentiment-analysis]]></category>
            <dc:creator><![CDATA[Tanmay Kaper]]></dc:creator>
            <pubDate>Tue, 04 Aug 2026 06:17:04 GMT</pubDate>
            <atom:updated>2026-08-04T06:17:04.459Z</atom:updated>
            <content:encoded><![CDATA[<p>I’ve been building an automated swing-trading system for <strong>NSE stocks</strong> — paper trading only, running daily on <strong>GitHub Actions</strong>. A few weeks ago, I decided to add a news sentiment layer, and my first instinct was to reach for an off-the-shelf tool like <strong>VADER</strong> or <strong>TextBlob</strong>. I’m glad I didn’t.</p><h3>The Problem with Generic Sentiment Lexicons in Finance</h3><p>In 2011, <strong>Loughran and McDonald</strong> published a paper in the <em>Journal of Finance</em> that’s since become foundational in financial NLP. They took the <strong>Harvard-IV General Inquirer</strong> — a standard, widely-used sentiment dictionary at the time — and checked how well its “negative” word list actually held up against real <strong>10-K filings</strong>.</p><blockquote><em>About </em><strong><em>three-quarters</em></strong><em> of the words it flagged as negative weren’t negative at all in a financial context.</em></blockquote><p>Words like <em>“liability,” “tax,” “cost,” “capital,”</em> and even <em>“president”</em> (as in <em>“vice president”</em>) read as bad news in everyday English, but are completely routine vocabulary in business writing. A generic model scoring financial headlines is, in a very literal sense, <strong>scoring the wrong language</strong>.</p><p>So instead of importing a generic library, I built a small sentiment engine from the ground up following the <strong>LM methodology</strong>, creating separate word categories for:</p><ul><li><strong>Negative</strong></li><li><strong>Positive</strong></li><li><strong>Uncertainty</strong></li><li><strong>Litigious</strong> <em>(the category that turned out to matter most)</em></li></ul><h3>Two Free Sources, on Purpose</h3><p>Headlines come from two independent free sources:</p><ol><li><strong>Yahoo Finance’s news feed</strong> <em>(via </em><em>yfinance)</em></li><li><strong>Google News RSS</strong></li></ol><p>No API keys, no paid tiers. Two sources isn’t redundancy for its own sake — I’d already been burned once elsewhere in this project by depending on a single free data source that silently changed its response shape. <strong>If one schema shifts without notice, the other source still covers you.</strong></p><h3>The Negation Bug That Taught Me the Most</h3><p>Early testing threw a sentence at the scorer that should obviously read negative:</p><blockquote>“Quarterly results were not impressive, margins weak.”</blockquote><p>It came back <strong>positive</strong>.</p><ul><li><strong>The Bug:</strong> My negation check looked backward a few words from any sentiment-bearing term to see if a negator preceded it. <em>“Not”</em> was technically within that window of <em>“weak”</em> — it just belonged to a different clause, negating <em>“impressive,”</em> not <em>“weak”</em> at all.</li><li><strong>The Fix:</strong> Scoping negation to <strong>stop at clause boundaries</strong> (commas, <em>“but,”</em> <em>“however”</em>) instead of just counting tokens. A small detail, but it’s exactly the kind of bug that looks fine on easy test sentences and quietly wrecks real headlines.</li></ul><h3>Why One Dramatic Headline Shouldn’t Move the Needle</h3><p>A single very negative headline about a stock with otherwise thin news coverage gets <strong>shrunk toward neutral</strong> before it’s trusted — using <strong>empirical-Bayes shrinkage toward a prior</strong>. This is the same statistical device used elsewhere in the project to stop a small sample of trades from over-swinging a pattern’s calibrated weight.</p><ul><li>A cluster of <strong>five corroborating headlines</strong> gets trusted much more than one.</li><li>Headlines also <strong>decay in relevance</strong>: today’s news outweighs a five-day-old story on an <strong>exponential half-life</strong>, ensuring stale coverage doesn’t linger in the score forever.</li></ul><h3>Two Different Jobs, Kept Separate</h3><p>The sentiment score performs two distinct roles, and I deliberately didn’t collapse them into a single number:</p><ol><li><strong>A Soft Factor:</strong> A small (<strong>10%-weighted</strong>) input into a larger cross-sectional conviction score that also includes <strong>momentum, trend quality, volume, and relative strength</strong>. Mildly positive news nudges conviction up a little. It’s a weak, noisy signal next to price/volume factors with decades of published evidence, and it’s sized accordingly.</li><li><strong>A Hard Veto:</strong> An independent, absolute-threshold check that can <strong>block a trade outright</strong> on a fresh, corroborated cluster of litigious/fraud-flagged headlines — regardless of how good everything else looks. This handles the asymmetric risk a pure price-based system is structurally blind to until the news is already priced into the chart.</li></ol><h3>Where This Fits Into the Bigger Picture</h3><p>The sentiment engine is one of <strong>five layers</strong> a trade candidate has to clear:</p><ol><li><strong>Technical Pattern Scanner</strong></li><li><strong>Fundamental Soft-Gate</strong></li><li><strong>Cross-Sectional Alpha Score</strong></li><li><strong>Sentiment Layer</strong></li><li><strong>Multi-Tier Risk Manager</strong> <em>(portfolio risk budget, sector concentration caps, drawdown circuit breaker)</em></li></ol><p>Every layer can be <strong>independently toggled on or off</strong>, specifically so I can A/B test whether each one is actually contributing anything, instead of just trusting that a sophisticated-sounding feature is helpful.</p><h3>Looking Ahead</h3><p>I’m not going to claim this makes money — the live paper-trading sample is still small, and I’d rather build the validation tooling properly than dress up a handful of trades as a track record. That’s genuinely the more interesting engineering problem anyway: <strong>not <em>“does this sound smart,”</em> but <em>“how do I actually find out.”</em></strong></p><ul><li><strong>Repository (Fully open, MIT licensed):</strong> <a href="https://github.com/tanmaykaper/Paper-Trading-Bot">github.com/tanmaykaper/Paper-Trading-Bot</a></li></ul><p><em>Would genuinely welcome pushback on the lexicon design or the shrinkage constants — still tuning both!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b6992ae0654a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>