SETS:
! Estimate the Bass model for new product sales(BASSMODEL);
! Keywords: forecasting, Bass model, new product diffusion,
  Logistic curve;
! Bass(1969) introduced a model for predicting 
  first purchases of a new product. 
  The following three parameters specify the model:
     M  = estimate of the market size,  that is, 
          the total number of customers that will 
          eventually buy the product. 
          For simplicity,  we assume that the product is a
          durable good,  so that a customer will
          purchase it at most once.
      p = probability that a candidate customer in a given
          period will purchase the product just by chance,
          without any influence from existing customers.
          These folk are called the innovators.
      q = rate at which a candidate customer is induced 
          to purchase the product because of interaction with
          existing customers.  The greater the number of 
          existing customers,  the greater the inducement.
          These folk are the followers;
 ! If p = 0, then the Bass model approximates a discrete time
   version of the logistic model for total cumulative sales.
   If q = 0, then the Bass model approximates a discrete time
   version of the exponential cdf for total cumulative sales;

 PERIOD: SALES, CUM, ERROR, FORECAST;
ENDSETS
DATA: ! Weekly sales data for the movie: "The Doctor", see Lilien & Rangaswamy; PERIOD = 1..12; SALES = 0.1 3.0 5.2 7.0 5.25 4.9 3.0 2.4 1.9 1.3 0.8 0.6; ! No. of observations for "training" model; TRAINON = 9; ! Upper and lower limits on parameters; ULP = 1.0; ULQ = 1.0; ULM = 9999; LLP = 0.0; LLQ = 0.0; LLM = 0.0; ENDDATA ! Errors can be negative or positive; @FOR( PERIOD( T): @FREE( ERROR( T)); @FREE( FORECAST(T)); ); FORECAST( 1) = P * M; CUM( 1) = SALES( 1); ERROR( 1) = FORECAST(1) - SALES( 1); @FOR( PERIOD( T)| T #GT# 1: ! The fundamental forecast formula; FORECAST( T) = ( P + Q * CUM( T - 1)/ M)*( M - CUM( T - 1)); CUM( T) = SALES( T) + CUM( T - 1); ERROR( T) = FORECAST( T) - SALES( T); ); MIN = ! Min sum of squared errors on training sample; @SUM( PERIOD( T)| T #LE# TRAINON: ERROR( T) * ERROR( T)); ! Enforce bounds on parameters; @BND( LLP, P, ULP); @BND( LLQ, Q, ULQ); @BND( LLM, M, ULM);