A Python-based stock market simulation modeling three distinct investment strategies with realistic price movements, dividend payments, and risk scenarios.
-
Three Stock Types:
- Growth — High-volatility momentum trading with bankruptcy risk
- Dividend — Stable income stocks with quarterly dividend payments (£0.15/share every 90 days)
- Common — Standard market behavior with moderate volatility
-
Realistic Market Dynamics: Momentum effects, dramatic swings, and probability-based daily price movements
-
ROI Analysis: Detailed breakdowns of returns, dividends, and stock performance
-
Visualization: Automatic day/year axis scaling with matplotlib graphs
- Python 3.13.0+
- NumPy
- Matplotlib
# Clone the repository
git clone https://github.com/yourusername/Stock-Market-Simulator-.git
cd Stock-Market-Simulator-
# Install dependencies
pip install -r requirements.txtRun the simulator:
python main.pyExample Session:
Brief overview of stock types:
Growth — Fast‑growing, high‑volatility companies aiming for rapid revenue/price gains (e.g., Tesla).
Dividend — Stable, cash‑generating firms that pay regular dividends for income (e.g., Lloyds).
Common — Regular publicly traded shares representing ownership; mix of income and growth (e.g., Tesco).
Choose stock type to simulate (growth/dividend/common) or (1/2/3): growth
Initial Investment (integer GBP): 1000
No. Yrs to Invest (integer): 5
Initial Stock Price: £10
Initial Investment: £1000
Initial Stocks Bought: 100.0
Years Invested: 5
Final Stock Price: £47.23
Final Amount: £4723.0
Return: £3723.0
Return on Investment: 372.3%
A matplotlib window displays the stock price over time.
Each stock type implements a distinct _create_stock() algorithm:
- Growth: Momentum-based system with explosive gains/crashes and bankruptcy below £0.10
- Dividend: Stable ±0.5% daily movements with quarterly cash payouts
- Common: 60% upward bias with 2% chance of large swings
The simulation runs 365 days/year and calculates total returns including dividends (where applicable).
Stock-Market-Simulator-/
├── main.py # Entry point and user interaction
├── stocks.py # Stock simulation classes and algorithms
├── requirements.txt # Python dependencies
└── README.md
The codebase uses abstract base classes (Stock) with three concrete implementations. To add new stock types:
- Inherit from
Stockinstocks.py - Implement
_create_stock()returning a list of daily prices - Optionally override
_calc_return()for custom return logic - Add to the
choicesdict inmain.py
Huang Hao Gao - Personal project for quantitative finance simulation and Python OOP practice