Bachelor thesis · 2024 · Swiss Life Asset Managers Recognition Award 2025
Alpha through sentiment analysisAward
Can the sentiment of Swiss newspaper articles be used to adjust the stock weights of a portfolio and beat the SMI?
- newspaper articles on SMI companies, published 2010–2023
- 30,993
- different companies in the SMI over 2010–2023, across 15 index changes
- 29
- language models, GermanFinBERT and GPT-3.5, scored every article and headline
- 2
- annual outperformance over the SMI, out of sample and before costs, Model 1
- +80 bps
In short
Classification trees, trained to forecast from article sentiment whether a stock rises the next day, steered the weights of an SMI portfolio. Out of sample and before costs, both strategies beat the SMI on absolute and risk-adjusted returns. Their daily forecasts, however, were less accurate than always answering “no gain”: article polarity alone does not predict the next day’s move reliably enough to steer the allocation on its own.
(01) · Business understanding
Question
Studies of news sentiment and Swiss stocks are rare, and transformer models had barely been tried on them.
Can transformer-based sentiment analysis of local media articles be used to manage the single-stock allocation of a Swiss equity portfolio tactically and earn an excess return over a benchmark?
Whether news can beat the market is an open question. The efficient-market hypothesis says public information is priced at once; behavioural finance finds sentiment and herding effects (Shiller 2003); the literature has no consensus (Malkiel 2003).
For the US, Fazlija and Harder (2022) report one to two percent a year over the S&P 500, 2011–2016, from a long-short strategy on BERT-classified news. For Switzerland, Schlaubitz (2021) found a significant correlation between the sentiment of cash.ch news and the price moves of Swiss small and mid caps. This thesis asks whether local German-language dailies carry a signal for the blue chips.
The finance is kept simple, so that the signal is the only variable: daily prices, the SMI’s own weights as the neutral position, no costs or liquidity modelled.
T−1 is a control target: if today’s sentiment “predicts” yesterday’s move as well as tomorrow’s, the news is already in the price.
(02) · Data understanding
Data
Three sources, none of them clean: index membership from SIX, articles exported as RTF, prices with 8 gaps.
Index membership
- SIX monthly statistical reports, 2010–2023, provided on request
- A custom parser, adapted as the report layout changed; it ran fully automatically
33 listings
29 companies, 15 index changes
Articles
- Factiva: NZZ, Tages-Anzeiger and Der Bund
- 30,993 articles in RTF batches of up to 100, split by regular expression and cleaned
30,055 articles
after cleaning
Prices
- Yahoo Finance, with investing.com, sharecast and macrotrends as fallbacks
- 8 ISINs without Yahoo data: 4 filled from other sites, 3 from another listing, Synthes dropped
7 of 8 gaps filled
Daily price: the mean of the day's open and close, forward-filled over weekends and holidays
Company mapping
41,066 rows
One row for every company an article names
- 29,934 kept
- 9,435 out of scope: the company was outside the SMI on the publication day
- 1,697 dropped: a feature missing
Analytics base table
29,934 rows
Sentiment, coverage and calendar features, and 8 candidate targets: the price change to T−1, T+1, T+2, T+3, T+4, T+5, T+14, T+30. The best horizon wasn’t known yet, so all of them were carried; T−1 is a control.
Show dataHide data
| Step | Count |
|---|---|
| Index listings | 33 |
| Articles exported | 30,993 |
| Articles after cleaning | 30,055 |
| ISINs without Yahoo data | 8 |
| Rows after the company mapping | 41,066 |
| out of scope: the company was outside the SMI on the publication day | 9,435 |
| dropped: a feature missing | 1,697 |
| Analytics base table | 29,934 |
- Index membership. The SMI’s detailed index constituents history is not public. SIX provided monthly statistical reports on request; their layout changed several times, so the custom parser was adapted to each layout and ran fully automatically. Every change was checked against SIX’s published index changes.
- Company replaced (11)
- Same company, new listing (4)
Show dataHide data
| Month | Out | In | Change |
|---|---|---|---|
| Jun 2010 | Swiss Life | Transocean | company replaced |
| May 2011 | Swiss Re | Swiss Re | new listing |
| Sep 2011 | Lonza | Givaudan | company replaced |
| Jun 2012 | Synthes | Geberit | company replaced |
| Sep 2013 | Richemont | Richemont | new listing |
| Nov 2014 | UBS | UBS Group | new listing |
| Mar 2016 | Transocean | Swiss Life | company replaced |
| May 2017 | Syngenta | Sika | company replaced |
| May 2017 | Actelion | Lonza | company replaced |
| Jun 2018 | Sika | Sika | new listing |
| Apr 2019 | Julius Bär | Alcon | company replaced |
| Sep 2020 | Adecco | Partners Group | company replaced |
| Sep 2021 | Swatch | Logitech | company replaced |
| Sep 2022 | SGS | Sonova | company replaced |
| Jun 2023 | Credit Suisse | Kühne + Nagel | company replaced |
- Articles. The academic Factiva account couldn’t export structured data, only RTF batches of up to 100 articles. RegEx was also used to extract information from the texts, such as date, title and category. Because of the unstructured data and varying layouts, some information, such as category, proved to be unreliable. 239 extracted categories were later remapped to 20 plus “Other” (Figures A1 and A2).
- NZZ
- Tages-Anzeiger
- Der Bund
Show dataHide data
| Company | NZZ | Tages-Anzeiger | Der Bund | Total |
|---|---|---|---|---|
| Credit Suisse | 2,137 | 2,242 | 1,717 | 6,096 |
| UBS | 2,458 | 1,997 | 1,432 | 5,887 |
| Novartis | 953 | 978 | 895 | 2,826 |
| Swisscom | 732 | 949 | 996 | 2,677 |
| Roche | 466 | 500 | 428 | 1,394 |
| Nestlé | 539 | 462 | 342 | 1,343 |
| Swiss Life | 576 | 300 | 210 | 1,086 |
| Holcim | 588 | 260 | 233 | 1,081 |
| Julius Bär | 423 | 324 | 234 | 981 |
| Swatch | 349 | 261 | 283 | 893 |
| Swiss Re | 431 | 235 | 205 | 871 |
| Syngenta | 342 | 226 | 173 | 741 |
| Zurich | 353 | 253 | 111 | 717 |
| Sika | 251 | 235 | 178 | 664 |
| Actelion | 303 | 121 | 104 | 528 |
| ABB | 252 | 158 | 111 | 521 |
| Lonza | 187 | 169 | 135 | 491 |
| Logitech | 211 | 89 | 84 | 384 |
| Geberit | 234 | 51 | 56 | 341 |
| Adecco | 178 | 64 | 94 | 336 |
| Kühne + Nagel | 238 | 46 | 44 | 328 |
| Richemont | 124 | 58 | 48 | 230 |
| Sonova | 87 | 35 | 21 | 143 |
| Transocean | 95 | 24 | 10 | 129 |
| Givaudan | 67 | 16 | 6 | 89 |
| SGS | 58 | 8 | 7 | 73 |
| Partners Group | 47 | 8 | 7 | 62 |
| Alcon | 25 | 12 | 8 | 45 |
| Synthes | 27 | 2 | 7 | 36 |
- Prices. Yahoo Finance returned nothing for 8 ISINs: 4 were filled from investing.com, sharecast or macrotrends, 3 from another listing of the same company, and Synthes had no usable prices anywhere and was dropped. The daily price is the mean of the day's open and close. Weekends and holidays were forward-filled with the last price, because articles also appear while the exchange is closed.
Some series had errors that only showed in the returns.
- Flag
- Every daily return beyond ±40%: 5 moves.
- Check
- Each move was checked by hand against the price series.
- Fix
- Actelion (+1,396,100%) and Sonova (+64.2%) were errors at the start of their series; the prices before the jump were set to the first plausible one.
- Keep
- The other 3, Transocean’s two jumps in June 2020 and Credit Suisse’s fall in March 2023, were real and stayed.
- Analytics base table. Joining the three sources needed one key per company, but a company could appear under several names and ISINs: the name or share class might have changed over the years. Each name was therefore mapped to the ISIN whose prices were used (Figure 4). The result holds one row per article and company it names, 29,934 rows once the out-of-scope and incomplete ones were dropped (Figure 1).
- One to one
- Several names or listings
- Prices from a secondary source
- No price data
Show dataHide data
| Company | SIX name | SIX ISIN | Price ISIN | Note |
|---|---|---|---|---|
| ABB | ABB LTD N | CH0012221716 | CH0012221716 | one name, one ISIN |
| Actelion | ACTELION N | CH0010532478 | CH0010532478 | one name, one ISIN; prices from a secondary source |
| Adecco | ADECCO N | CH0012138605 | CH0012138605 | one name, one ISIN |
| Alcon | ALCON N | CH0432492467 | CH0432492467 | one name, one ISIN |
| Credit Suisse | CS GROUP N | CH0012138530 | CH0012138530 | one name, one ISIN; prices from a secondary source |
| Geberit | GEBERIT N | CH0030170408 | CH0030170408 | one name, one ISIN |
| Givaudan | GIVAUDAN N | CH0010645932 | CH0010645932 | one name, one ISIN |
| Holcim | HOLCIM N · LAFARGEHOLCIM N | CH0012214059 | CH0012214059 | renamed, one ISIN |
| Julius Bär | JULIUS BAER N | CH0102484968 | CH0102484968 | one name, one ISIN |
| Kühne + Nagel | KUEHNE+NAGEL INT N | CH0025238863 | CH0025238863 | one name, one ISIN |
| Logitech | LOGITECH N | CH0025751329 | CH0025751329 | one name, one ISIN |
| Lonza | LONZA N | CH0013841017 | CH0013841017 | one name, one ISIN |
| Nestlé | NESTLE N | CH0038863350 | CH0038863350 | one name, one ISIN |
| Novartis | NOVARTIS N | CH0012005267 | CH0012005267 | one name, one ISIN |
| Partners Group | PARTNERS GROUP N | CH0024608827 | CH0024608827 | one name, one ISIN |
| Richemont | RICHEMONT · RICHEMONT N | CH0045039655 · CH0210483332 | CH0210483332 | two listings, merged onto the current ISIN |
| Roche | ROCHE GS | CH0012032048 | CH0012032048 | one name, one ISIN |
| SGS | SGS N | CH0002497458 | CH0002497458 | one name, one ISIN |
| Sika | SIKA I · SIKA N | CH0000587979 · CH0418792922 | CH0418792922 | share class changed, merged onto the current ISIN |
| Sonova | SONOVA N | CH0012549785 | CH0012549785 | one name, one ISIN |
| Swatch | SWATCH GROUP I | CH0012255151 | CH0012255151 | one name, one ISIN |
| Swiss Life | SWISS LIFE HOLDING AG N · SWISS LIFE HOLDING N | CH0014852781 | CH0014852781 | renamed, one ISIN |
| Swiss Re | SWISS RE HLDG N · SWISS RE N | CH0126881561 · CH0012332372 | CH0126881561 | holding restructure, merged onto the holding's ISIN |
| Swisscom | SWISSCOM N | CH0008742519 | CH0008742519 | one name, one ISIN |
| Syngenta | SYNGENTA N | CH0011037469 | CH0011037469 | one name, one ISIN; prices from a secondary source |
| Synthes | SYNTHES N | US87162M4096 | none | no price data anywhere, dropped |
| Transocean | TRANSOCEAN N | CH0048265513 | CH0048265513 | one name, one ISIN |
| UBS | UBS GROUP N · UBS N | CH0244767585 · CH0024899483 | CH0244767585 · CH0024899483 | prices for both listings, kept apart |
| Zurich | ZURICH FINANCIAL N · ZURICH INSURANCE N | CH0011075394 | CH0011075394 | renamed, one ISIN |
- One row per article. With the mapping in place, the analytics base table became the project’s single store for prediction. Every row is one article about one company and carries everything the models were given: the article’s form, its sentiment scores, the company’s recent coverage and the calendar, next to the price changes to predict. The models read nothing else, so every step downstream starts from this table. Figure 5 lists its columns by group.
Article
What the text looks like and when it appeared.
- length
- content_numeric_rate
- source
- category
- is_trading_day
Sentiment
Polarity of content and headline from both models, and days since the last positive or negative score.
- content_gpt_score
- title_gpt_score
- content_finbert_score
- title_finbert_score
- days_since_{gpt|finbert}_{pos|neg}_{c|t}
Coverage
How much attention the company is getting.
- articles_last_7D
- articles_last_30D
Calendar
Whether the target day is a trading day.
- trading_day_in_t+x
Targets
Price change from today to the horizon, continuous and as a positive/not-positive flag.
- T−1
- T+1 … T+5
- T+14
- T+30
- …_is_pos
(03) · Modelling
Sentiment
Two architectures scored every article and headline. They gave the same label to 35% of articles.
| GermanFinBERT_SC_SentimentA BERT pre-trained from scratch on German financial text, fine-tuned for sentiment on a German translation of the Financial PhraseBank (Scherrmann 2023) | GPT-3.5 TurboOpenAI’s gpt-3.5-turbo-0125, through the paid API (OpenAI n.d.) | |
|---|---|---|
| Architecture | encoder-only (BERT) | decoder-only LLM |
| Output | positive / neutral / negative | zero-shot prompt returning 1 / 0 / −1 |
| Input limit | 512 tokens | 16,385-token context, 4,096 output tokens |
| Run | locally; long articles via a sliding window | API, temperature 0, several articles per call |
GermanFinBERT_SC_Sentiment
A BERT pre-trained from scratch on German financial text, fine-tuned for sentiment on a German translation of the Financial PhraseBank (Scherrmann 2023)
- Architecture
- encoder-only (BERT)
- Output
- positive / neutral / negative
- Input limit
- 512 tokens
- Run
- locally; long articles via a sliding window
GPT-3.5 Turbo
OpenAI’s gpt-3.5-turbo-0125, through the paid API (OpenAI n.d.)
- Architecture
- decoder-only LLM
- Output
- zero-shot prompt returning 1 / 0 / −1
- Input limit
- 16,385-token context, 4,096 output tokens
- Run
- API, temperature 0, several articles per call
FinBERT reads at most 512 tokens, and about 13,000 articles were longer, so they were scored with a custom sliding window approach, after Longformer (Beltagy et al. 2020) and Big Bird (Zaheer et al. 2021), and the window scores averaged (Figure A3).
GPT-3.5 got a zero-shot prompt adapted from Zhang et al. (2023), with several articles per call to keep cost and rate limits down (Cheng et al. 2023; Figure A4).
Batching had a cost: the answers did not always carry a label for every ID sent (Figure A5).
- Check
- Every answer was matched against the IDs sent with it.
- Flag
- No label for about 10% of articles and 1.5% of headlines; their IDs went into a second pass.
- Result
- Still missing after the second pass: under 0.1%, dropped.
Hover or focus a cell. The diagonal is where the two models agree.
- Same label from both models
- 35%
- FinBERT called neutral
- 69%
- GPT-3.5 called neutral
- 19%
- GPT-3.5 scored lower than FinBERT
- about 48%
Show dataHide data
| GPT-3.5 ↓ · FinBERT → | negative | neutral | positive |
|---|---|---|---|
| negative | 14% | 42% | 4% |
| neutral | 2% | 15% | 2% |
| positive | 2% | 12% | 6% |
There was no labelled Swiss data set to judge the two against, so neither could be declared right. Likely causes of the gap: imperfectly transcribed text with typos, which GPT models cope with better (Cao et al. 2023, tested on GPT-4), and special characters that were deliberately left in. So both scores went into the table as features, four polarity scores per article for content and headline, and the predictive models were left to weigh them.
(04) · Modelling
Prediction
Next day looked like the best horizon. The first tuned tree, Model 1, showed why: it split on the calendar, not the news, so Model 2 was trained on trading days only.
- Logistic regression
- Classification tree
* T−1 and T+1 are inflated by non-trading days: forward-filled prices give a zero return that a model can learn from the calendar alone.
Show dataHide data
| Horizon | Accuracy · Logistic | F1 · Logistic | AUC · Logistic | Accuracy · Classification | F1 · Classification | AUC · Classification |
|---|---|---|---|---|---|---|
| T−1 | 0.60 | 0.59 | 0.63 | 0.60 | 0.59 | 0.63 |
| T+1 | 0.69 | 0.65 | 0.78 | 0.69 | 0.65 | 0.79 |
| T+2 | 0.61 | 0.59 | 0.65 | 0.62 | 0.60 | 0.66 |
| T+3 | 0.52 | 0.53 | 0.54 | 0.51 | 0.55 | 0.54 |
| T+4 | 0.52 | 0.54 | 0.54 | 0.51 | 0.60 | 0.53 |
| T+5 | 0.52 | 0.55 | 0.53 | 0.52 | 0.61 | 0.53 |
| T+14 | 0.53 | 0.54 | 0.55 | 0.54 | 0.47 | 0.55 |
| T+30 | 0.53 | 0.55 | 0.55 | 0.54 | 0.52 | 0.55 |
Two classifiers, a logistic regression and a classification tree, learned at each horizon to tell a gain from no gain (Figure 7). Both scored best one day ahead and drifted towards chance, an AUC near 0.50, beyond T+2. The choice fell on the classification tree, which edged out logistic regression by less than a percentage point at T+1 and stays readable. Like every score in Figure 7, it was measured on all calendar days, weekends and holidays included.
Two regressions, a linear one and a regression tree, were also fitted to the price change itself. They explained at most 3.8% of its variance at any horizon. The thesis therefore kept to the binary targets: a gain or no gain leaves out how far the price moves, which the regressions could not capture, while the classifiers reached an AUC well above chance one and two days ahead.
Short-horizon targets were skewed towards “no gain”, so model selection ran on downsampled data. A grid search over 432 combinations tuned the tree, and it landed on the deepest tree the grid allowed (Figure A6).
Model 1 is that tree, trained on all days without resampling. Its first split is on whether tomorrow is a trading day: forward-filled prices make the return over a weekend or holiday exactly zero, so those rows are all “no gain”, and the tree learns them from the calendar alone. The same effect flatters every short horizon in Figure 7.
Model 2 removes it. It keeps trading days only, so a prediction is never made for a day without a price, rebalances the classes and is tuned again. Its in-sample accuracy drops to 0.55, from 0.73 for Model 1, once the calendar no longer helps.
all days, no resampling
- no gain at t+1
- gain at t+1
trading_day_in_t+1 ≤ 0.5
gini 0.413 · 19,157 rows
13,576 no gain · 5,581 gain
leaf
gini 0.000 · 7,550 rows
7,550 no gain · 0 gain
days_since_finbert_pos_t ≤ 4.5
gini 0.499 · 11,607 rows
6,026 no gain · 5,581 gain
Model 1: 7,550 rows where the next day is not a trading day, and every one of them is “no gain”. The first split is the calendar, not the news, and the reason Model 2 drops non-trading days.
In sample: accuracy 0.73 · F1 0.51 · AUC 0.81
(05) · Evaluation
Backtest
Each predicted gain tilted its stock above the SMI’s own weight for the next day, out of sample from August 2020.
The strategy only ever raises weights. A stock the model expects to gain the next day goes above its weight in the SMI; no stock is sold short or dropped, and the others give up weight only because the total stays at 100%. What these tilts earn against the index is the active return (Figure 9).
rA = Σi (wP,i − wB,i) · (ri − rB)
The base weights replicate the SMI’s internal weights, so that only the tilts set the portfolios apart from their benchmark. The official historical weights of the SMI are not publicly available, so they were rebuilt from SIX data.
How the SMI was approximated →
Each day, the weights were set in five steps (Figure 10).
- Base
- Every stock starts at its weight in the rebuilt SMI.
- Signal
- Every article from day t for which the model predicts a gain at t+1 is one positive forecast for its stock.
- Tilt
- The first positive forecast adds the stock’s base weight again, doubling it. Each further one adds 0.9 times what the one before added (Figure A7).
- Rescale
- The weights are scaled back to 100%, so every other stock gives up weight in proportion.
- Hold
- The tilted weights hold for day t+1 only. The next day starts again from the base weights and that day’s forecasts.
A stock’s weight for the next day therefore depends on two things: its weight in the SMI and the number of positive forecasts its articles drew that day. Figure 11 shows how the two play out on an illustrative day.
Base
rebuilt SMI weights, %
- Stock A10%
- Stock B25%
- Stock C25%
- Stock D40%
Tilt
base × multiplier, ● = one positive forecast
- Stock A ●●●37.1
- Stock B ●50
- Stock C25
- Stock D40
Rescale
back to 100%, held for t+1
- Stock A24.4%
- Stock B32.9%
- Stock C16.4%
- Stock D26.3%
Why a decay factor of 0.9: Credit Suisse and UBS had about 6,000 articles each over the period, Givaudan 89. Without decay, a day with many positive forecasts for one bank would swamp the portfolio; with 0.9, the eighth adds 48% of what the first did (Figure A7). The factor is a setting of the strategy, and the result moves with it.
(06) · Conclusion
Answer
Both portfolios beat the SMI out of sample, also on the Sharpe ratio; the thesis answered yes, with a caveat.
Yes. The empirical analysis showed that an investment strategy based on the sentiment of local media articles, used to steer the short-term single-stock allocation, can earn absolute and risk-adjusted excess returns over the benchmark.
These results have to be put into perspective, however, given the models’ out-of-sample accuracy and F1 scores.
They suggest that sentiment analysis alone, at least with the data and methods used in this study, is not enough to deliver reliable forecasts for managing equity portfolios strategically.
| Portfolio | Per year | Over the SMI | Volatility | Sharpe |
|---|---|---|---|---|
| Model 1 | 4.62% | +80 bps | 13.60% | 0.309 |
| Model 2 | 4.24% | +42 bps | 13.48% | 0.284 |
| SMI · benchmark | 3.82% | – | 13.35% | 0.256 |
Both portfolios ran close to the index’s volatility, 13.60% and 13.48% against 13.35%, and both beat it on the Sharpe ratio.
- Model 1
- Model 2
- SMI
Show dataHide data
| Date | Model 1 | Model 2 | SMI |
|---|---|---|---|
| 10 Aug 2020 | 100.00 | 100.00 | 100.00 |
| 25 Sep 2020 | 102.64 | 101.89 | 101.24 |
| 30 Dec 2020 | 106.44 | 105.71 | 106.07 |
| 26 Mar 2021 | 110.23 | 109.87 | 110.17 |
| 25 Jun 2021 | 116.92 | 117.41 | 118.92 |
| 24 Sep 2021 | 112.12 | 112.99 | 117.11 |
| 30 Dec 2021 | 123.92 | 125.65 | 127.60 |
| 25 Mar 2022 | 121.62 | 121.98 | 120.12 |
| 24 Jun 2022 | 106.42 | 107.07 | 107.26 |
| 30 Sep 2022 | 98.23 | 98.97 | 101.75 |
| 30 Dec 2022 | 104.11 | 104.50 | 106.33 |
| 31 Mar 2023 | 108.59 | 109.55 | 110.06 |
| 30 Jun 2023 | 110.23 | 110.02 | 111.79 |
| 29 Sep 2023 | 112.26 | 111.04 | 108.65 |
| 29 Dec 2023 | 113.23 | 111.87 | 110.37 |
| Model | Accuracy in sample | F1 in sample | Accuracy out of sample | F1 out of sample |
|---|---|---|---|---|
| Model 1 · all days, no resampling | 0.73 | 0.51 | 0.49 | 0.44 |
| Model 2 · trading days only, classes rebalanced | 0.55 | 0.55 | 0.48 | 0.50 |
| Always “no gain” | – | – | 0.53 | – |
The thesis named its limits. The in-sample scores were inflated by non-trading days, whose forward-filled prices give a zero return that short-horizon models learn from the calendar alone. The excess return depends on the settings of the strategy and on the horizon. Both portfolios spent spells behind the SMI, about six index points at the deepest, in late 2021, so a different test window could give a different result. And the gap between the approximated and the actual index weights may account for a small part of the variance.
For further work, the thesis proposed four directions:
- Newer language models such as Llama 3 or GPT-4o, benchmarked against earlier studies.
- Aspect-based sentiment classification, for a more precise label for each part of an article.
- Several languages, to compare domestic and foreign sources, and channels beyond newspapers, such as social media, forums and television.
- Macro and company data next to sentiment: GDP forecasts, unemployment, inflation and consumer spending; market capitalisation, quarterly results, sector and sales markets.
(07) · Under the hoodAppendixThe original title, scope and stack, the detail behind each section, and the references.ShowHide
- Original title
- Alpha durch Sentiment-Analyse: Eine empirische Untersuchung der Einsatzfähigkeit von Natural Language Processing zur Steuerung der Einzeltitel-Allokation eines Schweizer Aktienportfolios
- Institution
- Bachelor thesis, HWZ Hochschule für Wirtschaft Zürich, May 2024
- Stack
- Python 3.11 · pandas · scikit-learn · GermanFinBERT · GPT-3.5 Turbo (OpenAI API) · yfinance · Factiva · Jupyter · RegEx · CRISP-DM
In scope
- SMI constituents, refreshed monthly
- NZZ, Tages-Anzeiger and Der Bund
- German-language articles only
- 1 January 2010 to 31 December 2023
- Daily prices in CHF, no intraday view
Left out on purpose
- Multilingual sources
- Intraday data
- Transaction costs and liquidity
- Diversification across asset classes, regions or sectors
- Lexicon-based and vector-based classifiers
| Rule | Threshold | Action | Why |
|---|---|---|---|
| Article length | under 50 characters | dropped | picture captions and teasers for other pages, no information |
| Numeric share of the text | above 0.15 | dropped | tables and figures rather than prose; the cut-off was set by inspecting the outliers |
| Article categories | 239 distinct values | remapped to 20 plus “Other” | title and category were read by position, and the metadata layout varies, so many values were spurious |
| Index removal date | Credit Suisse | corrected to June 2023 | the statistical reports said December 2023; the SIX release and the press said June |
| Non-trading days | weekends and holidays | forward-filled | articles are published while the exchange is closed |
Wirtschaft
Hedge Funds lancieren Sammelklage gegen Novartis
394 words
12 January 2010
Tages Anzeiger
TANZ
German
(c) 2010 Tages Anzeiger Homepage Address: http://www.tages-anzeiger.ch
Document TANZ000020100112e61c0003v
Metadata
Category, title, word count, date and source. The date is found by regular expression because its line moves. Title and category are read by position, which the varying layouts made unreliable; that is why the categories later needed a remap.
Content
Cleaned before scoring: repeated whitespace and line breaks removed, special characters dropped except punctuation, brackets and signs.
Document ID
Every article ends with an ID. It is the split point: one regular expression cuts an RTF batch of up to 100 articles into rows.
Python
PATTERN_ID = r'Document\s[A-Za-z0-9]{20,30}' # find end of article
...
articles_ids = find_pattern(content, PATTERN_ID) # get long IDs as they are deleted in next step
# Check if 100 IDs are detected (most files should have 100)
if len(articles_ids) != 100:
print('[!] ATTENTION | articles detected: {:<4}'.format(str(len(articles_ids))))
additional_tests.append(filepath)
print('[!] ATTENTION | logged for manual testing')
articles = re.split(PATTERN_ID, content) # Divide between articles
articles.pop(-1) # delete rest of .rtf file after last article| Date | Company | Move | Treatment |
|---|---|---|---|
| 5 Jan 2010 | Actelion | +1,396,100% | corrected |
| 8 Feb 2010 | Sonova | +64.2% | corrected |
| 17 Jun 2020 | Transocean | +50.6% | kept |
| 18 Jun 2020 | Transocean | +50% | kept |
| 20 Mar 2023 | Credit Suisse | −53% | kept |
Combined label for this article: (+1 + 0 + 0) / 3 = 0.33, rounded to 0, neutral.
Sentiment Analysis Task
Analyze the sentiment of the following German newspaper articles and predict
the sentiment label for each article individually from the predefined label
space: "positive", "neutral", "negative"
Article Format:
The articles are provided in a JSON format with the following structure:
{{id: article content}}
Your Task:
Please respond with a JSON object in the same format, using the same IDs as
provided in the input.
For each article, assign a sentiment label based on the language and tone used.
If the label is "positive", return 1. If the label is "neutral", return 0.
If the label is "negative", return -1.
Articles to Analyze:
{batch}Python
batch_scores = perform_api_call(prompt=final_prompt, articles_list=batch)
# get the IDs of sent vs returned
id_list_sent = [triplet[0] for triplet in batch]
id_list_returned = [pair[0] for pair in batch_scores]
# 1: Check for missing IDs
for sent_id in id_list_sent:
if sent_id not in id_list_returned:
ids_to_retry.append(sent_id)
# 2: Filter scores for IDs present in both sent and returned lists
for pair in batch_scores:
if pair[0] in id_list_sent:
chatgpt_scores.append(pair)Python
param_grid = {
'max_depth': [3, 4, 5, 6, 7, 8],
'min_samples_split': [500, 1000, 2000, 3000, 4000, 5000],
'min_samples_leaf': [250, 500, 750, 1000, 1500, 2000],
'criterion': ['gini', 'entropy']
}- factor used, f = 0.9
- other factors compared in the thesis
m(n) = 1 + Σk=0n−1 fk
Show dataHide data
| n | f = 0.5 | f = 0.6 | f = 0.7 | f = 0.8 | f = 0.9 (used) | f = 1.0 |
|---|---|---|---|---|---|---|
| 0 | 1.00 | 1.00 | 1.00 | 1.00 | 1.00 | 1.00 |
| 1 | 2.00 | 2.00 | 2.00 | 2.00 | 2.00 | 2.00 |
| 2 | 2.50 | 2.60 | 2.70 | 2.80 | 2.90 | 3.00 |
| 3 | 2.75 | 2.96 | 3.19 | 3.44 | 3.71 | 4.00 |
| 4 | 2.88 | 3.18 | 3.53 | 3.95 | 4.44 | 5.00 |
| 5 | 2.94 | 3.31 | 3.77 | 4.36 | 5.10 | 6.00 |
| 6 | 2.97 | 3.38 | 3.94 | 4.69 | 5.69 | 7.00 |
| 7 | 2.98 | 3.43 | 4.06 | 4.95 | 6.22 | 8.00 |
| 8 | 2.99 | 3.46 | 4.14 | 5.16 | 6.70 | 9.00 |
| 9 | 3.00 | 3.47 | 4.20 | 5.33 | 7.13 | 10.00 |
| 10 | 3.00 | 3.48 | 4.24 | 5.46 | 7.51 | 11.00 |
| 11 | 3.00 | 3.49 | 4.27 | 5.57 | 7.86 | 12.00 |
| 12 | 3.00 | 3.49 | 4.29 | 5.66 | 8.18 | 13.00 |
| 13 | 3.00 | 3.50 | 4.30 | 5.73 | 8.46 | 14.00 |
| 14 | 3.00 | 3.50 | 4.31 | 5.78 | 8.71 | 15.00 |
Model 1 · accuracy 0.49 · F1 0.44
| predicted | ||
|---|---|---|
| no gain | gain | |
| actual no gain | 1,154 | 993 |
| actual gain | 1,065 | 825 |
Model 2 · accuracy 0.48 · F1 0.50
| predicted | ||
|---|---|---|
| no gain | gain | |
| actual no gain | 900 | 1,247 |
| actual gain | 856 | 1,034 |
References
- Beltagy, I., Peters, M. E. & Cohan, A. (2020). Longformer: The Long-Document Transformer (arXiv:2004.05150). arXiv. arxiv.org→
- Cao, Q., Kojima, T., Matsuo, Y. & Iwasawa, Y. (2023). Unnatural Error Correction: GPT-4 Can Almost Perfectly Handle Unnatural Scrambled Text (arXiv:2311.18805). arXiv. arxiv.org→
- Cheng, Z., Kasai, J. & Yu, T. (2023). Batch Prompting: Efficient Inference with Large Language Model APIs (arXiv:2301.08721). arXiv. arxiv.org→
- Fazlija, B. & Harder, P. (2022). Using Financial News Sentiment for Stock Price Direction Prediction. Mathematics, 10(13), 2156. doi.org→
- Malkiel, B. G. (2003). The Efficient Market Hypothesis and Its Critics. Journal of Economic Perspectives, 17(1), 59–82. doi.org→
- Mondello, E. (2015). Portfoliomanagement: Theorie und Anwendungsbeispiele (2., aktualisierte Auflage). Springer Gabler.
- OpenAI. (n.d.). Models—GPT-3.5 Turbo. OpenAI Documentation. Retrieved 12 February 2024. platform.openai.com→
- Scherrmann, M. (2023). German FinBERT: A German Pre-trained Language Model (arXiv:2311.08793). arXiv. arxiv.org→
- Schlaubitz, A. (2021). Natural Language Processing in finance: Analysis of sentiment and complexity of news and earnings reports of swiss SMEs and their relevance for stock returns. doi.org→
- Shearer, C. (2000). The CRISP-DM Model: The New Blueprint for Data Mining. Journal of Data Warehousing, 5(4).
- Shiller, R. J. (2003). From Efficient Markets Theory to Behavioral Finance. Journal of Economic Perspectives, 17(1), 83–104. doi.org→
- Zaheer, M., Guruganesh, G., Dubey, A., Ainslie, J., Alberti, C., Ontanon, S., Pham, P., Ravula, A., Wang, Q., Yang, L. & Ahmed, A. (2021). Big Bird: Transformers for Longer Sequences (arXiv:2007.14062). arXiv. arxiv.org→
- Zhang, W., Deng, Y., Liu, B., Pan, S. J. & Bing, L. (2023). Sentiment Analysis in the Era of Large Language Models: A Reality Check (arXiv:2305.15005). arXiv. arxiv.org→