A Python-based analysis tool for modeling energy procurement strategies using day-ahead electricity prices from the Danish market (DK2 - Eastern Denmark). This project analyzes optimal timing and frequency of energy purchases to minimize total costs.
This project implements and visualizes different energy procurement strategies by analyzing historical day-ahead electricity prices from the ENTSO-E Transparency Platform. The main focus is on optimizing the number and timing of energy purchases throughout the year to minimize total procurement costs.
- Historical Price Analysis: Processes 3 years of hourly electricity price data (2023-2025)
- Procurement Strategy Optimization: Implements an adaptive procurement algorithm
- Cost Analysis: Compares total costs across different procurement frequencies
- Data Visualization: Generates comprehensive charts showing price trends and optimal purchase points
- Python 3.8+ (any platform: Windows, macOS, Linux)
- Git (optional, for cloning)
Linux/macOS:
git clone <repository-url>
cd EnergyTradingAnalysis
./scripts/setup.sh
Windows:
git clone <repository-url>
cd EnergyTradingAnalysis
scripts\setup.bat
- Clone or download this repository
- Create virtual environment:
python -m venv venv
- Activate virtual environment:
- Linux/macOS:
source venv/bin/activate
- Windows:
venv\Scripts\activate
(orvenv\Scripts\activate.bat
)
- Linux/macOS:
- Install dependencies:
pip install -r requirements.txt
conda env create -f environment.yml
conda activate energy-trading-analysis
nix develop # or nix-shell if using legacy Nix
# Build and run
docker build -t energy-analysis .
docker run -v $(pwd):/app energy-analysis
# Or use Docker Compose
docker-compose up --build
After setup:
# Run the analysis
cd src && python modelling.py
Output:
- Load and process the price data from CSV files
- Run procurement optimization for different strategies
- Generate two visualization files:
dayaheadprices.png
: Price trends with optimal purchase pointstotal_cost_vs_nproc.png
: Cost comparison across procurement frequencies
βββ src/ # Source code
β βββ modelling.py # Main analysis script
βββ data/ # Data files
β βββ price_dk_2023.csv # 2023 price data
β βββ price_dk_2024.csv # 2024 price data
β βββ price_dk_2025.csv # 2025 price data
β βββ spotprice_2024_2025.csv
βββ output/ # Generated outputs
β βββ dayaheadprices.png # Price trends visualization
β βββ total_cost_vs_nproc.png # Cost analysis chart
βββ scripts/ # Setup and utility scripts
β βββ setup.sh # Linux/macOS setup script
β βββ setup.bat # Windows setup script
βββ requirements.txt # Python dependencies
βββ environment.yml # Conda environment specification
βββ pyproject.toml # Modern Python project configuration
βββ Dockerfile # Docker container configuration
βββ docker-compose.yml # Docker Compose configuration
βββ flake.nix # Nix development environment
βββ flake.lock # Nix lock file
βββ .gitignore # Git ignore rules
βββ dayaheadprices.png # Generated: Price analysis chart
βββ total_cost_vs_nproc.png # Generated: Cost optimization chart
βββ README.md # This file
Data Provider: ENTSO-E Transparency Platform
Market Details:
- Market: Day-ahead Prices (DAM)
- Bidding Zone: DK2 (Denmark - Eastern)
- Time Zone: CET/CEST
- Resolution: Hourly data
- Period: 2023-2025
The core algorithm implements an adaptive procurement strategy:
- Time Partitioning: Divides the time period into
n_parts
equal segments - Reference Tracking: Maintains a reference price that updates to lower values
- Trigger Logic: Purchases energy when price exceeds
reference + limit
- Cost Calculation: Computes total cost for the specified energy volume (default: 1000 MWh)
Parameters:
mwhs
: Total energy to procure (default: 1000 MWh)n_parts
: Number of procurement periods (tested: 1, 2, 3, 4, 6, 12, 24)limit
: Price increase threshold for triggering purchases (default: β¬10/MWh)
- Daily Averaging: Converts hourly data to daily averages using 24-hour moving window
- Multi-Strategy Comparison: Tests procurement frequencies from 1 to 24 times per year
- Cost Optimization: Identifies optimal procurement frequency to minimize total costs
- Time series of daily average electricity prices
- Optimal purchase points for different procurement strategies
- Color-coded markers showing purchase timing for each strategy
- Total procurement costs vs. number of procurement periods
- Helps identify the optimal procurement frequency
- Shows diminishing returns of increased procurement frequency
- β Linux (Ubuntu, Debian, RHEL, etc.)
- β macOS (Intel & Apple Silicon)
- β Windows (10/11, WSL)
Virtual Environment (All platforms):
python -m venv venv
source venv/bin/activate # Linux/macOS
# or
venv\Scripts\activate # Windows
Conda (All platforms):
conda env create -f environment.yml
conda activate energy-trading-analysis
Nix (Linux/macOS):
nix develop # Modern Nix with flakes
# or
nix-shell # Legacy Nix
Docker (All platforms):
# Build and run with Docker
docker build -t energy-analysis .
docker run -v $(pwd)/output:/app/output energy-analysis
# Or use Docker Compose
docker-compose up --build
Windows:
- Use Command Prompt, PowerShell, or Git Bash
- WSL (Windows Subsystem for Linux) fully supported
- Python from Microsoft Store or python.org both work
macOS:
- Works with system Python or Homebrew Python
- Both Intel and Apple Silicon Macs supported
- Xcode Command Line Tools may be required
Linux:
- Most distributions supported
- Use system package manager for Python if needed
- Virtual environments recommended for isolation
# Run with default parameters (1000 MWh, 4 procurements, β¬10 limit)
buy_indices, total_cost = sched_proc(price_avg)
# Custom energy volume and procurement frequency
buy_indices, total_cost = sched_proc(
price=price_avg,
mwhs=2000, # 2000 MWh total
n_parts=6, # 6 procurements per year
limit=15 # β¬15/MWh price increase limit
)
The analysis typically shows:
- Optimal Procurement Frequency: Usually 3-6 times per year
- Cost Savings: Significant reduction compared to single annual purchase
- Seasonal Patterns: Purchase timing often aligns with seasonal price cycles
Import Errors:
# Ensure virtual environment is activated
source venv/bin/activate # Linux/macOS
venv\Scripts\activate # Windows
# Reinstall dependencies
pip install -r requirements.txt
Python Version Issues:
- Ensure Python 3.8+ is installed
- Use
python3
command ifpython
points to Python 2.x
Permission Issues (Linux/macOS):
chmod +x setup.sh
Windows Path Issues:
- Use Git Bash for Unix-like commands
- Or use the provided
.bat
script for native Windows
Ubuntu/Debian:
sudo apt update
sudo apt install python3 python3-pip python3-venv
macOS (with Homebrew):
brew install python
Windows:
- Download from python.org
- Or install via Microsoft Store
- Or use Anaconda/Miniconda
Contributions are welcome! Areas for improvement:
- Additional procurement strategies
- Risk analysis and volatility metrics
- Integration with other European bidding zones
- Real-time data integration
- Machine learning price prediction
- Fork the repository
- Run setup script for your platform
- Make changes and test across platforms
- Submit a pull request
This project is provided as-is for educational and research purposes. Price data is sourced from ENTSO-E under their terms of use.
pip install -e . # Development installation
# or
pip install . # Regular installation
python -m build # Create distribution packages
For questions or suggestions regarding this energy trading analysis, please open an issue or submit a pull request.
This project demonstrates quantitative analysis techniques for energy market optimization and serves as a foundation for more sophisticated trading algorithms.