SMA Crossover Strategy for E-mini S&P 500

Jose

Jose Acosta

SMA Crossover Strategy for E-mini S&P 500

This project implements and evaluates an algorithmic trading strategy based on a Simple Moving Average (SMA) crossover for E-mini S&P 500 (ES) futures. It uses nautilus-trader for backtesting and databento for high-quality historical data.

Features

Strategy: Crossover of a fast (20-period) and a slow (50-period) SMA.
Instrument: E-mini S&P 500 Futures.
Timeframe: 1-minute data.
Backtest Period: 2024.
Tech Stack: Python, NautilusTrader, Databento, Pandas.

1. Prerequisites

Python 3.11 or higher.
A Databento API key (the free plan is sufficient).

2. Installation

Clone the Repository
git clone <REPOSITORY-URL>
cd Test_Eagle
Create and Activate a Virtual Environment (Recommended)
# For Windows
python -m venv venv
venv\Scripts\activate

# For macOS/Linux
python3 -m venv venv
source venv/bin/activate
Install Dependencies The requirements.txt file contains all the necessary libraries.
pip install -r requirements.txt

3. Configuration

Set up the Databento API Key You must set your API key as an environment variable.
Windows (Command Prompt):
set DATABENTO_API_KEY="YOUR_API_KEY"
Windows (PowerShell):
$env:DATABENTO_API_KEY="YOUR_API_KEY"
macOS/Linux:
export DATABENTO_API_KEY="YOUR_API_KEY"
Replace "YOUR_API_KEY" with the key you obtained from Databento.
(Optional) Adjust Strategy Parameters You can modify parameters such as the SMA periods, trade size, or instrument ID directly in the run_backtest.py file.

4. Running the Backtest

The process is divided into two main steps:
Step 1: Download Data
The data_handler.py script downloads the data for the quarterly ES futures contracts for 2024 and consolidates them into a single Parquet file.
python data_handler.py
The data will be saved in data/raw/ES_2024.parquet.
Step 2: Run the Backtest
Once the data is ready, the run_backtest.py script runs the strategy simulation.
python run_backtest.py

5. Results

The backtest results (PnL, number of trades, etc.) are saved in results/backtest_results.csv.
For a detailed analysis of the strategy's performance, design decisions, and potential improvements, please refer to the full report at STRATEGY_REPORT.md.

6. Project Structure

Test_Eagle/

├── data/
│ └── raw/
│ └── ES_2024.parquet # Consolidated data

├── results/
│ └── backtest_results.csv # Performance metrics

├── data_handler.py # Script to download and prepare data
├── run_backtest.py # Main script to run the backtest
├── strategy.py # Defines the SMACrossoverStrategy logic
├── requirements.txt # Project dependencies
├── README.md # This file
└── STRATEGY_REPORT.md # Detailed strategy report

7. Useful Resources

Like this project

Posted Oct 7, 2025

Implemented SMA crossover strategy for E-mini S&P 500 using NautilusTrader and Databento.

Likes

0

Views

0

Timeline

Dec 31, 2023 - Dec 30, 2024