> For the complete documentation index, see [llms.txt](https://docs.gridstatus.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.gridstatus.io/developers/concepts/recipes/trading-hub-price-analysis.md).

# 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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
