R: Make future time series from existing

tk_make_future_timeseries {timetk} | R Documentation

## Make future time series from existing

### Description

Make future time series from existing

### Usage

    tk_make_future_timeseries(
      idx,
      length_out,
      inspect_weekdays = FALSE,
      inspect_months = FALSE,
      skip_values = NULL,
      insert_values = NULL,
      n_future = NULL
    )

### Arguments

`idx` | A vector of dates
`length_out` | Number of future observations. Can be numeric number or a phrase like "1 year".
`inspect_weekdays` | Uses a logistic regression algorithm to inspect whether certain weekdays (e.g. weekends) should be excluded from the future dates. Default is `FALSE`.
`inspect_months` | Uses a logistic regression algorithm to inspect whether certain days of months (e.g. last two weeks of year or seasonal days) should be excluded from the future dates. Default is `FALSE`.
`skip_values` | A vector of same class as `idx` of timeseries values to skip.
`insert_values` | A vector of same class as `idx` of timeseries values to insert.
`n_future` | (DEPRECATED) Number of future observations. Can be numeric number or a phrase like "1 year".

### Details

Future Sequences

`tk_make_future_timeseries` returns a time series based on the input index frequency and attributes.

Specifying Length of Future Observations

The argument `length_out` determines how many future index observations to compute. It can be specified as:

- A numeric value - the number of future observations to return.

  - The number of observations returned is always equal to the value the user inputs.

  - The end date can vary based on the number of timestamps chosen.

- A time-based phrase - The duration into the future to include (e.g. "6 months" or "30 minutes").

  - The duration defines the end date for observations.

  - The end date will not change and those timestamps that fall within the end date will be returned (e.g. a quarterly time series will return 4 quarters if `length_out = "1 year"`).

  - The number of observations will vary to fit within the end date.

Weekday and Month Inspection

The `inspect_weekdays` and `inspect_months` arguments apply to "daily" (scale = "day") data (refer to `tk_get_timeseries_summary()` to get the index scale).

- The `inspect_weekdays` argument is useful in determining missing days of the week that occur on a weekly frequency such as every week, every other week, and so on. It's recommended to have at least 60 days to use this option.

- The `inspect_months` argument is useful in determining missing days of the month, quarter or year; however, the algorithm can inadvertently select incorrect dates if the pattern is erratic.

Skipping / Inserting Values

The `skip_values` and `insert_values` arguments can be used to remove and add values into the series of future times. The values must be the same format as the `idx` class.

- The `skip_values` argument useful for passing holidays or special index values that should be excluded from the future time series.

- The `insert_values` argument is useful for adding values back that the algorithm may have excluded.

### Value

A vector containing future index of the same class as the incoming index `idx`

### See Also

- Making Time Series: `tk_make_timeseries()`

- Working with Holidays & Weekends: `tk_make_holiday_sequence()`, `tk_make_weekend_sequence()`, `tk_make_weekday_sequence()`

- Working with Timestamp Index: `tk_index()`, `tk_get_timeseries_summary()`, `tk_get_timeseries_signature()`

### Examples

    library(dplyr)
    library(tidyquant)
    library(timetk)

    # Basic example - By 3 seconds
    idx <- tk_make_timeseries("2016-01-01 00:00:00", by = "3 sec", length_out = 3)
    idx

    # Make next three timestamps in series
    idx %>% tk_make_future_timeseries(length_out = 3)

    # Make next 6 seconds of timestamps from the next timestamp
    idx %>% tk_make_future_timeseries(length_out = "6 sec")

    # Basic Example - By 1 Month
    idx <- tk_make_timeseries("2016-01-01", by = "1 month",
                              length_out = "12 months")
    idx

    # Make 12 months of timestamps from the next timestamp
    idx %>% tk_make_future_timeseries(length_out = "12 months")

    # --- APPLICATION ---
    # - Combine holiday sequences with future sequences

    # Create index of days that FB stock will be traded in 2017 based on 2016 + holidays
    FB_tbl <- FANG %>% filter(symbol == "FB")

    holidays <- tk_make_holiday_sequence(
        start_date = "2017-01-01",
        end_date   = "2017-12-31",
        calendar   = "NYSE")

    # Remove holidays with skip_values, and remove weekends with inspect_weekdays = TRUE
    FB_tbl %>%
        tk_index() %>%
        tk_make_future_timeseries(length_out       = "1 year",
                                  inspect_weekdays = TRUE,
                                  skip_values      = holidays)

[Package timetk version 2.0.0 Index]