Upload 2 files
Browse files- Project_1_Financial_News.ipynb +0 -0
- README.md +68 -0
Project_1_Financial_News.ipynb
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
README.md
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Financial headlines, topics, and large price moves
|
| 2 |
+
|
| 3 |
+
**Question:** How do headline language and topics relate to unusually large subsequent price moves, and how stable is that relationship across time?
|
| 4 |
+
|
| 5 |
+
Start with the [HTML report](Project_1_Financial_News.html) or [executed notebook](Project_1_Financial_News.ipynb). The [course alignment guide](COURSE_ALIGNMENT.md) explains the assignment connections and provides a seven-slide presentation outline.
|
| 6 |
+
|
| 7 |
+
## Supplied lesson code and this revision
|
| 8 |
+
|
| 9 |
+
The Box notebook has the same 255 cell sources as the earlier supplied notebook. The dataset already matches its published labeled news dataset. The project now directly reuses the instructor's financial sentiment analyzer in `course_baseline.py`, reports its direction baseline on the original partitions, and then presents the Project 1 extensions separately. Preprocessing adaptations are documented; the baseline is not claimed to exactly reproduce the instructor's saved scores.
|
| 10 |
+
|
| 11 |
+
See [lesson-to-project mapping](LESSON_TO_PROJECT.md), [adapted baseline metrics](outputs/course_baseline_metrics.csv), and [original source partitions](outputs/course_original_splits.csv). The direction baseline and magnitude extension use different targets and partitions, so their scores are not an improvement comparison.
|
| 12 |
+
|
| 13 |
+
The revised presentation is [Project_1_Course_Aligned_Presentation.pptx](presentation/Project_1_Course_Aligned_Presentation.pptx), with the [five-minute script](presentation/Five_Minute_Speaker_Script.md). It supersedes the earlier presentation. Present slides 1–7; slides 8–11 are backups.
|
| 14 |
+
|
| 15 |
+
## Data and target
|
| 16 |
+
|
| 17 |
+
The attached `../news_data.csv` contains individual headlines without return labels; it supports the raw-data audit. Supervised experiments use the public, labeled stock-day dataset referenced in [the supplied lesson notebook](../L1_NLP_Sentiment_Analysis_Classifier.ipynb): [firobeid/SP_DOW_NASDAQ_stocks__News_Headlines_labeled](https://huggingface.co/datasets/firobeid/SP_DOW_NASDAQ_stocks__News_Headlines_labeled/tree/35600ba11de0aa4de6a4d580c3e27dfcaa396677), pinned to revision `35600ba11de0aa4de6a4d580c3e27dfcaa396677`. Download URLs and SHA-256 hashes are recorded in [source_manifest.json](data/source_manifest.json). The two sources have different units and coverage; their row counts are not interchangeable.
|
| 18 |
+
|
| 19 |
+
The target changes from the lesson's return **direction** to **magnitude**: class 1 means `abs(returns) > 0.02`; class 0 includes exactly 2% and smaller moves. This threshold is fixed before evaluation. The outcome uses supplied returns, not labels reconstructed from the unlabeled CSV.
|
| 20 |
+
|
| 21 |
+
Cleaning normalizes HTML entities and whitespace, removes invalid records, keeps one document per ticker/date, and retains only the earliest occurrence of each normalized full document. Return, price, ticker, and original partition fields are excluded from predictors.
|
| 22 |
+
|
| 23 |
+
## Experiments and evaluation
|
| 24 |
+
|
| 25 |
+
The original partitions are combined and replaced with whole-date chronological windows:
|
| 26 |
+
|
| 27 |
+
| Dataset | Document dates |
|
| 28 |
+
|---|---|
|
| 29 |
+
| Train | Before March 25, 2020 |
|
| 30 |
+
| Test | April 1–June 23, 2020 |
|
| 31 |
+
| Inference | July 1, 2020 onward |
|
| 32 |
+
|
| 33 |
+
March 25–31 and June 24–30 are omitted. Model selection uses validation beginning February 1 within training; development fitting ends before January 25, leaving January 25–31 as another gap. These seven-calendar-day gaps are approximate precautions, not guarantees about unknown outcome horizons.
|
| 34 |
+
|
| 35 |
+
Five predetermined models are compared: majority-class dummy; Loughran–McDonald category rates, tone, and length with logistic regression; word-unigram TF-IDF with Naive Bayes; character 3–5-gram TF-IDF with Naive Bayes; and the same character representation with logistic regression. Validation macro-F1 selects the model, with balanced accuracy breaking ties. Models are refitted on full training data; the classification threshold remains 0.5. Held-out results do not change selection.
|
| 36 |
+
|
| 37 |
+
HW1 is represented through financial lexicon coverage and tone analysis. HW2 is represented through a **fresh NMF baseline**; no completed HW2 notebook was supplied. NMF fits eight topics on at most 20,000 sampled training documents, with up to 6,000 word/bigram features. Held-out documents use those fitted topics. Keywords, representative documents, topic frequencies, sentiment, and classification errors support interpretation; topic IDs are not ground-truth categories.
|
| 38 |
+
|
| 39 |
+
## Results and files
|
| 40 |
+
|
| 41 |
+
Validation selected **character TF-IDF with Naive Bayes**. Its macro-F1 is **0.612 on train, 0.500 on test, and 0.522 on inference**. On inference, macro-F1 exceeds the majority baseline's 0.419, but accuracy is lower (70.1% versus 72.2%) and large-move recall is only 16.0%. The evidence supports a weak retrospective signal, not a reliable forecasting system. See [results interpretation](RESULTS_INTERPRETATION.md) for presentation-ready explanations of these tradeoffs.
|
| 42 |
+
|
| 43 |
+
- [Computed findings](outputs/computed_findings.md): conclusions generated from the actual run.
|
| 44 |
+
- [Model metrics](outputs/model_metrics.csv), [validation metrics](outputs/validation_metrics.csv), and [split counts](outputs/split_summary.csv).
|
| 45 |
+
- [Topic keywords](outputs/topic_keywords.csv), [topic metrics](outputs/topic_metrics.csv), and [inference errors](outputs/inference_errors.csv).
|
| 46 |
+
- [Figures](outputs/figures/) and [run metadata](outputs/run_metadata.json).
|
| 47 |
+
|
| 48 |
+
The notebook reports accuracy, balanced accuracy, macro-F1, large-move precision/recall, ROC-AUC, and average precision. Training scores are in-sample diagnostics. “Inference” is a later labeled historical holdout, not live unlabeled news.
|
| 49 |
+
|
| 50 |
+
## Reproduce
|
| 51 |
+
|
| 52 |
+
Use Python 3.12. Keep `news_data.csv` and `Loughran-McDonald_MasterDictionary_1993-2024.csv` in the parent folder. Course PDFs and the lesson notebook are references, not runtime dependencies.
|
| 53 |
+
|
| 54 |
+
From this `project1` folder, in PowerShell:
|
| 55 |
+
|
| 56 |
+
```powershell
|
| 57 |
+
python -m venv .venv
|
| 58 |
+
.\.venv\Scripts\Activate.ps1
|
| 59 |
+
python -m pip install -r requirements.txt
|
| 60 |
+
python fetch_course_data.py
|
| 61 |
+
python execute_notebook.py
|
| 62 |
+
```
|
| 63 |
+
|
| 64 |
+
On macOS/Linux, activate with `source .venv/bin/activate` instead. Downloading public data requires internet access but no Hugging Face token. Execution writes notebook outputs, HTML, figures, and result tables. `build_notebook.py` is an optional source generator: running it **erases the notebook's saved outputs** until execution completes again.
|
| 65 |
+
|
| 66 |
+
## Interpretation limits
|
| 67 |
+
|
| 68 |
+
Daily headline timing, timezone, outcome construction, and price-adjustment metadata are not fully verified; after-close text may overlap the outcome interval. Source filtering already removes some extreme returns. Repeated stories may remain despite full-document deduplication. The 1993–2024 dictionary postdates the news sample and provides estimated tone, not human sentiment labels. Topic assignments are exploratory and model scores uncalibrated. Results describe retrospective associations; they establish neither causality nor trading profitability.
|