top of page

[Trading] Quantitative Stock Selection

Build a diversified stock portfolio using Python, combining multi-factor strategies, web scraping, and optimization techniques for stock selection and performance.

Executive Summary

This project focuses on designing and managing a diversified stock portfolio using Python by mining and analyzing financial data from various online sources. A multi-factor investment strategy was employed, leveraging value, momentum, and quality metrics to optimize portfolio construction. Data was collected through web crawling using BeautifulSoup and Selenium, stored in a MySQL database, and analyzed using techniques such as financial statement analysis and technical analysis with TA-Lib. Portfolio optimization and backtesting were conducted using Riskfolio-Lib and Backtrader, respectively, to ensure robust performance.


Introduction

Objective:The goal of this project was to build a data-driven stock portfolio using Python by analyzing financial and stock data from diverse sources. By leveraging metrics like value, momentum, and quality, the project aimed to create a multi-factor investment strategy to enhance stock selection and portfolio optimization processes.


Market Analysis:

  • The market exhibited caution due to a two-year inverted yield curve, signaling potential economic recessions.

  • Post-COVID-19 monetary policies, including quantitative easing, increased liquidity, but the market remained resilient.

  • This project emphasized data-driven approaches to navigate these conditions and identify investment opportunities.


Data and Methodology

Data Sources:

  • Korean Stock Market Data: Naver Finance, Korean Exchange (KRX), FN Guide

  • Global Stock Market Data: Investing.com, Yahoo Finance (via yfinance and yahooquery)


Methodology:

  1. Data Collection:

    • Web crawling using GET/POST requests with BeautifulSoup and Selenium.

    • Data was consolidated and stored in a MySQL database for structured access.

  2. Key Data Types:

    • Stock prices, financial statements, market sector data, and valuation metrics.

  3. Investment Strategy:

    • Multi-factor portfolio strategy integrating value, momentum, and quality metrics.

    • Technical analysis using TA-Lib for trade timing and trend identification.

    • Z-score computation for sector balance and outlier removal (1st and 99th percentiles).


Investment Strategy

Multi-Factor Portfolio:

  • Combined value, momentum, and quality metrics to select the top 20 stocks.

  • Factor Details:

Factor

Metrics

Quality

Return on Equity (ROE), Gross Profitability (GPA), Cash Flow (CFO)

Value

Price-to-Earnings Ratio (PER), Price-to-Book Ratio (PBR), etc.

Momentum

12-month logarithmic returns, K-Ratio

Technical Analysis:

  • Indicators: Moving averages, RSI, MACD, and Bollinger Bands implemented using TA-Lib.

Portfolio Optimization:

  • Constructed using Riskfolio-Lib, balancing risk and return based on metrics like Sharpe Ratio and Minimum Variance.

Backtesting:

  • Performed using Backtrader, simulating strategies on historical data to evaluate performance.


Results

  • Stock Selection: Successfully identified top-performing stocks based on multi-factor criteria.

  • Model Performance: Demonstrated the robustness of combining value, momentum, and quality factors.

  • Backtesting Outcome: Confirmed the portfolio’s resilience in volatile market conditions.


Future Work

  1. Expand to U.S. Markets: Adapt the model for U.S. stocks using Yahoo Finance and other data sources.

  2. Advanced Risk Management: Implement stop-loss and trailing stop mechanisms to mitigate risks during downturns.

  3. Integrate Machine Learning: Apply predictive models for enhanced stock selection and sentiment analysis using news and social media data.


Conclusion

This project demonstrates the feasibility of using Python for designing a robust investment strategy through data mining and advanced portfolio optimization techniques. By combining financial metrics with quantitative analysis, the project successfully integrates technology and investment principles, providing valuable insights for future market expansions and advanced analytics applications.

This summary is concise, professional, and well-structured, making it suitable for your portfolio website. You can further enhance it with visuals like charts, graphs, or code snippets to make it more engaging.

Project Gallery

bottom of page