Introduction
Forecasting time series is a ubiquitous task in finance, supporting decisions in trading, risk management, and strategic planning. Despite its prevalence, predicting the future prices of financial assets remains a formidable challenge, mainly due to the inherent volatility of financial markets. For those who believe in the feasibility of forecasting these assets, or for professionals whose roles require such predictions, TimeGPT is a powerful tool that simplifies the forecasting process. In this tutorial, we will demonstrate how to use TimeGPT for financial time series forecasting, focusing on Bitcoin price prediction. We will also showcase how to use TimeGPT for uncertainty quantification, which is essential for risk management and decision-making.Why Forecast Bitcoin Prices
Bitcoin (₿) is the first decentralized digital currency and is one of the most popular cryptocurrencies. Transactions are managed and recorded on a public ledger known as the blockchain. Bitcoins are created as a reward for mining, a process that involves solving complex cryptographic tasks to verify transactions. This digital currency can be used as payment for goods and services, traded for other currencies, or held as a store of value. Bitcoin’s high volatility and widespread trading make accurate forecasting a valuable tool for financial analysis, trading strategies, and risk management.What You’ll Learn
- How to load and prepare Bitcoin price data
- How to generate short-term forecasts with TimeGPT
- How to visualize and interpret forecast results
- How to detect anomalies and add exogenous variables
Quick Summary: This tutorial covers Bitcoin price prediction using TimeGPT in Python. You’ll learn to load cryptocurrency data, generate 7-day forecasts with confidence intervals, detect price anomalies, and understand forecasting limitations for volatile crypto markets.
How to Use TimeGPT to Forecast Bitcoin Prices
Step 1: Load Bitcoin Price Data
Bitcoin (₿) is the first decentralized digital currency, with transactions recorded on a public ledger called the blockchain. Bitcoins are created through mining—solving cryptographic tasks—and are used for payments, trading, and long-term investment. For convenience, we’ll rename columns to match TimeGPT’s expectedds
(date) and y
(target) format.
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 |
Step 2: Get Started with TimeGPT
Initialize theNixtlaClient
with your Nixtla API key. To learn more about how to set up your API key, see Setting up your API key.
Step 3: Visualize the Data
Before attempting any forecasting, it is good practice to visualize the data we want to predict. TheNixtlaClient
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.

Bitcoin Price Data
Step 4: Forecast with TimeGPT
Now we are ready to generate predictions with TimeGPT. To do this, we will use theforecast
method from the NixtlaClient
class.
The forecast
method requires the following arguments:
df
: The DataFrame containing the time series datah
: (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 |
plot
method to visualize the predictions with the historical data.

Panel view of historical data with future forecasts
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.

Zoomed view showing 7-day forecast with 50%, 80%, and 90% confidence intervals
Step 5: Extend Bitcoin Price Analysis with TimeGPT
Anomaly Detection
Given the volatility of the price of Bitcoin, it can be useful to try to identify anomalies in the data. TimeGPT can be used for this by calling thedetect_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.

Highlighted anomalies in Bitcoin price data
Add Exogenous Variables
If you have additional information that you believe could help improve the forecast, consider including it as an exogenous variable. For instance, you might add data such as the price of other cryptocurrencies, proprietary information, stock market indices, or the number of transactions in the Bitcoin network. TimeGPT supports the incorporation of exogenous variables in theforecast
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, see Numeric Features Guide.
Step 7: Understand the Model Limitations
As stated in the introduction, predicting the future prices of financial assets is a challenging task, especially for assets like Bitcoin. The predictions in this tutorial may appear accurate, mainly because they align with recent historical data and the model updates with new values at short intervals, avoiding significant deviations. However, the true challenge lies in forecasting Bitcoin’s price for the upcoming days, not just its historical performance. For those who need or want to try to forecast these assets,TimeGPT
can be an option that simplifies the forecasting process. With just a couple of lines of code, TimeGPT
can help you:
- Produce point forecasts
- Quantify the uncertainty of your predictions
- Produce in-sample forecasts
- Detect anomalies
- Incorporate exogenous variables
Next Steps in Cryptocurrency Forecasting
You’ve successfully learned how to forecast Bitcoin prices using TimeGPT with Python. Apply these techniques to other cryptocurrencies like Ethereum, Cardano, or XRP. Ready to forecast at scale? Sign up for Nixtla API access and start predicting cryptocurrency prices today.Frequently Asked Questions
How accurate is Bitcoin price prediction with TimeGPT? TimeGPT provides probabilistic forecasts with uncertainty intervals, making it suitable for risk-aware trading strategies. Accuracy depends on market volatility and forecast horizon. Can TimeGPT predict cryptocurrency crashes? TimeGPT includes anomaly detection capabilities that can identify unusual patterns in Bitcoin price data, helping detect potential market disruptions. What data do I need for Bitcoin price forecasting? You need historical Bitcoin price data with timestamps. This tutorial uses daily closing prices from 2020-2023. Does this work for other cryptocurrencies? Yes, you can apply these same techniques to forecast Ethereum, Cardano, XRP, or any other cryptocurrency with historical price data.References and Additional Material
Financial time series often exhibit random walk behavior, especially cryptocurrencies. Evaluate your models thoroughly with statistical metrics and domain knowledge to make informed decisions.