This project implements a stock market backtesting engine using only NumPy. It simulates a moving average crossover trading strategy on historical price data and evaluates performance based on portfolio returns.
- Data cleaning and preprocessing from raw CSV
- Moving Average (MA) calculation using NumPy
- Signal generation (Buy/Sell) using MA crossover
- Backtesting engine for trade simulation
- Portfolio value tracking over time
- Final performance evaluation (profit & returns)
- Short-term MA (10 days)
- Long-term MA (50 days)
MA_short > MA_long→ Buy (1)MA_short < MA_long→ Sell (-1)
- Load and clean stock price data
- Convert data into NumPy arrays
- Compute moving averages using convolution
- Generate trading signals
- Simulate trades using a backtesting loop
- Track portfolio value over time
- Final Portfolio Value
- Total Profit / Loss
- Return Percentage
- Number of Trades (optional)
- Python
- NumPy
moving_average_backtest.ipynb
data.csv
README.md
- Vectorized computations using NumPy
- Time-series data handling
- Financial strategy simulation
- Building logic without high-level libraries
- Add multiple strategies
- Include transaction costs
- Support multi-stock backtesting
- Visualize results using plots
Built a stock market backtesting engine using NumPy, implementing a moving average crossover strategy with vectorized signal generation and portfolio simulation. Evaluated trading performance using return-based metrics.