Event-Driven Processing of Market News: From Signals to Risk Alerts
This article explores the engineering approach to processing comprehensive market news, transforming unstructured natural language into computable structured records. It covers the complete pipeline from data collection and cleaning to structured extraction, consistency validation, derived metric calculation, and rule-based alert grading. By implementing this layered architecture, financial systems can reduce information latency, ensure data traceability, and generate reliable risk alerts.
1. Background: Why Market News Needs Engineering Processing
A comprehensive market news article typically contains macroeconomic events, corporate announcements, trading data, and industry dynamics. Published as paragraph text, these contents suffer from inconsistent fields, with values, expectations, and opinions mixed within the same sentence. Relying on manual reading leads to high information latency and makes conclusions difficult to trace. The engineering goal is to break down natural language into computable structured records and feed them into metric calculation and alert processes.
This article uses a sample news item, where specific companies and individuals have been neutralized, retaining only event types, numerical structures, and business implications.
2. Overall Architecture
A layered architecture is recommended, with clearly defined inputs and outputs for each layer:
- Collection Layer: Pulls or receives pushed data from sources, saving raw text, source identifiers, and fetch timestamps.
- Cleaning Layer: Removes template text, normalizes encoding, and splits the entire article into individual items.
- Extraction Layer: Identifies event types, subjects, metrics, values, units, and directions.
- Validation Layer: Checks the logical relationships between values, rejecting inconsistent records.
- Calculation Layer: Computes derived metrics such as period-over-period changes, interval variations, and continuity.
- Alert Layer: Grades, deduplicates, and rate-limits alerts based on rules.
- Storage Layer: Retains both original text and intermediate results to support traceability.
The layers are decoupled via message queues or task queues to prevent fluctuations in the extraction service from affecting collection speed.
3. Collection and Cleaning
3.1 Item Splitting
The sample news uses numbering like “1.”, “2.” to separate items, but comments and tabular data are interspersed between these numbers. When splitting, locate boundaries by sequence numbers first, then apply whitespace removal and length filtering to each segment.
function split_items(raw_text):boundaries = find_positions(raw_text, pattern = "number + enumeration comma or period")items = []for each segment between boundaries:seg = strip_whitespace(segment)if length(seg) >= MIN_ITEM_LENGTH:items.append(seg)return items
MIN_ITEM_LENGTH should be saved as a configuration item. Segments that are too short are usually residual titles or page noise.
3.2 Deduplication Fingerprint
The same news is often reposted multiple times, with differences only in punctuation or whitespace. Calculating a hash of the normalized text can quickly remove exact duplicate records.
function fingerprint(text):normalized = remove_whitespace_and_punctuation(text)normalized = to_lowercase(normalized)return hash_sha256(normalized)
For approximate duplicates that have been rewritten, similarity comparison can be performed, but this is computationally expensive and should be executed after exact deduplication.
4. Structured Extraction
4.1 Data Model
Each event record should contain at least the following fields:
Event {event_id: stringevent_type: enum // e.g., IPO_PRICING, BUYBACK, MARGIN_BALANCE, INDEX_MOVE, OPINIONsubject: string // Neutralized subject, e.g., "A semiconductor enterprise"metric: stringvalue: numberunit: string // e.g., billion CNY, ten thousand people, CNY/sharevalue_type: enum // ACTUAL, FORECAST, PREVIOUSdirection: enum // UP, DOWN, FLAT, UNKNOWNrange_low: number // Lower bound of the interval, null if no intervalrange_high: number // Upper bound of the interval, null if no intervalpublished_at: datetimesource_item_id: stringconfidence: float}
The value_type field is critical. The sample simultaneously contains “actual values”, “estimated values”, and “previous values”. Without differentiation, the calculation layer will treat estimates as actually occurred data.
4.2 Extraction Methods
In practice, it is recommended to use a hybrid of rules and models:
- Values, units, and intervals are extracted using regex rules, providing stable and explainable results.
- Event types are determined using classification models or keyword dictionaries, allowing multi-label classification.
- Sentences containing phrases like “comment”, “believe”, or “worth noting” should be tagged as
OPINIONand excluded from the numerical calculation layer.
4.3 Consistency Validation
After extraction, check whether the values are self-consistent. Taking margin trading balance as an example, the total margin balance equals the sum of the financing balance and the lending balance. If the news only provides the total and the financing balance, the lending balance can be calculated by the difference, which must be non-negative.
function check_margin_balance(total, financing):lending = total - financingif lending < 0:return REJECTreturn ACCEPT
Using the sample data: the total is 22378.30 billion CNY, and the financing balance is 22082.62 billion CNY. The calculated lending balance is approximately 295.68 billion CNY. The result is positive, so the record passes validation.
Another type of validation targets cumulative values. If the news states “a total decrease of 650.35 billion CNY over 4 consecutive trading days,” the sum of the four daily changes should match this value within a tolerance range. If they do not match, it should be flagged for review rather than triggering an alert immediately.
function check_cumulative(daily_changes, reported_total, tolerance):return abs(sum(daily_changes) - reported_total) <= tolerance
5. Derived Metric Calculation
5.1 Interval Revision Ratio
News often presents amounts as intervals, which are later adjusted up or down in subsequent updates. Comparing the midpoints of the intervals is more robust than directly comparing single numbers.
function revision_ratio(old_low, old_high, new_low, new_high):old_mid = (old_low + old_high) / 2new_mid = (new_low + new_high) / 2return (new_mid - old_mid) / old_mid
Taking the buyback plan in the sample as an example: the original plan was 10 to 20 billion CNY (midpoint 15), and the new plan is 25 to 50 billion CNY (midpoint 37.5). The revision ratio is (37.5 - 15) / 15, which is approximately 150%. This value can be directly used for alert grading.
5.2 Consecutive Change Days
When monitoring leverage fund indicators, the focus is often on “consecutive declines” rather than single-day fluctuations. Simply calculate the number of consecutive declining days at the end of the series:
function trailing_decline_streak(series):streak = 0for i from 1 to length(series) - 1:if series[i] < series[i - 1]:streak = streak + 1else:streak = 0return streak
Note that the series must be sorted in ascending order of time. Reverse input will lead to completely wrong conclusions, so a timestamp check should be added at the entry point.
5.3 Price Change Rate
The price change rate should be calculated based on the previous closing price, and intraday prices must be distinguished from closing prices. Descriptions like “surged at one point” or “intraday plunge” in the news should only enter the event text and should not be used as closing price metrics.
6. Alert Grading and Deduplication
6.1 Grading Rules
Thresholds should be stored in configurations and determined through backtesting with historical data. The following are example rules:
function classify_alert(event):if event.event_type == INDEX_MOVE and abs(event.value) >= 2.0:return "P0"if event.event_type == BUYBACK and event.revision_ratio >= 1.0:return "P1"if event.event_type == MARGIN_BALANCE and event.streak >= 3:return "P1"return "P2"
The purpose of grading is to reduce interruptions. P0 should trigger immediate notification, P1 enters the summary channel, and P2 is only stored in the database for retrieval.
6.2 Deduplication Key
When the same event appears multiple times within a short period, it should be merged into a single alert. The deduplication key consists of the event type, subject, and time window:
function dedup_key(event):window = floor_to_interval(event.published_at, 30 minutes)return hash(event.event_type + "|" + event.subject + "|" + window)
The length of the time window determines the deduplication strength. A window that is too long will miss subsequent important updates, while one that is too short will fail to eliminate duplicate reposts.
6.3 Rate Limiting
When the volume of alerts increases abnormally during a certain period, rate limiting should be enabled, and the excess should be summarized into a single digest. The rate limiting logic should record the number of merged alerts for post-event analysis.
7. Quality and Reliability
- Timeliness: The delay from publication to storage should be continuously monitored. If the delay exceeds the threshold, the alert should note that the data may be lagging.
- Accuracy: Regularly sample and compare system extraction results with manual annotations to calculate field-level accuracy. The accuracy requirement for numerical fields should be higher than for text classification fields.
- Traceability: Every alert must be associated with a
source_item_idand the original text snippet for easy review. - Fault Tolerance: When a source fails, the system should switch to a backup source or mark the source data as stale, rather than silently dropping it.
- Version Management: Changes to extraction rules and thresholds should have version numbers, and historical alerts must record the rule version used at that time.
8. Common Pitfalls
- Treating opinions as facts: Sentences following “comment” are the author’s judgments and should be tagged as
OPINION. They cannot participate in numerical calculations. - Confusing units: Billion CNY and ten thousand people cannot be directly compared. Units must be unified or stored in separate tables before entering the database.
- Replacing intervals with averages: Both the upper and lower bounds of an interval should be saved. Averages should only be used temporarily during calculations.
- Ignoring value types: Writing estimated values into the actual value field will distort all subsequent “beat expectations” judgments.
- Relying on a single source: Key values should ideally be cross-validated with a secondary source. If they disagree, they should enter a manual review queue.
9. Practical Checklist
- Store raw text, fetch timestamp, and fingerprint in the database.
- Retain sequence numbers after item splitting for easy location.
- Extraction results must include
value_typeand unit. - Every numerical record must pass consistency validation; failed records enter a review queue.
- Document derived metric formulas and associate them with code versions.
- Determine alert thresholds through historical backtesting and review them periodically.
