Transformer-Based Sentiment Analysis and Machine Learning Identification of Retail Investor Herding Behavior under Online Opinion Polarization
Abstract
The increasing significance of financial social media makes online opinion polarization an important determinant of retail investor herding behavior. Detecting retail investor herding behavior necessitates the use of computational methods to extract the stance of investors in unstructured texts and incorporate polarization patterns along with market indicators. In this paper, we propose a machine learning framework consisting of transformer-based financial text classification, quantitative measures of polarization and predictive modeling to detect retail investor herding behavior in China's A-share market. We employ publicly available Eastmoney Guba postings from 2022 to 2025, stock market indicators and small-order fund flows to obtain 28,120 observations at stock-day level across 284 stocks. Chinese RoBERTa-wwm-ext is fine-tuned to predict the three stances (bullish, neutral, and bearish) of investors while opinion polarization is measured with the help of Esteban-Ray index. Herding labels are generated using the absolute deviation convergence and normalized small-order fund flows. XGBoost model is utilized to detect herding behavior incorporating the polarity index, volume of postings, returns, turnovers and volatilities with Logistic Regression and Random Forest as benchmarks. The evaluation results from the simulated test set show that our stance classifier yields an accuracy of 0.895 and Macro-F1 score of 0.896. Our XGBoost model attains an AUC of 0.917 and F1-score of 0.842 whereas eliminating the polarization index decreases the AUC to 0.873.
References
- Cookson, J. A., Engelberg, J. E., & Mullins, W. (2023). Echo chambers.The Review of Financial Studies, 36(2), 450–500.
- Li, T., et al. (2023). Understanding the role of social media sentiment in identifying irrational herding behavior in the stock market.International Review of Economics & Finance, 87, 163–179.
- Chen, Z., & Craig, K. A. (2023). Active attention, retail investor base, and stock returns.Journal of Behavioral and Experimental Finance, 39, 100820.
- Bouteska, A., Cardillo, G., & Harasheh, M. (2023). Is it all about noise? Investor sentiment and risk nexus: Evidence from China.Finance Research Letters, 57, 104197.
- Cookson, J. A., et al. (2024). The social signal.Journal of Financial Economics, 158, 103870.
- Barber, B. M., et al. (2024). A (sub) penny for your thoughts: Tracking retail investor activity in TAQ.The Journal of Finance, 79(4), 2403–2427.
- Warkulat, S., & Pelster, M. (2024). Social media attention and retail investor behavior: Evidence from r/wallstreetbets.International Review of Financial Analysis, 96, 103721.
- Münster, M., Reichenbach, F., & Walther, M. (2024). Robinhood, Reddit, and the news: The impact of traditional and social media on retail investor trading.Journal of Financial Markets, 71, 100929.
- Pyun, C. (2024). Synchronous social media and the stock market.Journal of Financial Markets, 70, 100915.
- Yang, N., Fernandez-Perez, A., & Indriawan, I. (2024). Spillover between investor sentiment and volatility: The role of social media.International Review of Financial Analysis, 96, 103643.
- Hirshleifer, D., Peng, L., & Wang, Q. (2025). News diffusion in social networks and stock market reactions.The Review of Financial Studies, 38(3), 883–937.