Skip to main content

Module sentiment

Module sentiment 

Source
Expand description

§Sentiment: what people are saying, as one number

SD reads price. Sentiment reads people: the analysts who cover a company and the headlines written about it. It is folded into portfolio selection as a modest tie-breaker, not as a driver, for one honest reason: there is no free historical archive of headlines or analyst revisions, so unlike SD it cannot be backtested here. Small weight, clear label, easy to switch off (SENTIMENT_WEIGHT=0).

Four signals, each squeezed into [-1, 1]:

SignalSourceIdea
Analyst tiltNasdaq consensus (buy / hold / sell counts)(buys − sells) ÷ analysts
Revision momentumNasdaq monthly consensus historyis the buy share rising over 3 months?
Target upsideNasdaq mean price targettanh(upside ÷ 25%); targets run optimistic, so lightly weighted
Headline toneYahoo Finance RSS (recent headlines)finance word lists: “beats”, “upgrade” vs “miss”, “probe”
  raw   = 0.35·tilt + 0.25·revision + 0.15·upside + 0.25·news
  score = 0.5 + 0.5 · raw · confidence      (confidence grows with coverage)

A stock nobody covers lands at 0.5, neutral, rather than being punished or rewarded for silence.

Structs§

Cache
A day-scoped cache so re-runs on the same day do not refetch.
Sentiment

Functions§

fetch
Fetch and score sentiment for a US-listed symbol at price.
text_tone
Tone of one piece of text in [-1, 1], or None if it has no tone words.