Welcome to the Finlatics Financial Analyst & Quantitative Portfolio System repository. This project is a comprehensive toolkit designed to automate the collection, preprocessing, screening, and quantitative ranking of stocks from the BSE 500 index. Built during the Finlatics Financial Analyst program, it combines web scraping pipelines (Selenium & BeautifulSoup), API integrations (Yahoo Finance), and a multi-factor ranking model to construct daily stock watchlists and priority investment recommendations.
In addition to the software engineering components, this repository houses several high-grade financial research deliverables, valuation models, and program credentials.
The repository is organized into a clean and structured directory layout:
├── data/ # Historical daily CSV datasets from the BSE 500 universe
├── Watchlists/ # Output directory for daily screened Watchlists & Ranked Stocks
├── src/ # Core Python modules and scraper scripts
│ ├── datascraping.py # Dhan BSE 500 company list fetcher
│ ├── scrapegroww.py # Selenium browser automator for Groww fundamentals
│ ├── scrapeEPS.py # BeautifulSoup scraper for Moneycontrol EPS
│ ├── scrapePE.py # Selenium scraper for Groww P/E Ratio
│ ├── scrapeROE.py # Selenium scraper for Groww ROE
│ ├── yfdata.py # Yahoo Finance API data extractor
│ ├── mappingStockUrl.py # GROWW URL mapper utility
│ ├── spstock.py # Quantitative scoring and ranking algorithms
│ ├── EDA.ipynb # Interactive Exploratory Data Analysis & pipeline prototyping
│ └── EDA.py # Local data cleaning and testing script
├── reports/ # Strategic financial research, DCF models, and program certificates
│ ├── DCF_MVS.xlsx # Dynamic Discounted Cash Flow (DCF) valuation spreadsheet
│ ├── 921475_report.pdf # Program graduation thesis / final research summary
│ ├── 921475_certificate.pdf # Finlatics graduation credentials
│ └── ... # Strategic analyses (Porter's Five Forces, Portfolio Rebalancing)
├── run_pipeline.py # Unified CLI entry-point to execute the stock ranking pipeline
├── requirements.txt # Project dependencies list
└── .gitignore # Clean git exclusion policy (ignores caches, checkpoints, logs)
The workflow consists of four major phases:
graph TD
A[BSE 500 Raw Data] -->|Clean & Parse| B[Impute Missing Values]
B -->|Calculate Turnover Ratio| C[Liquidity Filter >= 5%]
C -->|Screening Criteria| D[Screened Watchlist]
D -->|Quantitative Scoring Model| E[Ranked Priority List]
E -->|Export CSV| F[Watchlists & Ranked Outputs]
- Scraping Engine: Pulls real-time financial stats where API data is sparse. Uses Selenium headless to parse fundamentals (P/E, P/B, ROE) from Groww and BeautifulSoup to extract standalone/consolidated EPS from Moneycontrol.
-
API Integration: Fetches valuation ratios dynamically via
yfinance. -
Imputation Logic: Fills missing metrics using logical relationships:
$$\text{EPS} = \frac{\text{LTP}}{\text{PE Ratio}}$$ Missing ROE/ROCE figures are filled using industry-specific group medians, and missing 200 DMAs are modeled via 50 DMA relative ratios.
To enter the investment watchlist, a stock must pass the following stringent value and momentum filters:
-
Liquidity: Turnover Ratio
$\ge 5%$ (filters out illiquid stocks).$$\text{Turnover Ratio} = \frac{\text{LTP} \times \text{Volume}}{\text{Market Cap (Cr.)} \times 100}$$ -
Relative P/E:
$\text{P/E Ratio} \le 1.5 \times \text{Industry P/E}$ (prevents overpaying). -
P/B Ratio:
$0.5 \le \text{P/B Ratio} \le 4.0$ (ensures reasonable asset backing). -
Profitability:
$\text{ROE} > 12%$ and$\text{ROCE} > 12%$ (ensures high returns on capital). -
Technical Momentum:
-
$\text{LTP} > 52\text{W Low} + 10%$ (stock has bottomed out). -
$\text{LTP} > 52\text{W High} \times 80%$ (stock is trading in its upper band).
-
Stocks that pass the screening filters are scored using a weighted multi-factor scoring card (totaling 100 points maximum):
-
ROCE Contribution (15%): Penalizes deviation from an ideal ROCE of
$26%$ .$$\text{Score}_{\text{ROCE}} = \max(0, 100 - |\text{ROCE} - 26| \times 3) \times 0.15$$ -
ROE Contribution (13%): Penalizes deviation from an ideal ROE of
$23%$ .$$\text{Score}_{\text{ROE}} = \max(0, 100 - |\text{ROE} - 23| \times 3) \times 0.13$$ -
EPS Strength (12%): Rewards absolute EPS values, capped at
$100%$ scaling.$$\text{Score}_{\text{EPS}} = \min(100, \text{EPS} \times 5) \times 0.12$$ -
P/E Discount (10%): Measures valuation deviation from the Industry P/E.
$$\text{Score}_{\text{PE}} = \max(0, 100 - (\text{PE} - \text{Industry PE}) \times 5) \times 0.10$$
-
Moving Average Trend (10%): Bullish trend confirmation.
$$\text{Score}_{\text{DMA}} = (\text{100 if LTP} > \text{200 DMA else 30}) \times 0.10$$ -
RSI Deviation (10%): Mean reversion signal targeting an ideal RSI of
$30$ .$$\text{Score}_{\text{RSI}} = \max(0, 100 - |\text{RSI} - 30| \times 2.5) \times 0.10$$ -
Medium/Long-Term Returns (10%): Combines 3-Month and 1-Year performance.
$$\text{Score}_{\text{Returns}} = \left( \frac{\text{3M Returns} + \text{1Yr Returns}}{2} + 50 \right) \times 0.10$$
-
P/B Ratio Discount (20%): Rewards stocks trading at discount multiples to book value.
$$\text{Score}_{\text{PB}} = \max(0, 100 - \text{PB Ratio} \times 10) \times 0.20$$
Total priority score determines the final Rank of each stock: $$\text{Total Score} = \text{Score}{\text{Fundamental}} + \text{Score}{\text{Technical}} + \text{Score}_{\text{Valuation}}$$
The reports/ folder contains comprehensive case studies and analyses completed during the program:
- Portfolio Restructuring and Rebalancing:
- Restructuring and Rebalancing of Portfolio.pdf / .docx: A detailed framework on optimizing asset allocations, analyzing risk-return profiles, and rebalancing portfolios dynamically to hedge macroeconomic drawdowns.
- Finance Sector Porter's 5 Forces Analysis:
- Finance-Sector-Porter's-5-Forces-Analysis.pdf / .docx: Evaluation of the Indian banking and financial services sector, detailing supplier power, buyer power, barrier to entries, threat of substitutes, and competitive rivalry.
- Discounted Cash Flow Model (
DCF_MVS.xlsx):- A fully interactive financial model showing projection periods, free cash flows (FCFF), Weighted Average Cost of Capital (WACC) calculations, terminal value estimates, and intrinsic share value outputs.
- Daily Market Decodes:
- Daily Market Decode.pdf / .docx: Real-time market reviews analyzing benchmark indices (Nifty, Sensex), corporate earnings reports, sector moves, and global interest rate decisions.
- Program Certificate & Final Thesis:
- 921475_certificate.pdf: Graduation certificate verifying internship credentials.
- 921475_report.pdf: Capstone report summarizing all project iterations.
Clone the repository and install the dependencies:
git clone https://github.com/YourUsername/Finlatics-Financial-Analyst-Portfolio.git
cd Finlatics-Financial-Analyst-Portfolio
pip install -r requirements.txtNote: Headless Selenium scrapers require Google Chrome and ChromeDriverManager installed on your local OS.
To execute the screening and ranking pipeline on a raw daily CSV output:
python3 run_pipeline.py --input data/nov11.csv --output-dir Watchlists--input,-i: Path to the input daily stock metrics CSV (default:data/nov11.csv).--output-dir,-o: Directory where output files will be written (default:Watchlists).--name,-n: Output base name override (e.g.2026-05-24).
The pipeline outputs two files:
Watchlists/<name>Watchlist.csv- The filtered list of candidate stocks.Watchlists/<name>Ranked_stocks.csv- Ranked list of priority stock options based on quantitative scores.
- Language: Python 3
- Libraries: Pandas, NumPy, Selenium, BeautifulSoup4, yfinance, requests, lxml
- Documentation & Analysis: Jupyter Notebook, Microsoft Excel, Microsoft Word, LaTeX/Markdown