Giter Club home page Giter Club logo

holt_winters's Introduction

Holt-Winters Triple Exponential Smoothing Algorithm

A Ruby port of Nishant Chandra's Java implementation of the Holt-Winters smoothing algorithm.

Algorithm

The equations are intended to give more weight to recent observations and less weights to observations further in the past.
These weights are geometrically decreasing by a constant ratio.

Usage

forecast()

It calculates the initial values and returns the forecast for m periods.

# y           Time series array
# alpha       Level smoothing coefficient
# beta        Trend smoothing coefficient (increasing beta tightens fit)
# gamma       Seasonal smoothing coefficient
# period      A complete season's data consists of L periods. And we need
#             to estimate the trend factor from one period to the next. To
#             accomplish this, it is advisable to use two complete seasons;
#             that is, 2L periods.  
# m           Extrapolated future data points
#             - 4 quarterly
#             - 7 weekly
#             - 12 monthly
def forecast(y, alpha, beta, gamma, period, m)
  # ...
end

Example

This will generate a several variations of beta for a simple line:

require 'holt_winters'

x = (0..128).to_a
puts x.join(',')
puts HoltWinters.forecast(x, 0.5, 0, 0, 12, 2).join(',')
puts HoltWinters.forecast(x, 0.5, 0.25, 0, 12, 2).join(',')
puts HoltWinters.forecast(x, 0.5, 0.5, 0, 12, 2).join(',')
puts HoltWinters.forecast(x, 0.5, 0.75, 0, 12, 2).join(',')
puts HoltWinters.forecast(x, 0.5, 1.0, 0, 12, 2).join(',')

Try plotting the different lines to see how beta affects the forecast:

Chart

License

(The MIT-License)

Copyright (c) 2011 Brandon Keene

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

holt_winters's People

Contributors

cmdrkeene avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

holt_winters's Issues

Division by zero

In algorithm some elements of overall smoothing (St) or seasonal smoothing (It) sequences, that are denominators, could be equal or close to zero. This causes unexpected forecast values, and could be even if series data (y) consists of big positive numbers (for example, if trend becomes less than 0). Is there way to fix this problem? Thank you for any advice.

Some problem about the formula

  • St[i] = alpha * y[i] / It[i - period] + (1.0 - alpha) * (St[i - 1] + Bt[i - 1])
  • Bt[i] = gamma * (St[i] - St[i - 1]) + (1 - gamma) * Bt[i - 1]
  • It[i] = beta * y[i] / St[i] + (1.0 - beta) * It[i - period]
  • Ft[i + m] = (St[i] + (m * Bt[i])) * It[i - period + m]

it seems that gamma and beta are mixed up, and another problem is that the forcast number cannot not be greater than period, i think it maybe is wrong

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.