macrosynergy.visuals.acf#

Functions used to visualize autocorrelation and partial autocorrelation functions.

plot_acf(df, cids, xcat, lags=30, alpha=0.05, freq='D', agg='sum', remove_zero_predictor=False, start=None, end=None, blacklist=None, figsize=(16, 9), title=None, ncol=3, share_x=True, share_y=True, zero=False, auto_ylims=True, return_fig=False, **kwargs)[source]#

Plots a facet grid of autocorrelation functions for a given xcat and multiple cids.

Parameters:#

dfpd.DataFrame

The input DataFrame with columns [‘real_date’, ‘cid’, ‘xcat’, ‘value’].

cidsList[str]

List of cids to plot.

xcatstr

The xcat to filter and plot ACFs for.

lagsUnion[int, Sequence], default=30

Number of lags for ACF calculation. If an integer, the lags from 1 to lags are plotted. If a sequence is provided, the lags are plotted as given.

alphafloat, default=0.05

Significance level for the confidence intervals.

freqstr, default=’D’

Frequency to aggregate the data to before computing ACF. Accepts pandas frequency aliases such as ‘D’ (daily), ‘W’ (weekly), ‘M’ (monthly), etc.

aggstr, default=’sum’

Aggregation function to use when resampling to a lower frequency. Common values: ‘sum’, ‘mean’, ‘last’.

remove_zero_predictorbool, default=False

Remove zeros from the input series.

blacklistdict

cross-sections with date ranges that should be excluded from the data frame. If one cross-section has several blacklist periods append numbers to the cross-section code.

startstr

ISO-8601 formatted date string. Select data from this date onwards. If None, all dates are selected.

endstr

ISO-8601 formatted date string. Select data up to and including this date. If None, all dates are selected.

figsizeTuple[float, float], default=(16,9)

Figure size for the plot.

titleOptional[str], default=None

Title for the plot.

ncolint, default=3

Number of columns in the facet grid.

share_xbool, default=True

Share x-axis across all subplots.

share_ybool, default=True

Share y-axis across all subplots.

zerobool, default=False

Include the zero lag in the plot.

auto_ylimsbool, default=True

Automatically set the y-axis limits for each subplot.

kwargsDict

Additional keyword arguments for the plot passed directly to Facetplot.lineplot.

plot_pacf(df, cids, xcat, lags=30, alpha=0.05, freq='D', agg='sum', remove_zero_predictor=False, method='ywm', start=None, end=None, blacklist=None, figsize=(16, 9), title=None, ncol=3, share_x=True, share_y=True, zero=False, auto_ylims=True, return_fig=False, **kwargs)[source]#

Plots a facet grid of partial autocorrelation functions for a given xcat and multiple cids.

Parameters:#

dfpd.DataFrame

The input DataFrame with columns [‘real_date’, ‘cid’, ‘xcat’, ‘value’].

cidsList[str]

List of cids to plot.

xcatstr

The xcat to filter and plot PACFs for.

lagsUnion[int, Sequence], default=30

Number of lags for PACF calculation. If an integer, the lags from 1 to lags are plotted. If a sequence is provided, the lags are plotted as given.

alphafloat, default=0.05

Significance level for the confidence intervals.

freqstr, default=’D’

Frequency to aggregate the data to before computing PACF. Accepts pandas frequency aliases such as ‘D’ (daily), ‘W’ (weekly), ‘M’ (monthly), etc.

aggstr, default=’sum’

Aggregation function to use when resampling to a lower frequency. Common values: ‘sum’, ‘mean’, ‘last’.

remove_zero_predictorbool, default=False

Remove zeros from the input series.

methodstr, default=’ywm’

Method for Statsmodel’s PACF calculation. Must be one of [‘ywm’, ‘ywmle’, ‘yw’, ‘ywadjusted’, ‘ols’, ‘ols-adjusted’].

blacklistdict

cross-sections with date ranges that should be excluded from the data frame. If one cross-section has several blacklist periods append numbers to the cross-section code.

startstr

ISO-8601 formatted date string. Select data from this date onwards. If None, all dates are selected.

endstr

ISO-8601 formatted date string. Select data up to and including this date. If None, all dates are selected.

figsizeTuple[float, float], default=(16,9)

Figure size for the plot.

titleOptional[str], default=None

Title for the plot.

ncolint, default=3

Number of columns in the facet grid.

share_xbool, default=True

Share x-axis across all subplots.

share_ybool, default=True

Share y-axis across all subplots.

zerobool, default=False

Include the zero lag in the plot.

auto_ylimsbool, default=True

Automatically set the y-axis limits for each subplot.

kwargsDict

Additional keyword arguments for the plot passed directly to Facetplot.lineplot.