Jump to content
  • Enable Holt-Winters Forecast in Spotfire® Consumer and Business Author


    The Holt-Winters Forecast uses Spotfire Enterprise Runtime for R to compute the Holt-Winters filtering of a time series or anything that can be coerced to a time series. This is an exponentially weighted moving average filter of the level, trend, and seasonal components of a time series. The smoothing parameters are chosen to minimize the sum of the squared one-step-ahead prediction errors.

    In Spotfire Analyst, Forecast is available as a context-menu option in Line Charts, Bar Charts and other visualization with time series, A custom tool can easily be created to enable the same functionality in the Consumer and Business Author clients. 

    This tutorial shows the steps needed to create the custom tool and also includes an example implementation in the attached .zip file.

    The example tool adds a Forecast context menu option to all Line Charts:




    Selecting "Forecast" results in the following:





    • Spotfire® Analyst, see download instructions here.
    • Spotfire® Developer (SDK), see download instructions here.
      • To try out the example as-is, you don't need a Developer since the attached zip file contains a ready-build Spotfire package file.
    • Spotfire® Statistics Services, download from edelivery.
    • Spotfire® Server, download from edelivery
      • Assign the installed Spotfire® Statistics Services URL to the "Spotfire Enterprise Runtime for R URL" preference. This is done in the Administration Manager tool in  Spotfire Analyst.
    • Microsoft Visual Studio® 2013 or higher. The free Community edition is available for download here.

    See Also


    This Custom Tool in this example adds a Forecast menu option to Line Charts, defined in the code by setting LineChart as the tool context in the tool class. This can easily be generalized to support more visualization types. Read more about tool contexts here.

     public class HoltWintersTool : CustomTool<LineChart> 

    Since the Holt-Winters algorithm is already part of the Spotfire Fitting Model framework it is fairly easy to implement the tool logic.

    Note: Tools in the web client must implement ExecuteAndPromptCore rathe than ExecuteCore, whether they are prompting or not.

    protected override IEnumerable<object> ExecuteAndPromptCore(LineChart context)
      var models = context.FittingModels;
      var holtWinters = models.OfType<ForecastHoltWintersFittingModel>().ToList();
      if (holtWinters.Count == 0)
        // Add a new model and configure defaults
        models.Transactions.ExecuteTransaction(() =>
          var forecast = models.AddForecastHoltWinters();
          // Configure forecast
          forecast.AutomaticFrequency = true;
          forecast.UseSeasonal = true;
          forecast.TimePointsAhead = 12;
          forecast.IndividualFittingModes = IndividualFittingModes.Color | IndividualFittingModes.Trellis;
          // Change settings for curves
          forecast.ForecastCurve.LineStyle = LineStyle.Dot;
          forecast.ConfidenceCurve.Visible = false;
        // Update enabled state on all models
        bool hasEnabled = holtWinters.Any(m => m.Enabled);
        holtWinters.ForEach(hwModel => hwModel.Enabled = !hasEnabled);
      return base.ExecuteAndPromptCore(context);

    To keep the example simple, many parameters have hard-coded default values that are not taking the visualization configuration into account. For instance, the TimePointsAhead = 12 works best when Month is the lowest level in the time hierarchy in the Line Chart's x-axis. A more generalized tool should apply some heuristics to set the correct parameters that adapt to how the visualization is configured. 

    Another thing that is missing from the example is a GUI to change the forecast parameters. 


    To run the example as it is, deploy the HoltWintersToolExample.spk file (included in the attached zip file) to a Spotfire Server. For a detailed description of how to do this, read the Adding software packages to a deployment area in the Spotfire Server Installation and Administration Manual. Make sure that  Spotfire Enterprise Runtime for R is configured properly. Assign the installed Spotfire® Statistics Services URL to the "Spotfire Enterprise Runtime for R URL" preference. This is done in the Administration Manager tool in Spotfire Analyst.

    If you modify the example, you will need to create a new package file. Before creating the package file, make sure to set the Intended Client to: Spotfire Web Client. Read about how to set up the development environment and how to configure, run and deploy extensions here.



    User Feedback

    Recommended Comments

    There are no comments to display.

  • Create New...