CoolFace
Apppublic

naik123/ai-financial-modeler

sourceHugging Faceupdated 8mo agoView on Hugging Face
1likes
App README

AI Financial Modeling Platform

An AI-powered platform for generating institutional-grade Excel financial models for Indian stocks. Built with FastAPI, Next.js, and Google Gemini AI.

[image]

![Deploy on Spaces](https://huggingface.co/spaces/new?template=docker)

๐Ÿš€ Features

Core Capabilities

  • โ€”AI-Powered Industry Classification: Uses Google Gemini AI to classify companies and select appropriate model templates
  • โ€”Real Excel Formulas: Generated models use linked formulas, not static values - fully editable
  • โ€”150+ Indian Stocks: Comprehensive database covering Power, Banking, IT, Pharma, FMCG, Auto, and more
  • โ€”Raw Data Input: Generate models from your own financial data without scraping

Advanced Financial Modeling

  • โ€”Three-Statement Model: Income Statement, Balance Sheet, Cash Flow - all linked
  • โ€”DCF Valuation: WACC calculation, FCFF projections, terminal value, implied share price
  • โ€”Sensitivity Analysis: WACC vs Terminal Growth, Revenue vs EBITDA Margin tables
  • โ€”Scenario Analysis: Bear/Base/Bull case projections with IRR calculation
  • โ€”Dashboard with Charts: Revenue & EBITDA bars, margin trends, net income charts

Industry-Specific Templates

  • โ€”Power Sector: PLF tracking, fuel costs, tariff analysis
  • โ€”Banking: NIM analysis, credit costs, CASA ratios
  • โ€”IT Services: Utilization, billing rates, offshore mix
  • โ€”Pharmaceuticals: R&D intensity, ANDA filings
  • โ€”FMCG: Distribution metrics, brand spending
  • โ€”And more!

๐Ÿ“‹ Requirements

  • โ€”Python 3.9+
  • โ€”Node.js 18+
  • โ€”Google Gemini API Key (optional, uses templates as fallback)

๐Ÿ› ๏ธ Installation

Backend Setup

bash
cd backend

# Create virtual environment
python -m venv venv
venv\Scripts\activate  # Windows
# source venv/bin/activate  # Linux/Mac

# Install dependencies
pip install -r requirements.txt

# Create .env file
copy .env.example .env
# Edit .env and add your GEMINI_API_KEY

Frontend Setup

bash
cd frontend

# Install dependencies
npm install

๐Ÿš€ Running the Application

Start Backend

bash
cd backend
python main.py
# Server starts at http://127.0.0.1:8000

Start Frontend

bash
cd frontend
npm run dev
# App opens at http://localhost:3000

๐Ÿ“ก API Endpoints

Company Information

bash
GET /api/company/{symbol}?exchange=NSE

Returns company name, sector, market cap, and current price.

Stock Database

bash
GET /api/stocks              # All 172 stocks
GET /api/stocks?sector=power # Filter by sector
GET /api/stocks/search/TCS   # Search by symbol or name
GET /api/sectors             # List all 14 sectors

Model Generation

bash
POST /api/model/generate
{
    "symbol": "ADANIPOWER",
    "exchange": "NSE",
    "forecast_years": 5,
    "model_types": ["three_statement", "dcf"]
}

Raw Data Model Generation

bash
POST /api/model/generate-raw
{
    "company_name": "My Company Ltd",
    "industry": "general",
    "forecast_years": 5,
    "historical_data": {
        "income_statement": {
            "revenue": 10000,
            "ebitda": 2500,
            "net_income": 1500
        },
        "balance_sheet": {
            "total_assets": 20000,
            "total_liabilities": 8000
        }
    },
    "assumptions": {
        "revenue_growth": 0.10,
        "ebitda_margin": 0.25,
        "tax_rate": 0.25
    }
}

Job Status

bash
GET /api/job/{job_id}

Download Model

bash
GET /api/download/{job_id}

๐Ÿ“Š Excel Model Structure

Each generated model contains:

SheetDescription
CoverCompany summary, key metrics, model info
SummaryNavigation links, key outputs
AssumptionsNamed ranges for all inputs (yellow cells)
Income_Statement5Y historical + 5Y forecast P&L
Balance_SheetAssets, liabilities, equity with balance check
Cash_FlowOperating, investing, financing activities
ValuationDCF model with WACC, terminal value, equity bridge
SensitivityWACC vs TGR, Revenue vs EBITDA sensitivity tables
ScenariosBear/Base/Bull case analysis with IRR
DashboardCharts for Revenue, EBITDA, Margins, Net Income

๐Ÿญ Supported Sectors (14 Categories)

  1. 1.Power & Utilities - ADANIPOWER, NTPC, TATAPOWER, POWERGRID...
  2. 2.Banking - HDFCBANK, ICICIBANK, SBIN, KOTAKBANK...
  3. 3.IT Services - TCS, INFY, WIPRO, HCLTECH, TECHM...
  4. 4.Pharmaceuticals - SUNPHARMA, DRREDDY, CIPLA, LUPIN...
  5. 5.FMCG - HINDUNILVR, ITC, NESTLEIND, BRITANNIA...
  6. 6.Automobiles - MARUTI, TATAMOTORS, M&M, HEROMOTOCO...
  7. 7.Metals & Mining - TATASTEEL, HINDALCO, JSWSTEEL, VEDL...
  8. 8.Oil & Gas - RELIANCE, ONGC, IOC, BPCL...
  9. 9.Cement - ULTRACEMCO, SHREECEM, ACC, AMBUJACEM...
  10. 10.Infrastructure - L&T, ADANIENT, ADANIPORTS, GMRINFRA...
  11. 11.NBFC - BAJFINANCE, BAJAJFINSV, SBICARD, MUTHOOTFIN...
  12. 12.Telecom - BHARTIARTL, IDEA...
  13. 13.Chemicals - PIDILITIND, UPL, CLEAN...
  14. 14.Consumer Durables - TITAN, HAVELLS, VOLTAS, CROMPTON...

๐ŸŽจ Frontend Features

  • โ€”Modern Dark Theme: Glassmorphism effects, gradient accents
  • โ€”Stock Browser: Search, filter by sector, click to select
  • โ€”Raw Data Input: Enter your own financial data and assumptions
  • โ€”Real-time Progress: Live status updates during generation
  • โ€”Model Preview: See included features before downloading

๐Ÿ”ง Configuration

Environment Variables

env
# Required for AI features (optional - falls back to templates)
GEMINI_API_KEY=your_gemini_api_key

# Optional
ALPHA_VANTAGE_API_KEY=your_alpha_vantage_key

Model Assumptions (Editable in Excel)

The Assumptions sheet contains named ranges for:

  • โ€”Revenue Growth Rate
  • โ€”EBITDA Margin
  • โ€”Depreciation % of Revenue
  • โ€”Tax Rate
  • โ€”Working Capital Days
  • โ€”CapEx % of Revenue
  • โ€”WACC, Risk-Free Rate, Equity Risk Premium
  • โ€”Terminal Growth Rate
  • โ€”And more...

๐Ÿ“ Project Structure

ai-financial-modeler/
โ”œโ”€โ”€ backend/
โ”‚   โ”œโ”€โ”€ main.py              # FastAPI server
โ”‚   โ”œโ”€โ”€ requirements.txt     # Python dependencies
โ”‚   โ”œโ”€โ”€ data/
โ”‚   โ”‚   โ”œโ”€โ”€ yahoo_finance.py # Yahoo Finance data collector
โ”‚   โ”‚   โ”œโ”€โ”€ screener_scraper.py # Screener.in scraper
โ”‚   โ”‚   โ””โ”€โ”€ stock_database.py   # 172 Indian stocks database
โ”‚   โ”œโ”€โ”€ agents/
โ”‚   โ”‚   โ”œโ”€โ”€ industry_classifier.py # AI industry classification
โ”‚   โ”‚   โ”œโ”€โ”€ financial_modeler.py   # Model structure design
โ”‚   โ”‚   โ””โ”€โ”€ qa_validator.py        # Model validation
โ”‚   โ”œโ”€โ”€ excel/
โ”‚   โ”‚   โ””โ”€โ”€ generator.py     # Excel model generator
โ”‚   โ””โ”€โ”€ output/              # Generated Excel files
โ””โ”€โ”€ frontend/
    โ”œโ”€โ”€ app/
    โ”‚   โ”œโ”€โ”€ page.tsx         # Main page with stock selection
    โ”‚   โ”œโ”€โ”€ layout.tsx       # Root layout
    โ”‚   โ””โ”€โ”€ globals.css      # Dark theme styles
    โ”œโ”€โ”€ package.json
    โ””โ”€โ”€ tailwind.config.js   # Custom theme config

๐Ÿค Contributing

Pull requests are welcome! Please ensure:

  1. 1.Code follows existing style patterns
  2. 2.New features include appropriate tests
  3. 3.Documentation is updated

๐Ÿ“„ License

MIT License - see LICENSE file for details.

๐Ÿ™ Acknowledgments

  • โ€”Yahoo Finance for financial data
  • โ€”Screener.in for detailed Indian stock data
  • โ€”Google Gemini AI for intelligent classification
  • โ€”openpyxl for Excel generation