Skip to content

tanishhh2077/trading-simulator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

15 Commits
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“ˆ Algorithmic Trading Simulator (SMA Crossover)

A Python-based backtesting tool that implements a 20/50-day Simple Moving Average (SMA) crossover strategy.
It fetches historical stock data via Yahoo Finance, executes trades with next-day discipline to avoid look-ahead bias, logs results into SQLite, and generates equity curve plots comparing the strategy against a Buy & Hold benchmark.


πŸ”§ Features

  • πŸ“Š Historical stock data retrieval with yFinance
  • πŸ“‰ Implements short-term vs long-term SMA crossover strategy
  • πŸ—„οΈ Logs trades and returns into SQLite database for reproducibility
  • πŸ“ˆ Plots equity curve vs Buy & Hold benchmark using matplotlib
  • βœ… Avoids look-ahead bias by executing trades next day

πŸ› οΈ Tech Stack

  • Python 3.11
  • pandas, NumPy
  • yFinance
  • matplotlib
  • SQLite

πŸš€ Quickstart

Clone the repository and set up your environment:

git clone https://github.com/USERNAME/trading-simulator.git
cd trading-simulator

# Create and activate virtual environment
python -m venv .venv
.venv\Scripts\activate   # On Windows

# Install dependencies
pip install -r requirements.txt

Run the backtest:
python backtest.py

---

## πŸ“Š Example Output

Running the backtest on **Nvidia Corporation (NVDA)** produces:

- `equity.png` β†’ Equity curve of strategy vs Buy & Hold  
- `trades.db` β†’ SQLite database log of trades  

Example equity curve output:
(See equity.png in the folder)
---


About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages