A robust, quantitative natural gas trading system with data pipelines, strategy modules, backtesting, and live trading capabilities.
This project implements a sophisticated natural gas trading system that combines fundamental data (EIA storage, production, consumption), weather data (NOAA forecasts), and technical indicators to generate alpha signals for natural gas futures trading.
- Data Ingestion: Automated pipelines for EIA, NOAA, and market data
- Feature Engineering: Weather-based features, storage analysis, and technical indicators
- Strategy Development: Modular alpha, risk, and portfolio construction components
- Backtesting: Vector-based backtesting engine with transaction costs and slippage
- Analytics: Performance analysis and strategy comparison tools
- Live Trading: Signal generation, trade recommendations, and position management
- Python 3.8+
- Git
-
Clone the repository:
git clone https://github.com/yourusername/natural-gas-trading.git cd natural-gas-trading
-
Create and activate a virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Set up configuration:
cp config/credentials.yaml.example config/credentials.yaml # Edit credentials.yaml with your API keys
The system requires the following API keys to function properly:
-
NOAA API - For weather data
- Register at https://www.ncdc.noaa.gov/cdo-web/token
- Add your token to
config/credentials.yaml
-
EIA API - For natural gas storage and price data
- Register at https://www.eia.gov/opendata/register.php
- Add your key to
config/credentials.yaml
natural-gas-trading/
├── config/ # Configuration files
│ ├── config.yaml # System configuration
│ └── credentials.yaml # API keys (git-ignored)
├── data/ # Data storage
│ ├── raw/ # Raw data from APIs
│ ├── processed/ # Processed datasets
│ └── signals/ # Generated trading signals
├── src/ # Source code
│ ├── data_ingestion/ # API connectors and data fetchers
│ ├── data_processing/ # Cleaning and feature engineering
│ ├── strategies/ # Trading strategies
│ ├── backtesting/ # Backtesting framework
│ ├── live_trading/ # Live trading components
│ ├── utils/ # Utilities
│ └── visualization/ # Visualizations and dashboards
├── notebooks/ # Jupyter notebooks for analysis
├── tests/ # Unit and integration tests
├── logs/ # System logs
└── run_trading_system.py # Main entry point
To run a backtest of the weather-storage strategy over 2 years:
python run_trading_system.py --mode backtest --strategy weather --years 2
To compare all strategies:
python run_trading_system.py --mode backtest --strategy ensemble --years 2
To run individual backtests for all strategies with plotting:
python run_trading_system.py --mode backtest --strategy all --years 2 --plot
To generate a single trading signal:
python run_trading_system.py --mode live --once
To run the continuous signal generation service (60-minute intervals):
python run_trading_system.py --mode live --interval 60
-
Data Ingestion
- NOAA weather data fetcher for temperature and precipitation
- EIA natural gas storage and pricing data
- Integration with market data sources
-
Feature Engineering
- Weather features: Heating/Cooling Degree Days (HDD/CDD)
- Storage deviation from seasonal norms
- Price momentum and mean reversion indicators
- Cross-asset signals
-
Weather-Storage Strategy
- Combines temperature anomalies with storage deviations
- Seasonal adjustment based on time of year
- Momentum overlay for trend confirmation
-
Momentum Strategy
- Captures medium-term price trends
- Volatility-adjusted position sizing
-
Mean Reversion Strategy
- Identifies overbought/oversold conditions
- Statistical significance testing
-
Fundamental Strategy
- Storage-based signals
- Supply/demand imbalance indicators
- Seasonal components
-
Position Sizing
- Volatility-based sizing
- Maximum position limits
- Kelly criterion implementation
-
Stop Loss
- Trailing stops
- Volatility-based stops
- Time-based exits
- Return Metrics: Total return, annualized return
- Risk Metrics: Sharpe ratio, Sortino ratio, max drawdown
- Trading Metrics: Win rate, profit factor, average win/loss
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
- NOAA for weather data access
- EIA for natural gas market data
- CME Group for futures market information