Skip to content

purnankgogarkar/quantfolio-simulation-hub

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

12 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Quantfolio Simulation Hub

A professional-grade portfolio risk analysis platform that helps investors understand their investment risk using advanced Monte Carlo simulations, statistical modeling, and real-time market data.

Python Streamlit License

🎯 Features

  • 4 Simulation Methods

    • Monte Carlo Simulation
    • Historical Simulation
    • Bootstrap Simulation
    • Stress Testing
  • Real-time Market Data πŸ“ˆ

    • Live NSE/BSE stock prices
    • 1-year historical data
    • Automatic data alignment & cleaning
  • Professional Risk Metrics πŸ“Š

    • Value at Risk (VaR) calculation
    • Expected Shortfall (ES)
    • Maximum Loss/Gain analysis
    • Statistical summaries
  • Interactive Dashboard 🎨

    • Drag-and-drop portfolio builder
    • Real-time portfolio summary
    • Dynamic loss distribution charts
    • Portfolio composition breakdown
  • Professional PDF Reports πŸ“„

    • Embedded loss distribution charts
    • Financial explanations & insights
    • Risk recommendations
    • Compliance-ready disclaimers
  • Educational Content πŸŽ“

    • VaR/ES explanations
    • Chart interpretation guides
    • Risk management recommendations

πŸ› οΈ Tech Stack

Component Technology
Frontend Streamlit
Backend Python, NumPy, Pandas
Visualization Plotly, Matplotlib
Data yfinance
PDF Generation ReportLab
Simulations SciPy, NumPy

πŸ“Έ Screenshots

Main Window

image

Risk Analysis Results

image image image

PDF Report

image image

πŸš€ Quick Start

Prerequisites

  • Python 3.9+
  • pip package manager

Installation

  1. Clone the repository
git clone https://github.com/YOUR_USERNAME/quantfolio-simulation-hub.git
cd quantfolio-simulation-hub
  1. Create virtual environment
python -m venv venv

# Windows
venv\Scripts\activate

# macOS/Linux
source venv/bin/activate
  1. Install dependencies
pip install -r requirements.txt
  1. Run the application
streamlit run app.py
  1. Open in browser
http://localhost:8501

πŸ“– How to Use

  1. Upload Portfolio

    • Click "Upload Excel" or "Build Portfolio"
    • Add stock symbols and quantities
    • File format: Stock, Quantity columns
  2. Configure Simulation

    • Choose simulation method (Monte Carlo, Historical, Bootstrap, Stress)
    • Set number of iterations (1,000 - 50,000)
    • Select confidence level (90% - 99%)
  3. Run Simulation

    • Click "πŸš€ Run Simulation"
    • Wait for calculations to complete
  4. Analyze Results

    • View risk metrics (VaR, ES)
    • Explore loss distribution chart
    • Read educational explanations
    • Download PDF report or CSV data

πŸ“Š Key Concepts Explained

Value at Risk (VaR)

The maximum amount you could lose on a single day with a given confidence level (e.g., 95%).

Example: VaR of β‚Ή50,000 at 95% confidence means:

  • 95% of days, you won't lose more than β‚Ή50,000
  • 5% of days, you might lose more than β‚Ή50,000

Expected Shortfall (ES)

The average loss on days when the loss exceeds the VaR threshold. Represents the worst-case scenario losses.

Monte Carlo Simulation

Generates thousands of random market scenarios based on historical volatility and correlation to estimate potential portfolio outcomes.

πŸ”§ Project Structure

quantfolio-simulation-hub/
β”œβ”€β”€ app.py                          # Main Streamlit application
β”œβ”€β”€ requirements.txt                # Python dependencies
β”œβ”€β”€ README.md                       # This file
β”‚
β”œβ”€β”€ simulations/
β”‚   β”œβ”€β”€ monte_carlo.py             # Monte Carlo implementation
β”‚   β”œβ”€β”€ historical.py              # Historical simulation
β”‚   β”œβ”€β”€ bootstrap.py               # Bootstrap resampling
β”‚   └── stress_test.py             # Stress test simulation
β”‚
β”œβ”€β”€ utils/
β”‚   β”œβ”€β”€ data_fetcher.py            # yfinance data integration
β”‚   β”œβ”€β”€ pdf_generator.py           # PDF report generation
β”‚   β”œβ”€β”€ explanations.py            # Financial education content
β”‚   β”œβ”€β”€ styling.py                 # CSS styling
β”‚   └── ...
β”‚
└── ui/
    β”œβ”€β”€ portfolio_builder.py       # Portfolio input interface
    β”œβ”€β”€ modern_components.py       # Streamlit components
    └── charts.py                  # Visualization

πŸ› Key Features & Bug Fixes

  • βœ… Intelligent data cleaning: Handles missing values using forward/backward fill
  • βœ… Stock alignment: Validates portfolio stocks against downloaded data
  • βœ… Error handling: Comprehensive error messages for users
  • βœ… Performance optimization: 10K simulations run in <5 seconds
  • βœ… Professional output: PDFs with embedded charts and explanations

πŸ’‘ Learning Points

This project demonstrates:

  1. Financial Computing

    • Monte Carlo simulations
    • Statistical risk modeling
    • Time-series analysis
  2. Data Engineering

    • Real-time data fetching
    • Data cleaning & alignment
    • Missing value handling
  3. Software Design

    • Modular architecture
    • Error handling
    • Code organization
  4. Product Development

    • UI/UX design
    • Professional reporting
    • User education

🚧 Future Enhancements

  • Portfolio optimization suggestions
  • Tax-loss harvesting recommendations
  • Correlation analysis between stocks
  • Multi-currency support
  • Mobile app version
  • API for integration
  • Historical report tracking
  • Risk alerts & notifications

πŸ“ Notes

  • Data is fetched in real-time from Yahoo Finance (yfinance)
  • Simulations are based on 1-year historical data
  • Past performance does not guarantee future results
  • See disclaimer in PDF reports for important legal information

⚠️ Disclaimer

This tool is for educational and analytical purposes only. It is not a substitute for professional financial advice. Past performance does not guarantee future results. Consult with a qualified financial advisor before making investment decisions.

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

🀝 Contributing

Contributions are welcome! Please feel free to submit issues or pull requests.

πŸ‘¨β€πŸ’» Author

[Your Name]

πŸ“§ Questions?

Feel free to open an issue or reach out directly!


Built with ❀️ for financial literacy
Quantfolio Simulation Hub Β© 2024

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages