Learn how to work with both regular and irregular timestamps in TimeGPT for accurate forecasting.
NOTE: TimeGPT requires that your data does not contain missing values, as this is not currently supported. In other words, the irregularity of the data should stem from the nature of the recorded phenomenon, not from missing observations. If your data contains missing values, please refer to our tutorial on missing dates.
freq
parameter to a valid
pandas frequency string,
such as MS
for month-start frequency or min
for minutely frequency.
When working with Polars DataFrames, you must specify the frequency explicitly
by using a valid polars offset,
such as 1d
for daily frequency or 1h
for hourly frequency.
Below is an example of how to specify the frequency for a Polars DataFrame.
Air Passengers Forecast
IMPORTANT NOTE: While we are using TimeGPT to predict stock price in this
tutorial, please note that this is being done only with the intention of showing
the capability of forecasting with irregular timestamps. Stock prices are random walks
and as
such can not be predicted using traditional time series forecasting methods
(including TimeGPT). Predictions for random walk will be a straight line type
of forecast where tomorrow’s price is predicted to be equal to today’s price,
which is not a useful model.
date | Open | High | Low | Close | Adj Close | Volume | Dividends | Stock Splits | |
---|---|---|---|---|---|---|---|---|---|
0 | 2020-09-30 | 10.00 | 11.41 | 9.11 | 9.50 | 9.50 | 338584400 | 0.0 | 0.0 |
1 | 2020-10-01 | 9.69 | 10.10 | 9.23 | 9.46 | 9.46 | 124297600 | 0.0 | 0.0 |
2 | 2020-10-02 | 9.06 | 9.28 | 8.94 | 9.20 | 9.20 | 55018300 | 0.0 | 0.0 |
3 | 2020-10-05 | 9.43 | 9.49 | 8.92 | 9.03 | 9.03 | 36316900 | 0.0 | 0.0 |
4 | 2020-10-06 | 9.04 | 10.18 | 8.90 | 9.90 | 9.90 | 90864000 | 0.0 | 0.0 |
PLTR Adjusted Close Prices
pandas_market_calendars package
,
specifically the get_calendar
method, to obtain the New York Stock Exchange
(NYSE) calendar. Using this calendar, we can create a custom frequency that
includes only the days the stock market is open.
PLTR Forecast (Custom Frequency)
date | |
---|---|
0 | 2023-08-28 |
1 | 2023-08-29 |
2 | 2023-08-30 |
3 | 2023-08-31 |
4 | 2023-09-01 |
5 | 2023-09-05 |
6 | 2023-09-06 |
freq
parameter to the corresponding pandas alias.