Implements FastAPI backend with ML model support for energy trading, including price prediction models and RL-based battery trading policy. Features dashboard, trading, backtest, and settings API routes with WebSocket support for real-time updates.
19 lines
540 B
Python
19 lines
540 B
Python
from typing import List
|
|
import pandas as pd
|
|
|
|
|
|
def add_regional_features(df: pd.DataFrame, regions: List[str]) -> pd.DataFrame:
|
|
result = df.copy()
|
|
|
|
if "region" in result.columns and "real_time_price" in result.columns:
|
|
avg_price_by_region = result.groupby("region")["real_time_price"].mean()
|
|
|
|
for region in regions:
|
|
region_avg = avg_price_by_region.get(region, 0)
|
|
result[f"price_diff_{region}"] = result["real_time_price"] - region_avg
|
|
|
|
return result
|
|
|
|
|
|
__all__ = ["add_regional_features"]
|