finvader 0.1.0

Finance-aware sentiment analysis for Rust — VADER extended with a financial lexicon, phrase rules, and catalyst detection for news headlines and market text
Documentation
//! Multi-word financial phrases with valences on VADER's -4.0..=4.0 scale.
//!
//! Phrases are matched before single words and consume their text, so a
//! match on "record revenue" does not also count the single word "record".
//! Entries are stored padded with spaces for boundary-safe substring
//! matching against the normalized text.

/// (phrase, valence). Phrases must be lowercase; hyphens allowed.
pub const PHRASES: &[(&str, f64)] = &[
    // earnings vs expectations (verb+object pairs live in GAP_PHRASES)
    ("better than expected", 2.6),
    ("better-than-expected", 2.6),
    ("worse than expected", -2.6),
    ("worse-than-expected", -2.6),
    ("above consensus", 2.2),
    ("below consensus", -2.2),
    ("fell short", -2.4),
    ("falls short", -2.4),
    ("beat and raise", 3.6),
    // guidance & outlook (verb+object pairs live in GAP_PHRASES)
    ("guidance raised", 3.2),
    ("guidance cut", -3.4),
    ("profit warning", -3.0),
    // records & highs
    ("record revenue", 3.0),
    ("record earnings", 3.0),
    ("record profit", 3.0),
    ("record quarter", 2.8),
    ("record sales", 2.8),
    ("record high", 2.2),
    ("all-time high", 2.4),
    ("all time high", 2.4),
    ("new highs", 1.8),
    ("52-week high", 1.8),
    ("52-week low", -1.8),
    // profitability & margins
    ("margin expansion", 2.4),
    ("margin expanded", 2.4),
    ("margins expanded", 2.4),
    ("margin compression", -2.2),
    ("margins compressed", -2.2),
    ("eps acceleration", 2.6),
    ("revenue acceleration", 2.6),
    ("swings to profit", 2.4),
    ("swung to profit", 2.4),
    ("turns profitable", 2.4),
    ("swings to loss", -2.4),
    ("posts loss", -2.0),
    ("posted a loss", -2.0),
    // market position
    ("market share gains", 2.2),
    ("gaining market share", 2.2),
    ("losing market share", -2.2),
    ("market share losses", -2.2),
    ("design win", 2.6),
    ("design wins", 2.6),
    ("contract win", 2.6),
    ("wins contract", 2.6),
    ("won a contract", 2.4),
    ("contract award", 2.4),
    ("awarded contract", 2.6),
    ("government contract", 2.2),
    ("defense contract", 2.2),
    ("dod contract", 2.2),
    ("demand exceeds supply", 2.4),
    ("supply constraints", -1.2),
    ("supply glut", -2.0),
    ("inventory correction", -1.8),
    ("inventory glut", -2.0),
    ("consecutive quarter", 1.2),
    // capital returns & structure (verb+object pairs live in GAP_PHRASES)
    ("dividend increase", 2.0),
    ("dividend cut", -3.0),
    ("dividend suspension", -3.4),
    ("share buyback", 2.0),
    ("buyback program", 2.0),
    ("share repurchase", 2.0),
    ("stock split", 1.2),
    ("reverse split", -2.0),
    ("capital raise", -1.0),
    ("secondary offering", -1.4),
    ("share dilution", -1.8),
    // flow & positioning
    ("short squeeze", 1.8),
    ("insider buying", 2.2),
    ("insider purchases", 2.2),
    ("insider selling", -1.0),
    ("cluster buying", 2.4),
    ("open market purchase", 2.2),
    // analyst targets
    ("price target raised", 2.4),
    ("raises price target", 2.4),
    ("price target cut", -2.2),
    ("cuts price target", -2.2),
    // legal / accounting / distress
    ("sec investigation", -3.2),
    ("sec charges", -3.4),
    ("doj investigation", -3.0),
    ("accounting irregularities", -3.4),
    ("accounting fraud", -3.8),
    ("going concern", -3.6),
    ("chapter 11", -3.8),
    ("chapter 7", -3.8),
    ("class action", -2.0),
    ("data breach", -2.2),
    ("cyber attack", -2.2),
    ("cyberattack", -2.2),
    ("trading halted", -2.0),
    ("auditor resigns", -3.2),
    ("ceo resigns", -1.8),
    ("cfo resigns", -2.2),
    ("ceo departure", -1.4),
    // deals & index events
    ("to be acquired", 2.6),
    ("acquired at a premium", 2.8),
    ("takeover bid", 2.2),
    ("buyout offer", 2.2),
    ("merger agreement", 1.8),
    ("strategic partnership", 2.0),
    ("partnership with", 1.6),
    ("joint venture", 1.2),
    ("s&p 500 inclusion", 2.4),
    ("added to s&p", 2.4),
    ("joins s&p", 2.4),
    ("index inclusion", 2.2),
    ("removed from s&p", -2.4),
    ("index removal", -2.2),
    // biotech / regulatory catalysts
    ("fda approval", 3.0),
    ("fda approves", 3.0),
    ("fda approved", 3.0),
    ("fda clearance", 2.6),
    ("fda rejects", -3.2),
    ("fda rejection", -3.2),
    ("complete response letter", -3.0),
    ("breakthrough therapy", 2.8),
    ("fast track designation", 2.2),
    ("met primary endpoint", 3.0),
    ("missed primary endpoint", -3.4),
    ("failed primary endpoint", -3.4),
    ("positive phase 3", 2.8),
    // macro
    ("rate cut", 1.4),
    ("rate cuts", 1.4),
    ("rate hike", -1.0),
    ("rate hikes", -1.2),
    ("soft landing", 1.6),
    ("hard landing", -2.4),
];

