

Kotak
Stockshaala
Chapter 5 | 3 min read
अल्गो स्ट्रैटेजी (algo strategy): सेंटिमेंट ड्रिवन ट्रेड्स (sentiment driven trades)
कभी देखा है किसी स्टॉक को 8% बढ़ते हुए जब कोई ब्रेकिंग न्यूज़ अलर्ट आता है?
यह है सेंटिमेंट का असर।
जहां ट्रेडिशनल स्ट्रैटेजीज़ प्राइस, वॉल्यूम, और इंडिकेटर्स पर ध्यान देते हैं — सेंटिमेंट-बेस्ड अल्गोस यह समझने की कोशिश करते हैं कि मार्केट क्या महसूस कर रहा है और किसी इंसान से तेज़ी से रिएक्ट करते हैं।
सेंटिमेंट एनालिसिस (Sentiment Analysis) क्या है?
आसान शब्दों में — यह जानने के बारे में है कि न्यूज़, ट्वीट्स, आर्टिकल्स, या अनाउंसमेंट्स का टोन पॉजिटिव, नेगेटिव, या न्यूट्रल है।
जैसे हम कहते हैं, "वाइब्स अच्छे हैं," अल्गोस मार्केट वाइब्स को पढ़ने की कोशिश करते हैं:
- न्यूज़ वेबसाइट्स
- सोशल मीडिया (जैसे Twitter/X)
- कंपनी अनाउंसमेंट्स
- फोरम्स और ब्लॉग्स
अल्गोस सेंटिमेंट का उपयोग कैसे करते हैं
अल्गोस को नेचुरल लैंग्वेज प्रोसेसिंग (Natural Language Processing, NLP) टूल्स के साथ प्रोग्राम किया जाता है। ये टूल्स कर सकते हैं:
-
सेकंड्स में सैकड़ों हेडलाइन्स स्कैन करें
-
कीवर्ड्स और टोन को समझें
-
सेंटिमेंट को स्कोर करें (उदाहरण के लिए, +0.8 बहुत पॉजिटिव के लिए, -0.6 नेगेटिव के लिए) अगर किसी स्टॉक को अचानक पॉजिटिव न्यूज़ की लहर मिलती है, तो अल्गो कर सकता है:
-
लॉन्ग जाएं (स्टॉक खरीदें)
-
एक टाइट स्टॉपलॉस रखें (अगर यह फॉल्स सिग्नल है)
-
जब उत्साह ठंडा हो जाए तो एग्जिट करें
उदाहरण
मान लीजिए एक बड़ी न्यूज़ हेडलाइन आती है: "कंपनी XYZ ने ₹1,200 करोड़ का डिफेंस कॉन्ट्रैक्ट हासिल किया"
अल्गो "bags," "₹1,200 crore," और "defence" शब्दों को स्कैन करता है → पॉजिटिव स्कोर असाइन करता है।
स्टॉक पहले से ही प्री-मार्केट में 2% ऊपर है।
अल्गो:
- वॉल्यूम में स्पाइक की पुष्टि करता है
- ट्वीट्स में उछाल की पुष्टि करता है
- एक तेज़ ख़रीद ट्रेड ट्रिगर करता है
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))
ये ट्रेड्स आमतौर पर शॉर्ट-टर्म मोमेंटम प्लेज़ होते हैं, जो कुछ मिनटों से लेकर एक घंटे तक चलते हैं।
चुनौतियाँ
- सार्कैज़्म और स्लैंग: अल्गोस के लिए डिटेक्ट करना मुश्किल (जैसे, “वाह, क्या शानदार नुकसान!” नेगेटिव हो सकता है पर पॉजिटिव लगता है)
- फेक न्यूज़: अल्गोस हमेशा विश्वसनीयता नहीं जान सकते
- स्पीड रेस: कई संस्थान यह कर रहे हैं, इसलिए लेटेंसी (स्पीड) बहुत मायने रखती है
इसे सुरक्षित रूप से कैसे उपयोग करें
एक शुरुआत के रूप में:
- सेंटिमेंट इंजन को स्क्रैच से न बनाएं — यह जटिल है
- बेसिक API-बेस्ड सेंटिमेंट डेटा का उपयोग करें (अगर उपलब्ध हो)
- सेंटिमेंट को प्राइस एक्शन या वॉल्यूम कन्फर्मेशन के साथ मिलाएं
उदाहरण के लिए: “अगर सेंटिमेंट स्कोर > 0.7 और प्राइस > पिछले दिन की हाई है, तो लॉन्ग जाएं।”
प्रो टिप
सेंटिमेंट अल्गोस अक्सर इवेंट-बेस्ड ट्रेडिंग में उपयोग होते हैं:
- बजट दिन
- चुनाव परिणाम
- तिमाही आय
- वैश्विक न्यूज़ (जैसे फेड इंटरेस्ट रेट परिवर्तन)
यहां, न्यूज़ = ट्रिगर, और अल्गोस हमेशा सुनते रहते हैं।
इससे हमारा पॉपुलर अल्गो स्ट्रैटेजीज़ पर नजर डालना पूरा होता है!
अगले में, हम मॉड्यूल 6 शुरू करेंगे, जहां हम थ्योरी से एक्शन की ओर बढ़ेंगे:
“चलो एक सिंपल अल्गो बनाएं!”
This content has been translated using a translation tool. We strive for accuracy; however, the translation may not fully capture the nuances or context of the original text. If there are discrepancies or errors, they are unintended, and we recommend original language content for accuracy.
Disclaimer: This article is for informational purposes only and does not constitute financial advice. It is not produced by the desk of the Kotak Neo Research Team, nor is it a report published by the Kotak Neo 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.
Recommended Courses for you
Beyond Stockshaala
Discover our extensive knowledge center
Learn, Invest, and Grow with Kotak Videos
Explore our comprehensive video library that blends expert market insights with Kotak's innovative financial solutions to support your goals.















