Skip to main content

Quantitative analysis for power markets

Project description

octoanalytics logo

License

octoanalytics is a Python package by Octopus Energy providing tools for quantitative analysis and risk calculation on energy data. It facilitates analyzing energy consumption time series, incorporating temperature data, forecasting consumption, retrieving market prices, and computing risk premiums.


Key Features

  • Smoothed Temperature Retrieval: Fetches hourly smoothed temperature data for major French cities and computes a national average.
  • Energy Consumption Forecasting: Gradient Boosting model based on time features and temperature.
  • Interactive Plotting: Visualize forecasts vs actual consumption with MAPE annotation.
  • Spot and Forward Price Data: Functions to query EPEX spot prices and EEX forward prices from Databricks.
  • Risk Premium Calculation: Computes risk premiums from forward price curves and forecast errors.
  • Data Preprocessing: Automatic feature engineering, imputation, and scaling.

Installation

To install octoanalytics, use:

pip install octoanalytics

Dependencies such as pandas, numpy, scikit-learn, holidays, plotly, tqdm, and tentaclio will be installed automatically.


Usage

Importing the package

from octoanalytics import eval_forecast, plot_forecast, calculate_mape, get_temp_smoothed_fr, get_spot_price_fr, get_forward_price_fr, get_pfc_fr, calculate_prem_risk_vol

Data format for forecasting

The input data should be a DataFrame with at least:

  • A datetime column (default named 'datetime')
  • A consumption column (default named 'consumption')

Example:

import pandas as pd

data = pd.DataFrame({
    'datetime': ['2025-01-01 00:00', '2025-01-01 01:00', '2025-01-01 02:00'],
    'consumption': [120.5, 115.3, 113.7]
})

data['datetime'] = pd.to_datetime(data['datetime'])

Forecasting energy consumption

Use the eval_forecast function to train and predict consumption:

forecast_df = eval_forecast(data)
print(forecast_df.head())

This returns the test set with a 'forecast' column containing predicted values.

Plotting forecasts

Visualize actual vs predicted consumption with:

plot_forecast(data)

Calculate MAPE (Mean Absolute Percentage Error)

mape_value = calculate_mape(data)
print(f"MAPE: {mape_value:.2f}%")

Retrieve smoothed temperature data for France

temp_df = get_temp_smoothed_fr('2025-01-01', '2025-01-31')
print(temp_df.head())

Retrieve spot prices for French electricity market

Requires a Databricks token:

spot_prices = get_spot_price_fr(token='your_token_here', start_date='2025-01-01', end_date='2025-01-31')
print(spot_prices.head())

Retrieve forward prices and Price Forward Curve (PFC)

forward_prices = get_forward_price_fr(token='your_token_here', cal_year=2026)
pfc = get_pfc_fr(token='your_token_here', cal_year=2026)

Calculate premium risk volatility

premium = calculate_prem_risk_vol(token='your_token_here', input_df=data, datetime_col='datetime', target_col='consumption', plot_chart=True, quantile=50)
print(f"Risk premium at 50th percentile: {premium}")

Function Descriptions

eval_forecast(df, datetime_col='datetime', target_col='consumption')

Trains a Gradient Boosting model using time features and smoothed temperature data to forecast energy consumption. Splits data into train/test sets and returns test data with forecasts.


plot_forecast(df, datetime_col='datetime', target_col='consumption')

Plots interactive time series comparing actual consumption with forecasts, showing MAPE on the plot.


calculate_mape(df, datetime_col='datetime', target_col='consumption')

Returns the MAPE between actual and predicted consumption using the forecasting model.


get_temp_smoothed_fr(start_date, end_date)

Fetches hourly smoothed temperatures averaged over multiple major French cities.


get_spot_price_fr(token, start_date, end_date)

Retrieves hourly spot prices for the French electricity market (EPEX) from Databricks.


get_forward_price_fr(token, cal_year)

Fetches annual forward prices for French electricity (EEX) for a specified calendar year.


get_pfc_fr(token, cal_year)

Retrieves and resamples hourly Price Forward Curve data for French electricity (EEX) for a specified calendar year.


calculate_prem_risk_vol(token, input_df, datetime_col, target_col, plot_chart=False, quantile=50)

Calculates a risk premium based on forecast errors and forward price curves. Returns the premium value for the requested quantile and optionally plots the distribution.


Author


License

MIT License — see LICENSE file for details.


Contributions

Contributions are welcome! Please open issues or pull requests on GitHub for suggestions or bug reports.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

octoanalytics-0.2.0.tar.gz (14.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

octoanalytics-0.2.0-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

Details for the file octoanalytics-0.2.0.tar.gz.

File metadata

  • Download URL: octoanalytics-0.2.0.tar.gz
  • Upload date:
  • Size: 14.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.6

File hashes

Hashes for octoanalytics-0.2.0.tar.gz
Algorithm Hash digest
SHA256 b6d67f5f62ae5c26b6eee6dd4208b608248dd7c23c3c1ae1f95c3e3892b7a7ed
MD5 6b2bba624ca81da77d8c43ffc4acb6da
BLAKE2b-256 25859c02018c0ab9a137eff8dc9a3cf5109eee39aa3530c088fa58fca732c97a

See more details on using hashes here.

File details

Details for the file octoanalytics-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: octoanalytics-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 12.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.6

File hashes

Hashes for octoanalytics-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7e4f205a4f4cc0028ea5b37e4d82609957da02da5878728d81d8052851ddb757
MD5 7c762394ae2f643db84fe59998e743c7
BLAKE2b-256 3fa1390a53877be521b93b50fc47219f23d04ca3c8f86bca9eb854921a98bb67

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page