Ever seen a stock jump 8% within minutes of a breaking news alert?
That’s sentiment in action.
While traditional strategies focus on price, volume, and indicators — sentiment-based algos try to understand what the market is feeling and react faster than any human possibly can.
In simple words — it’s about figuring out whether the tone of the news, tweets, articles, or announcements is positive, negative, or neutral.
Just like we say, “The vibes are good,” algos try to read market vibes from:
Algos are programmed with Natural Language Processing (NLP) tools. These tools can:
Scan hundreds of headlines in seconds
Understand keywords and tone
Score the sentiment (e.g., +0.8 for very positive, -0.6 for negative)
If a stock gets a sudden wave of positive news, the algo may:
Go long (buy the stock)
Place a tight stoploss (in case it's a false signal)
Exit when the euphoria cools down
Example
Let’s say a big news headline breaks: "Company XYZ bags ₹1,200 crore defence contract"
Algo scans the word “bags,” “₹1,200 crore,” and “defence” → assigns a positive score.
Stock is already up 2% in the pre-market.
Algo:
import pandas as pd import re from datetime import datetime
#---- Example inputs (exactly as described) ---- headline = "Company XYZ bags ₹1,200 crore defence contract" tweets = [ "Big win for $XYZ as it bags massive defence order!", "Volume building up fast. Watching XYZ closely." ]
premarket_change = 0.02 #+2% pre-market volume_spike = True #confirmed tweet_surge = True #confirmed
last_price = 100.0 #mock LTP vwap_now = 100.8 #mock intraday VWAP
#---- Tiny lexicon sentiment scorer (fast + transparent) ---- LEXICON = { "bags": 0.9, "wins": 0.7, "secures": 0.7, "award": 0.6, "order": 0.5, "contract": 0.7, "defence": 0.2, "crore": 0.2, "probe": -0.6, "downgrade": -0.7, "loss": -0.6, "delay": -0.4, "ban": -0.7, "default": -0.9, "fraud": -1.0, "penalty": -0.6 }
def score_text(text: str, lex=LEXICON) -> float: tokens = re.findall(r"[a-zA-Z]+", text.lower()) hits = [lex[t] for t in tokens if t in lex] if not hits: return 0.0 return max(-1.0, min(1.0, sum(hits)/len(hits)))
#---- Sentiment on the provided example ---- news_scores = [score_text(headline)] tweet_scores = [score_text(t) for t in tweets] sentiment = round(pd.Series(news_scores + tweet_scores).mean(), 3)
#---- Trading rule (quick, sentiment-led scalp toward VWAP) ---- POS_THRESH = 0.25 PREMARKET_MIN = 0.02
conditions_ok = ( sentiment >= POS_THRESH and premarket_change >= PREMARKET_MIN and volume_spike and tweet_surge )
if conditions_ok: entry = round(last_price, 2) target = round(min(vwap_now, entry * 1.01), 2) #~1% or VWAP, whichever lower stop = round(entry * 0.985, 2) #~1.5% tight SL action = "BUY" why = f"sentiment={sentiment}≥{POS_THRESH}; premarket={int(PREMARKET_MIN*100)}%+; volume spike; tweet surge" else: action = "NO TRADE" entry = target = stop = None why = "conditions not met"
#---- Output ---- result = { "time": datetime.now().strftime("%Y-%m-%d %H:%M:%S"), "headline": headline, "sentiment": sentiment, "premarket_change_%": round(premarket_change*100, 2), "volume_spike": volume_spike, "tweet_surge": tweet_surge, "action": action, "entry": entry, "target": target, "stop": stop, "vwap_now": vwap_now, "why": why }
print(pd.Series(result))
These trades are usually short-term momentum plays, lasting from a few minutes to an hour.
As a beginner:
For example: “If sentiment score > 0.7 and price > previous day’s high, go long.”
Sentiment algos are often used in event-based trading:
Here, news = trigger, and algos are always listening.
That wraps up our look at popular algo strategies!
Next, we’ll begin Module 6, where we shift from theory to action:
“Let’s Build a Simple Algo!”
Disclaimer: This article is for informational purposes only and does not constitute financial advice. It is not produced by the desk of the Kotak Securities Research Team, nor is it a report published by the Kotak Securities Research Team. The information presented is compiled from several secondary sources available on the internet and may change over time. Investors should conduct their own research and consult with financial professionals before making any investment decisions. Read the full disclaimer here.
Investments in securities market are subject to market risks, read all the related documents carefully before investing. Brokerage will not exceed SEBI prescribed limit. The securities are quoted as an example and not as a recommendation. SEBI Registration No-INZ000200137 Member Id NSE-08081; BSE-673; MSE-1024, MCX-56285, NCDEX-1262.
Disclaimer: This article is for informational purposes only and does not constitute financial advice. It is not produced by the desk of the Kotak Securities Research Team, nor is it a report published by the Kotak Securities Research Team. The information presented is compiled from several secondary sources available on the internet and may change over time. Investors should conduct their own research and consult with financial professionals before making any investment decisions. Read the full disclaimer here.
Investments in securities market are subject to market risks, read all the related documents carefully before investing. Brokerage will not exceed SEBI prescribed limit. The securities are quoted as an example and not as a recommendation. SEBI Registration No-INZ000200137 Member Id NSE-08081; BSE-673; MSE-1024, MCX-56285, NCDEX-1262.
Explore our comprehensive video library that blends expert market insights with Kotak's innovative financial solutions to support your goals.