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.
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.
- 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
| 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 |
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
pip install -r requirements.txtRequired packages:
google-genai- Google Gemini API clientpandas- Data manipulationopenpyxl- Excel file supportpydantic- Data validationpython-dotenv- Environment variable management
Create a .env file in the project root with your Google Gemini API key:
GEMINI_API_KEY=your_api_key_herepython analyzer.py -i Balancepos20260529.txt -o output.xlsxpython analyzer.py -i Balancepos20260529.txt -t ADRO,GOTO,BBRI -o output.xlsxpython analyzer.py -i Balancepos20260529.txt -a -o output.xlsxpython analyzer.py -i Balancepos20260529.txt -b 100 -o output.xlsx| 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) |
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
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
Balancepos20260529.txt- Sample KSEI data (May 29, 2025)Mei2026_All.xlsx,Mei2026.xlsx- Excel format data
MIT