ForecastPlots.ForecastPlotsModule

Package: ForecastPlots

Collection of plot functionalities for time series analysis. The available plots are:

• acf: Auto-Correlation plot
• candle: Candelstick plot for stock prices
• ccf: Cross-Correlation plot
• dplot: Decomposition plot for Data, Trend, Seasonality and Remainder.
• fplot: Multivariate forecasting plots with with prediction intervals.
• pacf: Partial Auto-Correlation plot
• splot: Seasonal plot, similar to monthplot in R.
ForecastPlots.acfMethod

Package: ForecastPlots

acf(x;
type = "cor",
lag = Integer(ceil(10*log10(length(x)))),
alpha = (0.95,0.99);
plot = true)

Compute the auto-correlation or auto-covariance for an univariate series with an optional plot.

The results are normalized to preserve homoscedasticity. The distribution used to normalize the data is an approximation of a Fisher Transformation via a Normal Distribution. There is a plot recipe for the returned object, if the type is cor the plot will also show confidence intervals for the given alpha values.

Arguments

• x: Vector or uni-dimensional DataFrame of data.
• type: Valid values are "cor" for correlation (default) and "cov" for convariance.
• lag: Maximum number of lags.
• alpha: A tuple with two thresholds (t1,t2) with t1 <= t2 to plot confidence intervals. The default values are 0.95 and 0.99.
• plot: When true displays a plot with the results.

Returns

A CF object and optional plot

Examples

x = rand(100);
acf(x; type="cor");
acf(x; type="cor", plot=false)
20-element Vector{Float64}:
-0.07114015325321181
-0.045271910181007916
0.19300008480298597
[...]
ForecastPlots.candleFunction

Package: ForecastPlots

candel(x, t, args...; colors = (:green, :red), kw...)

Plot a candlestick for stock prices

Arguments

• x: Matrix with four columns for Open, High, Low and Close values.
• t: Vector with time units, it defaults to 1:size(x,1)
• args...: plot arguments
• colors: Tuple with the up and down color symbols, it defaults to (:green,:red)
• kw...: plot keyword arguments

Returns

Candle plot

Examples

using MarketData

x = yahoo(:INTC)
last_month_intc = values(x)[end-30:end,1:4]
candle(last_month_intc)
candle(last_month_intc,timestamp(x)[end-30:end])
candle(last_month_intc,timestamp(x)[end-30:end]; colors=(:white,:black), title = "INTC")
ForecastPlots.ccfMethod

Package: ForecastPlots

ccf(x1::{AbstractVector,DataFrame},
x2::{AbstractVector,DataFrame};
type = "cor",
lag = Integer(ceil(10*log10(length(x1)))),
alpha = (0.95,0.99);
plot = true)

Compute the cross-correlation or cros-covariance of two univariate series with an optional plot

The results are normalized to preserve homoscedasticity. The distribution used to normalize the data is an approximation of a Fisher Transformation via a Normal Distribution. There is a plot recipe for the returned object, if the type is cor the plot will also show confidence intervals for the given alpha values.

If, for a given integer k, x2 repeats x1 values such that x1[t] = x2[t+k] for all i then high correlation value will be placed at the right from the center in the results. That is, this convention will be represented in the plots as x1_t = x2_{t+k} -> _____0__k__ meaning x2 behavior can be predicted by x1 in k units.

Arguments

• x1: Vector or uni-dimensional DataFrame of data.
• x2: Vector or uni-dimensional DataFrame of data.
• type: Valid values are "cor" for correlation (default) and "cov" for convariance.
• lag: Maximum number of lags.
• alpha: A tuple with two thresholds (t1,t2) with t1 <= t2 to plot confidence intervals. The default values are 0.95 and 0.99.
• plot: When true displays a plot with the results.

Returns

Cros-correlation vector with an optional plot

Examples

x1 = rand(100);
x2 = circshift(x1,6);
ccf(x1, x2; type="cor");
ccf(x1, x2; type="cor", plot = false)
41-element Vector{Float64}:
0.09861519494432992
-0.04384418688776631
-0.1900182513825246
[...]
ForecastPlots.dplotMethod

Package: ForecastPlots

dplot(x; dlabels = ["Data","Trend","Seasonal","Remainder"])

Plot a seasonal, trend and remainder decomposition of a time series.

Arguments

• x: Matrix with three columns containing sesonality, trend and remainder decomposition
• dlabels: String array of length four containing labels for data, seasonality, trend and remainder.

