1. Import packages
First, we import the required packages and initialize the Nixtla client.👍 Use an Azure AI endpoint To use an Azure AI endpoint, remember to set also thebase_url
argument:nixtla_client = NixtlaClient(base_url="you azure ai endpoint", api_key="your api_key")
2. Handling regular frequencies
As discussed in the introduction, for time series data with regular frequencies, where observations are recorded at consistent intervals, TimeGPT can automatically infer the frequency of your timestamps if the input data is a pandas DataFrame. If you prefer not to rely on TimeGPT’s automatic inference, you can set thefreq
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.

3. Handling irregular frequencies
In this section, we will discuss cases where observations are not recorded at consistent intervals.3.1 Load data
We will use the daily stock prices of Palantir Technologies (PLTR) from 2020 to 2023. The dataset includes data up to 2023-09-22, but for this tutorial, we will exclude any data before 2023-08-28. This allows us to show how a custom frequency can handle days when the stock market is closed, such as Labor Day in the U.S.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 |

3.2 Define the frequency
To define a custom frequency, we will first extract and sort the dates from the input data, ensuring they are in the correct datetime format. Next, we will use thepandas_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.
3.3 Forecast with TimeGPT
With the custom frequency defined, we can now use theforecast
method,
specifying the custom_bday
frequency in the freq
argument. This will
make the forecast respect the trading schedule of the stock market.
📘 Available models in Azure AI If you are using an Azure AI endpoint, please be sure to setmodel="azureai"
:nixtla_client.forecast(..., model="azureai")
For the public API, we support two models:timegpt-1
andtimegpt-1-long-horizon
. By default,timegpt-1
is used. Please see this tutorial on how and when to usetimegpt-1-long-horizon
.

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 |
4. Summary
Below are the key takeaways of this tutorial:-
TimeGPT can reliably infer regular frequencies, but you can override
this by setting the
freq
parameter to the corresponding pandas alias. - When working with polars data frames, you must always specify the frequency using the correct polars offset.
- TimeGPT supports irregular frequencies and allows you to define a custom frequency, generating forecasts exclusively for the specified dates.