What We’re Building

A Python-based Korean stock screener that:

  • Pulls data from KRX via pykrx
  • Filters stocks by multiple criteria (PER, PBR, volume)
  • Exports results to CSV
  • Can be automated with GitHub Actions

Setup

pip install pykrx pandas

Complete Screener Code

from pykrx import stock
import pandas as pd
from datetime import datetime, timedelta

class KoreanStockScreener:
    def __init__(self, market="KOSPI"):
        self.market = market
        self.today = datetime.now().strftime("%Y%m%d")
    
    def get_all_data(self):
        fundamentals = stock.get_market_fundamental_by_ticker(
            self.today, market=self.market
        )
        market_cap = stock.get_market_cap_by_ticker(
            self.today, market=self.market
        )
        df = pd.concat([fundamentals, market_cap[["시가총액", "거래량"]]], axis=1)
        df["name"] = [stock.get_market_ticker_name(t) for t in df.index]
        return df
    
    def screen(self, max_per=15, max_pbr=1.5, min_div=2.0, min_volume=100000):
        df = self.get_all_data()
        filtered = df[
            (df["PER"] > 0) & (df["PER"] < max_per) &
            (df["PBR"] > 0) & (df["PBR"] < max_pbr) &
            (df["DIV"] > min_div) &
            (df["거래량"] > min_volume)
        ]
        return filtered[["name", "PER", "PBR", "DIV", "시가총액", "거래량"]]
    
    def export(self, df, filename="screener_results.csv"):
        df.to_csv(filename, encoding="utf-8-sig")
        print(f"Saved {len(df)} stocks to {filename}")

# Run screener
screener = KoreanStockScreener(market="KOSPI")
results = screener.screen(max_per=12, max_pbr=1.2, min_div=3.0)
print(results.head(20))
screener.export(results)

Automating with GitHub Actions

Create .github/workflows/screener.yml:

name: Korean Stock Screener

on:
  schedule:
    - cron: '0 7 * * 1-5'  # 4PM KST weekdays
  workflow_dispatch:

jobs:
  screen:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-python@v4
        with:
          python-version: '3.11'
      - run: pip install pykrx pandas
      - run: python screener.py
      - uses: actions/upload-artifact@v3
        with:
          name: screener-results
          path: screener_results.csv