/*
   tssmooth hwinters

*! VERSION 1.1.1  03mar2005

*/

VERSION 9.0
INCLUDE _std_large
INCLUDE _ht350
INCLUDE header
HELP hlp1, view("help tssmooth_hwinters")
RESET res1

DIALOG main, label("tssmooth hwinters - Holt-Winters nonseasonal smoothing") /*
		*/ tabtitle("Main")
BEGIN
  DEFINE _x _xsetbu
  DEFINE _y _top
  INCLUDE _bu_tsset

  TEXT     tx_gener    _lft      _ss       _cwd3_1   .,			/*
  		*/label("New variable:")

  TEXT     tx_exp      _lft3_2   @         _comb3_1  .,			/*
  		*/label("Expression to be forecast: ")

  EDIT     ed_gener    _lft      _ss       _vnwd     .,			/*
  		*/label("New variable ")

  TEXT     tx_equals   _eqxpos   @         _eqwd     .,			/*
  		*/center						/*
  		*/label("=")

  EXP      ex_exp      _lft3_2   @         _comb3_1  .,			/*
  		*/label("Create ...")					/*
  		*/error("Expression to be forecast")

DEFINE _x _lft
DEFINE _y _ls
DEFINE _cx _cwd1
INCLUDE _type
DEFINE holdy @y

  CHECKBOX ck_replace  _lft3_2	 holdy	   _cwd2     .,			/*
		*/ option(replace) nomem				/*
		*/ label("Replace existing variable")

  GROUPBOX gb_opts     _lft      +35       _iwd      _ht16h,		/*
		*/ label("Options")

  RADIO    rb_parms1   _ilft     _ss       _cwd2     .,			/*
  		*/ label("Choose smoothing parameter to")		/*
		*/ clickon(script main_parms_on)			/*
		*/ first

  DEFINE holdy1 @y

  TEXT     tx_parms1    _indent2  _vss      _inwd     .,		/*
  		*/label("minimize sum-of-squared forecast")
  TEXT     tx_parms2   @         _vss      @         .,			/*
  		*/label("errors")

  RADIO    rb_parms2   _lft4_3   holdy1    _cwd2     .,			/*
  		*/ label("Specify smoothing parameter:")		/*
		*/ clickon(script main_parms_off)			/*
		*/ last

  TEXT     tx_parms3    _indent2  _vss      _inwd     .,		/*
  		*/label("(Parameter must be in [0,1])")

  EDIT     ed_parms1   @         _ss       _en7wd    ., numonly		/*
  		*/ label("First box for smooth parameter")

  DEFINE holdy2 @y

  EDIT     ed_parms2   +80       holdy2	   _en7wd    ., numonly		/*
  		*/ label("Second box for smooth parameter")

  CHECKBOX ck_samp0    _ilft     _ms       _cwd2     .,			/*
  		*/ label("# of observations to be used to")		/*
  		*/ clickon(script main_samp0_on)			/*
    		*/ clickoff(script main_samp0_off)
  DEFINE holdy3 @y
  TEXT     tx_samp0    _indent2  _vss      _inwd     .,			/*
  		*/label("obtain initial values for recursion:")

  SPINNER  sp_samp0    @         _ss	   _spwd     .,			/*
  		*/ option(samp0)					/*
      		*/ min(2)						/*
      		*/ max(c(N))						/*
		*/ default(2)

  CHECKBOX ck_s0       _ilft4_3  holdy3	   _cwd2     .,			/*
		*/ label("Initial values for the recursion:")		/*
		*/ clickon(script main_s0_on)				/*
  		*/ clickoff(script main_s0_off)

  EDIT     ed_s01      _indent2  _ss   	   _en7wd    .,	numonly		/*
  		*/ label("First starting values for recursion")

  EDIT     ed_s02      +80       @         _en7wd    .,	numonly		/*
  		*/ label("Second starting values for recursion")

  CHECKBOX ck_for      _ilft     _xls      _cwd1     .,			/*
  		*/ label("Periods for out-of-sample forecast:")		/*
		*/ clickon(gaction main.sp_for.enable)			/*
  		*/ clickoff(gaction main.sp_for.disable)

  SPINNER  sp_for      _indent2  _ss       _spwd     .,			/*
  		*/ option(forecast)					/*
  		*/ min(1)						/*
  		*/ max(500)						/*
		*/ default(1)


END

DIALOG opt, tabtitle("Options")
BEGIN
  CHECKBOX ck_diff     _lft      _top      _iwd      .,			///
	option(diff)							///
	label("Obtain initial value for the recursion on the linear term by averaging the")

  TEXT     tx_diff1    _indent2  _vss      _inwd     .,			///
	label("first-difference of the expression to be smoothed, and obtain the starting value")

  TEXT     tx_diff2    @         _vss      @         .,			///
	label("for the constant as a0=x1-b0.")
END

SCRIPT POSTINIT
BEGIN
	script max_setDefaultDifficult
	script max_setFromForHwinters
END

INCLUDE ifin
INCLUDE _type_list_fd
INCLUDE max_ml

SCRIPT main_parms_on
BEGIN
	gaction main.ed_parms1.disable
	gaction main.ed_parms2.disable
	script max_from_enable
END

SCRIPT main_parms_off
BEGIN
	script max_from_disable
	gaction main.ed_parms1.enable
	gaction main.ed_parms2.enable
END

SCRIPT main_samp0_on
BEGIN
	gaction main.ck_s0.disable
	gaction main.ed_s01.disable
	gaction main.ed_s02.disable
	gaction main.sp_samp0.enable
END

SCRIPT main_samp0_off
BEGIN
	gaction main.sp_samp0.disable
	gaction main.ck_s0.enable
END

SCRIPT main_s0_on
BEGIN
	gaction main.sp_samp0.disable
	gaction main.ck_samp0.disable
	gaction main.tx_samp0.disable
	gaction main.ed_s01.enable
	gaction main.ed_s02.enable
END

SCRIPT main_s0_off
BEGIN
	gaction main.ed_s01.disable
	gaction main.ed_s02.disable
	gaction main.ck_samp0.enable
	gaction main.tx_samp0.enable
END

PROGRAM command
BEGIN
	put "tssmooth hwinters "
	INCLUDE _type_pr
	require main.ed_gener
	put main.ed_gener
	put " "
	put "= "
	require main.ex_exp
	put main.ex_exp
	INCLUDE _ifin_pr
	beginoptions
		if main.rb_parms2 {
			require main.ed_parms1
			require main.ed_parms2
			put "parms("
			put main.ed_parms1
			put " "
			put main.ed_parms2
			put ")"
			put " "
		}

		if main.ck_s0 {
		   	require main.ed_s01
		   	require main.ed_s02
			put "s0("
			put main.ed_s01
			put " "
			put main.ed_s02
			put ")"
			put " "
		}
		if main.ck_samp0 {
			optionarg main.sp_samp0
		}
		if main.ck_for {
			optionarg main.sp_for
		}
		option main.ck_replace
		option opt.ck_diff
		put " " /program max_output
	endoptions

END
