The Croston TSB method is a forecast strategy for products with intermittent demand. It is a modification of Croston's method and uses separate single exponential smoothing for demand probability and demand size. The TSB model can be expressed using specific formulas. The method supports two different algorithm types: constant mode and sporadic mode. In constant mode, the average demand between two non-zero demands is used, while in sporadic mode, the demand at the non-zero demand time is predicted.
------

SET SCHEMA DM_PAL;

DROP TABLE PAL_CROSTONTSB_DATA_TBL;
CREATE COLUMN TABLE PAL_CROSTONTSB_DATA_TBL (
    "ID" INT,
    "RAWDATA" DOUBLE
);
INSERT INTO PAL_CROSTONTSB_DATA_TBL VALUES (0, 0.0);
INSERT INTO PAL_CROSTONTSB_DATA_TBL VALUES (1, 0.0);
INSERT INTO PAL_CROSTONTSB_DATA_TBL VALUES (2, 4.0);
INSERT INTO PAL_CROSTONTSB_DATA_TBL VALUES (3, 0.0);
INSERT INTO PAL_CROSTONTSB_DATA_TBL VALUES (4, 0.0);
INSERT INTO PAL_CROSTONTSB_DATA_TBL VALUES (5, 0.0);
INSERT INTO PAL_CROSTONTSB_DATA_TBL VALUES (6, 5.0);
INSERT INTO PAL_CROSTONTSB_DATA_TBL VALUES (7, 3.0);
INSERT INTO PAL_CROSTONTSB_DATA_TBL VALUES (8, 0.0);
INSERT INTO PAL_CROSTONTSB_DATA_TBL VALUES (9, 0.0);
INSERT INTO PAL_CROSTONTSB_DATA_TBL VALUES (10, 0.0);

DROP TABLE #PAL_PARAMETER_TBL;
CREATE LOCAL TEMPORARY COLUMN TABLE #PAL_PARAMETER_TBL (
    "PARAM_NAME" VARCHAR (256),
    "INT_VALUE" INTEGER,
    "DOUBLE_VALUE" DOUBLE,
    "STRING_VALUE" VARCHAR (1000)
);
INSERT INTO #PAL_PARAMETER_TBL VALUES ('ALPHA', NULL,0.1,NULL);
INSERT INTO #PAL_PARAMETER_TBL VALUES ('BETA', NULL,0.1,NULL);
INSERT INTO #PAL_PARAMETER_TBL VALUES ('FORECAST_NUM',10, NULL,NULL);
INSERT INTO #PAL_PARAMETER_TBL VALUES ('METHOD',1, NULL,NULL);
INSERT INTO #PAL_PARAMETER_TBL VALUES('MEASURE_NAME',NULL,NULL,'MAPE');
INSERT INTO #PAL_PARAMETER_TBL VALUES('EXPOST_FLAG',1,NULL,NULL);
INSERT INTO #PAL_PARAMETER_TBL VALUES('REMOVE_LEADING_ZEROS',0,NULL,NULL);

CALL "_SYS_AFL"."PAL_CROSTONTSB"(PAL_CROSTONTSB_DATA_TBL, #PAL_PARAMETER_TBL, ?, ?, ?);
