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_temperature_lissee_france, 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_temperature_lissee_france('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_temperature_lissee_france(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.1.0.tar.gz (9.9 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.1.0-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for octoanalytics-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d6a65e366dc3b1927e9103c412bed76ef750b7243be53ebacaa71085b455e052
MD5 cb945a3b88ee1be4acbdcea6ddcaf103
BLAKE2b-256 0855bc19094f7e3b7a5ab9853e011eb15d5fab328047aa1f05803af6aa281bf4

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for octoanalytics-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4c525f6cdea58b3798c5655066b923a7d0583fe3337a388c2172db74a8a81528
MD5 05668aad19c3ec4657d497b99e43ce1c
BLAKE2b-256 ec7b8e0622277fd0aae065a09915e39611eedd08fc46c0305a1b0fd74fc78387

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