Returns

Sesonal decomposition plot with scale bars

Examples

dplot(randn(100,3))
dplot(randn(100,3); labels = ["數據","趨勢","季節性","剩餘"])
dplot(rand(100,3),now()-Day(99):Day(1):now())
ForecastPlots.fplotFunction

Package: ForecastPlots

fplot(x0, x1, px1, t=1:size(x0,1)+size(x1,1), args...;
plt = palette([:blue,:red],max(2,size(x0,2))), kw...)

Plot time series with its prediction intervals

Arguments

• x0: Vector or Matrix with time series
• x1: Vector of Matrix forecast for x0
• px1: Prediction intervals for x1 with size(px1) == (size(x1,1),2,N) where N is the number of intervals provided with the format [lowx1, highx1].
• t: Values for the temporal axis, it defaults to intengers starting at 1.
• args...: plot arguments
• plt: palette of colors for the time series, it defaults to palette([:blue,:red],max(2,size(x0,2)))
• kw...: plot keyword arguments

Returns

Forecast plots

Examples

x0 = rand(20);
x1 = rand(10);
px1 = zeros(10,2,2);
px1[:,1,1] .= -0.2; px1[:,2,1] .= 0.2;
px1[:,1,2] .= -0.4; px1[:,2,2] .= 0.4;

fplot(x0,x1,px1)

xb0 = rand(20) .+ 2;
xb1 = rand(10) .+ 2;
px1 = zeros(10,2,2,2)
px1[:,1,1,1] .= -0.2; px1[:,2,1,1] .= 0.2;
px1[:,1,2,1] .= -0.4; px1[:,2,2,1] .= 0.4;
px1[:,1,1,2] .= -0.2; px1[:,2,1,2] .= 0.2;
px1[:,1,2,2] .= -0.4; px1[:,2,2,2] .= 0.4;

xx0 = [x0 xb0]
xx1 = [x1 xb1]
fplot(xx0, xx1, px1)

using Dates
fplot(x0,x1,px1,now()-Day(20+10-1):Day(1):now())
ForecastPlots.pacfMethod

Package: ForecastPlots

pacf(x,
type = "step-real",
lag = Integer(ceil(10*log10(length(x)))),
alpha = (0.95,0.99);
plot = true)

Compute the partial auto-correlation for an univariate series with an optional plot.

There are two versions; the "step" version estimates the auto-regressive parameters of an increasing model, the "real" version estimates the actual partial auto-correlation by eliminating the linear information provided by the lags. When using the default type "stepwise-real" both versions are calculated.

The distribution used to estimate the confidence intervals is an approximation of a Fisher Transformation via a Normal Distribution. There is a plot recipe for the returned object.

Arguments

• x: Vector of data.
• type = Valid values are "stepwise", "real" and "stepwise-real".
• lag: Maximum number of lags.
• alpha: A tuple with two thresholds (t1,t2) with t1 <= t2 to plot confidence intervals. The default values are 0.95 and 0.99.
• plot: When true displays a plot with the results.

Returns

A CF object

Examples

x = rand(100);
pacf(x);
pacf(x; plot=false)
20×2 Matrix{Float64}:
-0.0475437   -0.101204
0.0407006    0.058935
-0.0747269    0.0366026
ForecastPlots.splotMethod

Package: ForecastPlots

splot(x, labels; plot = true)

Plot a seasonal plot of x based on the parameter labels

Arguments

• x: Regular timed observations
• labels: This parameter accepts Integer, String and Vector values. - When an Integer the labels are 1:labels. - When a Vector the sorted labels are specified within. - When a String it accepts values "month", "day" and "quarter"m, by default the first value of x to fall in "Jan", "Mon" or "Q1", if other initial values are required labels must be specified in a vector.
• plot: When true the splot is displayed, otherwise only the seasonal per column matrix is returned.

Returns

Matrix with seasonal data by column with an optional plot

Examples

splot(rand(120),"month");
splot(rand(120),"quarter");
splot(rand(120),"day"; plot=false)
18×7 Matrix{Union{Missing, Float64}}:
0.799164   0.214773   0.957464   0.969107   0.5886    0.153288   0.298444
0.631211   0.539124   0.728887   0.235045   0.398699  0.492781   0.332502
0.691047   0.473517   0.834303   0.0316447  0.208999  0.231782   0.00797575