Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

KSEI Stock Analyzer

An advanced Indonesian stock ownership analyzer that processes KSEI (Kustodian Sentral Efek Indonesia) registry data, calculates institutional ownership ratios, and uses Google Gemini AI to categorize stocks into investment-relevant categories.

Overview

This tool reads raw KSEI text files containing stock ownership breakdown by investor type, enriches the data with calculated analytical ratios, and leverages AI to provide actionable insights about stock characteristics.

Features

  • Automated Ownership Analysis: Calculates six key ownership metrics from raw KSEI data
  • AI-Powered Categorization: Uses Google Gemini to classify stocks into meaningful categories
  • Syariah Compliance Inference: Automatically identifies potentially Sharia-compliant stocks
  • Batch Processing: Handles large datasets with configurable batch sizes and automatic model fallback
  • Excel Export: Produces formatted spreadsheets with insights and raw percentages

Ownership Metrics Calculated

Metric Description
Pct_Retail Speculation indicator (Local ID + Foreign ID)
Pct_Smart_Money Safe haven indicator (Local Pension + Insurance)
Pct_Hot_Money Global macro vulnerability (Foreign PF + MF + IB)
Pct_Strategic_Foreign FDI/foreign parent control (Foreign CP)
Pct_Corp_Treasury Cross-holdings by conglomerates (Local CP)
Pct_Free_Float True free float estimation

Stock Categories

The AI classifies stocks into one of six categories:

  • Strategic Foreign Hold - Stocks with significant foreign corporate control
  • Hot Money Target - Stocks vulnerable to global macro shifts
  • Smart Money Favorite - Stocks favored by pension funds and insurance
  • Retail Casino - Speculative retail-driven stocks
  • Low Float Risk - Illiquid stocks easily cornered
  • Corporate Treasury Spike - Stocks with high cross-ownership

Installation

pip install -r requirements.txt

Required packages:

  • google-genai - Google Gemini API client
  • pandas - Data manipulation
  • openpyxl - Excel file support
  • pydantic - Data validation
  • python-dotenv - Environment variable management

Configuration

Create a .env file in the project root with your Google Gemini API key:

GEMINI_API_KEY=your_api_key_here

Usage

Basic Analysis

python analyzer.py -i Balancepos20260529.txt -o output.xlsx

Analyze Specific Tickers

python analyzer.py -i Balancepos20260529.txt -t ADRO,GOTO,BBRI -o output.xlsx

Force Full Extraction (All Stocks)

python analyzer.py -i Balancepos20260529.txt -a -o output.xlsx

Custom Batch Size

python analyzer.py -i Balancepos20260529.txt -b 100 -o output.xlsx

Command-Line Options

Option Description
-i, --input (Required) Input raw .txt layout path
-o, --output Output Excel file path (default: KSEI_Advanced_Insights.xlsx)
-b, --batch-size Batch size for processing (default: 200)
-t, --tickers Comma-separated list of specific tickers to analyze
-a, --all Force extraction for ALL stocks (skip anomaly filtering)

Input File Format

The tool expects a pipe-delimited (|) text file from KSEI with the following columns:

  • Code (Stock ticker)
  • Type (EQUITY filter applied)
  • Price
  • Local IS/CP/PF/IB/ID/MF and Total
  • Foreign IS/CP/PF/IB/ID/MF and Total

Output

Generates an Excel file with the following columns:

  • Stock Ticker
  • Syariah Compliant (AI Inferred)
  • Insight Category
  • AI Detailed Analysis
  • Price
  • Pct_Retail, Pct_Smart_Money, Pct_Hot_Money, Pct_Strategic_Foreign, Pct_Corp_Treasury, Pct_Free_Float

Data Files

  • Balancepos20260529.txt - Sample KSEI data (May 29, 2025)
  • Mei2026_All.xlsx, Mei2026.xlsx - Excel format data

License

MIT

About

Get insights of stock performance using stocks public data

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages