Skip to content

soydas1609/tr-power-market-sql-analysis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Turkish Power Market — SQL Analytical Toolkit

A lightweight analytical layer over 4 years of Turkish electricity market data. Demonstrates SQL fluency: window functions, CTEs, and business-relevant analytical queries.

license duckdb python

What's Inside

  • Schema: 3-table design (fact_market_hourly, dim_calendar, dim_weather)
  • 5 analytical SQL queries — each answers a concrete business question
  • Executed Jupyter notebook running all queries with visualizations
  • 4 years (2021–2024) of hourly Turkish DAM + IDM price data

SQL Features Demonstrated

Feature Where Used
STDDEV_SAMP() OVER (ROWS BETWEEN ...) Q02 rolling volatility
RANK() OVER (PARTITION BY ... ORDER BY ...) Q03 IDM premium, Q04 hour ranking
CORR() OVER (ROWS BETWEEN ...) Q05 weather correlation
Multi-CTE chains (WITH ... AS) Q01, Q03, Q04
CASE WHEN with business classification Q03, Q04, Q05
Multi-table JOIN with fact + dimension tables All queries

The 5 Queries

Query Business Question Key SQL Feature
Q01 How has peak/off-peak spread evolved? CTE + GROUP BY + CASE WHEN
Q02 When is the market most volatile? STDDEV_SAMP window, ROWS frame
Q03 Does IDM trade above DAM? When? RANK() PARTITION BY + JOIN
Q04 Which hours are most expensive per month? RANK() PARTITION BY year, month
Q05 When does temperature predict price? CORR() window function

Sample Findings

Peak/Off-Peak Spread (Q01) The absolute spread grew ~3× from 2021 to 2024, tracking TL inflation. The percentage spread remains stable at 15–20%, confirming consistent market structure despite nominal price growth.

IDM Premium (Q03) IDM trades at an average +18–25 TL/MWh premium over DAM during peak hours (08:00–20:00). Off-peak hours show near-parity, reflecting thin intraday volumes and limited price discovery.

Weather Correlation (Q05) Temperature–price correlation peaks in summer (r ≈ 0.4–0.6 for Istanbul), confirming that cooling demand dominates the generation stack in July–August. Spring/autumn show near-zero correlation — other signals matter more in transitional seasons.

How to Reproduce

git clone https://github.com/soydas1609/tr-power-market-sql-analysis
cd tr-power-market-sql-analysis
pip install -r requirements.txt
python sql/02_seed_data.py          # ~5 seconds, creates data/market.db
jupyter notebook notebooks/market_analysis.ipynb

Project Structure

tr-power-market-sql-analysis/
├── sql/
│   ├── 01_schema.sql              # DuckDB table definitions
│   ├── 02_seed_data.py            # Data generation + seeding script
│   └── 10_queries/
│       ├── q01_peak_offpeak_spread.sql
│       ├── q02_rolling_volatility.sql
│       ├── q03_dam_vs_idm_premium.sql
│       ├── q04_monthly_hour_ranking.sql
│       └── q05_weather_price_correlation.sql
├── notebooks/
│   └── market_analysis.ipynb      # Executed notebook with all 5 queries
├── results/figures/               # Charts from notebook
└── data/
    └── README.md                  # Data documentation

Tech Stack

DuckDB · SQL (window functions, CTEs) · Python · Jupyter · matplotlib

About

Built by Hamit Soydas — energy trading analyst, Turkish electricity market.

About

SQL analytical toolkit for Turkish electricity market data. Demonstrates window functions, CTEs, rolling aggregates — DuckDB + Python + Jupyter.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors