# Trading Hub Price Analysis

Compare prices across trading hubs to identify arbitrage opportunities and congestion patterns.

```python
import pandas as pd

# Fetch one week of hourly average prices for major ERCOT hubs
df = client.get_dataset(
    "ercot_lmp_by_settlement_point",
    start="2026-01-01",
    end="2026-01-08",
    filter_column="location",
    filter_value="HB_HOUSTON,HB_NORTH,HB_WEST,HB_SOUTH",
    filter_operator="in",
    columns=["interval_start_utc", "location", "lmp"],
    resample="1 hour",
    resample_function="mean"
)

# Pivot to get locations as columns
df_pivot = df.pivot(index='interval_start_utc', columns='location', values='lmp')

# Calculate price spreads
df_pivot['Houston_North'] = df_pivot['HB_HOUSTON'] - df_pivot['HB_NORTH']
df_pivot['Houston_West'] = df_pivot['HB_HOUSTON'] - df_pivot['HB_WEST']

# Summary statistics
print("=== Hub Price Spread Analysis ===")
print(f"\nHouston-North Spread:")
print(f"  Mean: ${df_pivot['Houston_North'].mean():.2f}/MWh")
print(f"  Max: ${df_pivot['Houston_North'].max():.2f}/MWh")
print(f"  Min: ${df_pivot['Houston_North'].min():.2f}/MWh")
print(f"  Std Dev: ${df_pivot['Houston_North'].std():.2f}/MWh")

print(f"\nHouston-West Spread:")
print(f"  Mean: ${df_pivot['Houston_West'].mean():.2f}/MWh")
print(f"  Max: ${df_pivot['Houston_West'].max():.2f}/MWh")

# Find hours with largest spreads (potential congestion)
print(f"\n=== Top 5 Hours with Largest Houston-North Spread ===")
top_spreads = df_pivot.nlargest(5, 'Houston_North')[['HB_HOUSTON', 'HB_NORTH', 'Houston_North']]
print(top_spreads)
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.gridstatus.io/developers/concepts/recipes/trading-hub-price-analysis.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