/// Gap-tolerant verb+object pairs: `(lead, tail, valence)`.
///
/// Headlines routinely insert tokens between the verb and its object —
/// "beats **Q3** expectations", "raises **full-year** guidance", "missed
/// **fourth quarter** estimates" — so these match with up to two tokens
/// between lead and tail.
pub const GAP_PHRASES: &[(&str, &str, f64)] = &[
    // expectations
    ("beat", "expectations", 2.8),
    ("beats", "expectations", 2.8),
    ("exceeded", "expectations", 2.8),
    ("exceeds", "expectations", 2.8),
    ("topped", "expectations", 2.7),
    ("miss", "expectations", -2.8),
    ("misses", "expectations", -2.8),
    ("missed", "expectations", -2.8),
    // estimates
    ("beat", "estimates", 2.6),
    ("beats", "estimates", 2.6),
    ("topped", "estimates", 2.6),
    ("tops", "estimates", 2.6),
    ("miss", "estimates", -2.6),
    ("misses", "estimates", -2.6),
    ("missed", "estimates", -2.6),
    // guidance
    ("raises", "guidance", 3.2),
    ("raised", "guidance", 3.2),
    ("raising", "guidance", 3.2),
    ("cut", "guidance", -3.4),
    ("cuts", "guidance", -3.4),
    ("lowers", "guidance", -3.2),
    ("lowered", "guidance", -3.2),
    ("withdraws", "guidance", -3.0),
    ("withdrew", "guidance", -3.0),
    ("suspends", "guidance", -3.0),
    ("suspended", "guidance", -3.0),
    // outlook
    ("raises", "outlook", 3.0),
    ("raised", "outlook", 3.0),
    ("cut", "outlook", -3.2),
    ("cuts", "outlook", -3.2),
    ("lowers", "outlook", -3.0),
    ("lowered", "outlook", -3.0),
    // dividend
    ("raises", "dividend", 2.2),
    ("raised", "dividend", 2.2),
    ("hikes", "dividend", 2.2),
    ("increases", "dividend", 2.0),
    ("increased", "dividend", 2.0),
    ("cut", "dividend", -3.0),
    ("cuts", "dividend", -3.0),
    ("suspends", "dividend", -3.4),
    ("suspended", "dividend", -3.4),
];