The finnts package, commonly referred to as “Finn”, is a standardized times series forecast framework developed by Microsoft Finance. It’s a result of years of effort trying to perfect a centralized forecasting practice that everyone in finance could leverage. Even though it was built for finance like forecasts, it can easily be extended to any type of time series forecast.

Finn takes years of hard work and thousands of lines of code, and simplifies the forecasting process down to one line of code. A single function, “forecast_time_series”, takes in historical data and applies dozens of models to produce a state of the art forecast. While simplifying the forecasting process down to a single function call might seem limiting, Finn actually allows for a lot of flexibility under the hood. In order to leverage the best components of Finn, please check out all of the other vignettes within the package.

Getting started with Finn is as simple as 1..2..3

1. Bring Data

Data used in Finn needs to follow a few requirements, called out below.

  • Data is tabular, formatted as data frame or tibble.
  • Needs a time stamp or date column, which needs to be formatted as a date and labeled as “Date”. The date values need to start at the beginning of the period. For example, a monthly data set needs to have each date period started on the first day of each month. For a quarterly forecast, the first day of the quarter, etc.
  • Contains at least one unique label to identify one time series from another. These are sometimes referred to as “data combos” or “combo variables” in Finn. For example, a monthly forecast by country should have a column with country names to help Finn split out each country into separate time series.
  • No duplicate rows at the intersection of data combos and date.
  • Column headers should contain only letters, numbers, and underscores. They should also start with a letter, not a number. These requirements ensure that R/Python handle your data frame correctly without any errors.
  • External regressors are optional, they’re not required to produce a Finn forecast. To learn more about how to use them, please check out the vignette on external regressors.

A good example to use when producing your first Finn forecast is to leverage existing data examples from the timetk package. Let’s take a monthly example and trim it down to speed up the run time of your first Finn forecast.

library(finnts)

hist_data <- timetk::m4_monthly %>%
  dplyr::filter(date >= "2010-01-01") %>%
  dplyr::rename(Date = date) %>%
  dplyr::mutate(id = as.character(id))

print(hist_data)
#> # A tibble: 264 × 3
#>    id    Date       value
#>    <chr> <date>     <dbl>
#>  1 M1    2010-01-01  9480
#>  2 M1    2010-02-01  8800
#>  3 M1    2010-03-01  8810
#>  4 M1    2010-04-01  7690
#>  5 M1    2010-05-01  7710
#>  6 M1    2010-06-01  9660
#>  7 M1    2010-07-01 11870
#>  8 M1    2010-08-01 12920
#>  9 M1    2010-09-01 10890
#> 10 M1    2010-10-01  9500
#> # … with 254 more rows

print(unique(hist_data$id))
#> [1] "M1"    "M2"    "M750"  "M1000"

The above data set contains 4 individual time series, identified using the “id” column.

2. Create Finn Forecast

Calling for “forecast_time_series” function is the easiest part. In this example we will be running just two models.


finn_output <- forecast_time_series(
  input_data = hist_data,
  combo_variables = c("id"),
  target_variable = "value",
  date_type = "month",
  forecast_horizon = 3,
  back_test_scenarios = 6, 
  models_to_run = c("arima", "ets"), 
  run_global_models = FALSE, 
  run_model_parallel = FALSE
)

3. Use Forecast Outputs

Future Forecast

finn_output$final_fcst %>%
  head() %>%
  print()

finn_output$final_fcst %>%
  tail() %>%
  print()

Back Test Results

print(finn_output$back_test_data)

Back Test Best Model per Time Series

print(finn_output$back_test_best_MAPE)

Note: the best model for the “M1” combination is a simple average of “arima” and “ets” models.