Skip to main content

SIP Backtester

BACKTESTING ALL INIDAN Mutual Funds

Python

SIP & Mutual Fund Backtester (India)

A production-grade MVP for backtesting Indian mutual fund SIP investments with tax calculations, FD comparison, and portfolio rebalancing suggestions.

🎯 Purpose

This tool helps Indian retail investors:

  • Analyze historical SIP returns for mutual funds
  • Calculate post-tax returns (LTCG/STCG)
  • Compare MF returns with Fixed Deposits
  • Get rule-based portfolio rebalancing suggestions

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        Frontend                              β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”‚
β”‚  β”‚ Input Form   β”‚ β”‚  Results     β”‚ β”‚  Rebalance   β”‚         β”‚
β”‚  β”‚              β”‚ β”‚  Dashboard   β”‚ β”‚  Panel       β”‚         β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β”‚
β”‚         React + Vite (Port 5173)                            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                            β”‚
                            β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                     Backend API                              β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”‚
β”‚  β”‚ /api/funds   β”‚ β”‚/api/simulate β”‚ β”‚/api/rebalanceβ”‚         β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β”‚
β”‚         FastAPI + Uvicorn (Port 8000)                       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                            β”‚
                            β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚               Financial Calculation Engine                   β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚SIP Engine  β”‚ β”‚ Returns  β”‚ β”‚ Taxation β”‚ β”‚ Comparison   β”‚  β”‚
β”‚  β”‚            β”‚ β”‚CAGR/XIRR β”‚ β”‚LTCG/STCG β”‚ β”‚ MF vs FD     β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                            β”‚
                            β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Data Layer                                β”‚
β”‚          Versioned CSV files (data/nav/)                     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“Š Financial Assumptions

Tax Model (FY 2024-25)

CategoryTypeRateNotes
Equity FundsLTCG (>1 year)12.5%Exempt up to β‚Ή1.25L annually
Equity FundsSTCG (<1 year)20%Full gains taxable
Debt FundsAllSlab RateNo indexation (post-April 2023)
Fixed DepositsInterestSlab RateFully taxable

FD Rates Used

  • 1 year: 6.5%
  • 2-3 years: 7.0%
  • 5+ years: 7.25%

Rebalance Targets

HorizonEquityDebt
Short (<3 yrs)20%80%
Medium (3-7 yrs)50%50%
Long (>7 yrs)80%20%

πŸ“ Data Sources

Sample data included for demonstration purposes.

For production use, data can be sourced from:

  • AMFI India (amfiindia.com) - Official NAV data
  • Fund house websites - Historical NAV disclosures
  • Value Research / Morningstar - Third-party aggregators

NAV CSV Format

date,fund_id,fund_name,nav,fund_type,expense_ratio
2024-01-02,HDFC_FLEXI,HDFC Flexicap Fund,525.45,equity,1.75

πŸš€ Running Locally

Prerequisites

  • Python 3.11+
  • Node.js 18+
  • pip / npm

Backend Setup

cd backend
python -m venv venv
venv\Scripts\activate  # Windows
pip install -r requirements.txt
uvicorn app.main:app --reload

Backend runs at: http://localhost:8000

Frontend Setup

cd frontend
npm install
npm run dev

Frontend runs at: http://localhost:5173

Running Tests

cd backend
pip install pytest httpx
pytest tests/ -v

🌐 Deployment

Free Hosting Options

Backend (Python/FastAPI)

  • Render.com (free tier)
  • Railway.app
  • Fly.io

Frontend (React)

  • Vercel
  • Netlify
  • GitHub Pages (for static build)

Environment Variables

# Backend
CORS_ORIGINS=https://your-frontend.vercel.app

# Frontend (if not using proxy)
VITE_API_URL=https://your-backend.onrender.com

⚠️ Limitations

  1. Historical data only - Cannot predict future returns
  2. Sample data - MVP includes demo data; connect real NAV feeds for production
  3. Tax simplifications - Does not handle:
    • Grandfathering rules
    • Multiple financial years in one redemption
    • Set-off of losses
  4. No real-time data - NAV data is static CSVs
  5. Single fund simulation - Multi-fund portfolio analysis not implemented

πŸ“œ Disclaimer

⚠️ This is an educational tool for historical analysis only.

  • Past performance does not guarantee future returns
  • Tax calculations are estimates based on FY 2024-25 rules
  • Always consult a SEBI-registered investment advisor before investing
  • Verify calculations independently before making financial decisions

πŸ§ͺ Test Coverage

ModuleTests
SIP EngineDate generation, unit calculation, expense drag
ReturnsCAGR accuracy, XIRR convergence, volatility
TaxationEquity/Debt classification, LTCG/STCG edge cases
APIEndpoints, response schemas, error handling

πŸ“ License

MIT License - Free for personal and commercial use.


Built with ❀️ for Indian retail investors.