Skip to content

Generate a random stock portfolio and find out if it beats the markets!

License

Notifications You must be signed in to change notification settings

mr-karan/monkeybeat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MonkeyBeat

Can random stock picks beat professional fund managers?

MonkeyBeat generates equi-weighted portfolios of 10 randomly selected stocks from NSE indices and compares their performance against the underlying benchmark.

Test the "monkeys throwing darts" hypothesis yourself!

MonkeyBeat Screenshot

Quick Start

# Requires Python 3.12+ and uv
uv run app.py

Open http://localhost:7777

First run takes 5-10 minutes to fetch 5 years of stock data from Yahoo Finance.

Features

  • Single file app - Everything in app.py (~850 lines)
  • Zero setup - Embedded DuckDB, no external database
  • 9 NSE indices - From NIFTY 50 to Smallcap 250
  • Monte Carlo simulations - 100 random portfolios per request
  • Fast - ~150ms response after data is loaded
  • Shareable - UUID-based links with social sharing

Supported Indices

Index Stocks Category
NIFTY 50 50 Large Cap
NIFTY Next 50 50 Large Cap
NIFTY 100 100 Large Cap
NIFTY 200 200 Large Cap
NIFTY 500 500 Large Cap
NIFTY Midcap 100 100 Mid Cap
NIFTY Midcap 150 150 Mid Cap
NIFTY Smallcap 100 100 Small Cap
NIFTY Smallcap 250 250 Small Cap

How It Works

  1. Select an index from the dropdown
  2. App randomly picks 10 stocks from that index
  3. Calculates returns over 1M, 6M, 1Y, 3Y, and 5Y periods
  4. Compares against the benchmark index
  5. Runs 100 Monte Carlo simulations to show win rate

Project Structure

monkeybeat/
├── app.py                    # FastAPI app (uv inline dependencies)
├── templates/                # Jinja2 templates
│   ├── base.html            # Layout with HTMX, Tailwind, Lightweight Charts
│   ├── portfolio.html       # Results page
│   └── error.html
├── scripts/
│   ├── download_indices.sh  # Fetch latest index constituents
│   └── ind_*.csv            # Index constituent lists
├── static/                   # Logo, favicon
└── data/                     # DuckDB database (auto-created)

Tech Stack

Updating Index Data

./scripts/download_indices.sh

Why Does the Monkey Usually Win?

  1. Equal weighting - Your portfolio weights each stock equally, while indices are cap-weighted
  2. Survivorship bias - Current index members are "survivors"; poor performers were removed
  3. Concentration - 10 stocks can get lucky with 1-2 multibaggers

License

MIT

Credits

Disclaimer

This is for educational/entertainment purposes only. Not financial advice. Past performance does not guarantee future results.

About

Generate a random stock portfolio and find out if it beats the markets!

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •