Learn how to use TimeGPT for financial time series forecasting
pandas
DataFrame.
Date | Close | |
---|---|---|
0 | 2020-01-01 | 7200.174316 |
1 | 2020-01-02 | 6985.470215 |
2 | 2020-01-03 | 7344.884277 |
3 | 2020-01-04 | 7410.656738 |
4 | 2020-01-05 | 7411.317383 |
Date
and Close
columns to ds
and y
, respectively.
TimeGPT
, you need to instantiate the
NixtlaClient
class. For this, you will need a Nixtla API key.
👍 Use an Azure AI endpoint To use an Azure AI endpoint, remember to set also theTo learn more about how to set up your API key, please refer to the Setting Up Your Authentication API Key tutorial.base_url
argument:nixtla_client = NixtlaClient(base_url="you azure ai endpoint", api_key="your api_key")
NixtlaClient
class includes a plot
method for this purpose.
The plot
method has an engine
argument that allows you to choose
between different plotting libraries. Default is matplotlib
, but you
can also use plotly
for interactive plots.
ds
and
y
, you will need to specify the time_col
and target_col
arguments
of the plot
method:
plot
method but for all methods
from the
NixtlaClient
class.
forecast
method from the
NixtlaClient
class.
The forecast
method requires the following arguments:
df
: The DataFrame containing the time series data
h
: (int) The forecast horizon. In this case, we will forecast the
next 7 days.
level
: (list) The confidence level for the prediction intervals.
Given the inherent volatility of Bitcoin, we will use multiple
confidence levels.
ds | TimeGPT | TimeGPT-lo-90 | TimeGPT-lo-80 | TimeGPT-lo-50 | TimeGPT-hi-50 | TimeGPT-hi-80 | TimeGPT-hi-90 | |
---|---|---|---|---|---|---|---|---|
0 | 2024-01-01 | 42269.460938 | 39567.209020 | 40429.953636 | 41380.654646 | 43158.267229 | 44108.968239 | 44971.712855 |
1 | 2024-01-02 | 42469.917969 | 39697.941669 | 40578.197049 | 41466.511361 | 43473.324576 | 44361.638888 | 45241.894268 |
2 | 2024-01-03 | 42864.078125 | 40538.871243 | 41586.252507 | 42284.316674 | 43443.839576 | 44141.903743 | 45189.285007 |
3 | 2024-01-04 | 42881.621094 | 40603.117448 | 41216.106493 | 42058.539392 | 43704.702795 | 44547.135694 | 45160.124739 |
4 | 2024-01-05 | 42773.457031 | 40213.699760 | 40665.384780 | 41489.812431 | 44057.101632 | 44881.529282 | 45333.214302 |
📘 Available models in Azure AI If you are using an Azure AI endpoint, please be sure to setWe can pass the forecasts we just generated to themodel="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
.
plot
method to
visualize the predictions with the historical data.
max_insample_length
argument. Note that setting
max_insample_length=60
, for instance, will display the last 60
historical values along with the complete forecast.
add_history
argument of the forecast
method to True
, TimeGPT
will generate predictions for the historical
observations too. This can be useful for assessing the model’s
performance on the training data.
ds | TimeGPT | TimeGPT-lo-50 | TimeGPT-lo-80 | TimeGPT-lo-90 | TimeGPT-hi-50 | TimeGPT-hi-80 | TimeGPT-hi-90 | |
---|---|---|---|---|---|---|---|---|
0 | 2020-02-03 | 9425.702148 | 7622.287194 | 5999.157479 | 5027.779677 | 11229.117103 | 12852.246818 | 13823.624619 |
1 | 2020-02-04 | 9568.482422 | 7765.067467 | 6141.937752 | 5170.559951 | 11371.897376 | 12995.027092 | 13966.404893 |
2 | 2020-02-05 | 9557.082031 | 7753.667077 | 6130.537362 | 5159.159560 | 11360.496986 | 12983.626701 | 13955.004502 |
3 | 2020-02-06 | 9486.123047 | 7682.708092 | 6059.578377 | 5088.200576 | 11289.538001 | 12912.667717 | 13884.045518 |
4 | 2020-02-07 | 9475.242188 | 7671.827233 | 6048.697518 | 5077.319716 | 11278.657142 | 12901.786857 | 13873.164659 |
📘 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
.
TimeGPT
can be used for this by
calling the detect_anomalies
method from the
NixtlaClient
class. This method evaluates each observation against its context within
the series, using statistical measures to determine its likelihood of
being an anomaly. By default, it identifies anomalies based on a 99
percent prediction interval. To change this, you can specify the level
argument.
📘 Available models in Azure AI If you are using an Azure AI endpoint, please be sure to setmodel="azureai"
:nixtla_client.detect_anomalies(..., 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
.
TimeGPT
, take a look
at our Anomaly
Detection
tutorial.
TimeGPT
supports the incorporation of exogenous variables in the
forecast
method. However, keep in mind that you’ll need to know the
future values of these variables.
To learn how to incorporate exogenous variables to TimeGPT
, refer to
the Exogenous
Variables
tutorial.
TimeGPT
can be an option that simplifies the
forecasting process. With just a couple of lines of code, TimeGPT
can
help you:
TimeGPT
capabilities, please refer to the TimeGPT
Documentation.