plot_seasonality
function backtide.analysis.seasonality.plot_seasonality(data, price_col="close", title=None, legend=None, figsize=(900, 600), filename=None, display=True)[source]
Create a seasonality heatmap.
For daily or longer intervals, aggregates returns into calendar months and displays a year x month grid. For intraday intervals, displays a day-of-week x hour grid of average returns. Useful for spotting recurring seasonal or intraday patterns.
| Parameters |
data : pd.DataFrame | pl.DataFrame
Input data containing columns
price_col : str, default="close"symbol, the column specified by
price_col, and dt with the datetime.
Column name used to compute returns.
title : str | dict | None, default=None
Title for the plot.
legend : str | dict | None, default=None
Legend for the plot. Defaults to None since a colorbar is shown
instead.
figsize : tuple[int, int], default=(900, 600)
Figure's size in pixels, format as (x, y).
filename : str | Path | None, default=None
Save the plot using this name. The type of the file depends on the
provided name (
display : bool | None, default=True.html, .png, .pdf, etc...). If filename has no
file type, the plot is saved as .html. If None, the plot isn't saved.
Whether to render the plot. If
None, it returns the figure.
|
| Returns |
Figure | None
The Plotly figure object. Only returned if
display=None.
|
See Also
Create a correlation heatmap.
Create a drawdown chart.
Create a returns distribution histogram.
Example
>>> from backtide.storage import query_bars
>>> from backtide.analysis import plot_seasonality
>>> # Daily interval
>>> df = query_bars("AAPL", "1d")
>>> plot_seasonality(df.iloc[-5 * 250:, :]) # Just show the last 5 years
>>> # Intraday interval
>>> df = query_bars("AAPL", "1h")
>>> plot_seasonality(df)