Research

Spot Forecasting in DeFi

December 16, 2024
6 Min read
Profile picture of Nathan Burton

Nathan Burton

Senior Quantitative Researcher

Cover image for Spot Forecasting in DeFi

What is Spot?

Spot is a term used in trading that refers to an asset as is at current market price. Spot differs from something like futures where contracts for future prices are traded, or options where the choice to buy or sell at a certain price in the future are traded. In DeFi the most immediate example of spot trading is the exchange of one token or coin for another described as a pair, for example ETH/USDT is the pair of ETH and USDT and the spot price is the exchange rate of first asset in terms of the second.

TLDR; Spot price is just the price.

Spot forecasting is some method of attempting to anticipate future prices or returns on a spot asset, including leveraging machine learning and AI models. The forecast may be in the realm of milliseconds, or up to months and possibly even years.

What is Spot Forecasting used for?

Spot forecasting can be useful for many applications over many different timeframes. The most apparent is implementing a manual or algorithmic buy/sell trading strategy based on anticipated price movement, which in practice has mixed results depending on the performance of the forecasting model and the strategy. Further a portfolio might make use of spot forecasting in hedging or risk management using forecasts and statistics around those forecasts for multiple pairs.

DeFi provides other unique opportunities where spot forecasts can be helpful:

Vaults implementing ML spot forecasting can utilize more sophisticated and dynamic porfolio strategies. A vault agent or algorithm that anticipates potential future price movements can reduce risk by reducing exposure to volatile assets ahead of anticipated downturn, or increase exposure when a comparative increase in value is expected in certain assets. All of this can be managed by cleverly using both stable pairs, ex. ETH/USDT, and non-stable pairs, ex. SOL/ETH. Incorporating forecasting and machine learning into their decision-making frameworks, vaults can achieve more stable, adaptive, and profitable portfolio management.

Yield aggregators aim to produce regular income or value increase using staking or other lock-up methods. Spot forecasts enable the aggregator to compare the relative expected value of staking in one protocol vs. another, for example if the value of asset AA is expected to increase relative to the value of BB, it may make sense to exchange some BB and increase the holding of AA to be staked so that AA can be liquidated at some later date. Further the staking reward on AA could be worth more than that on BB (unless the yield on BB is higher, in which case this system can be optimized according to yields and risks).

Modern Portfolio Theory techniques for portfolio optimization can utilize spot returns forecasts as inputs for mean-variance optimization. These forecasts, which typically represent expectations for asset returns over a specific investment horizon, are combined with historical or implied covariance matrices to generate efficient portfolios that maximize expected return for a given level of risk. The key advantage of using spot returns forecasts, rather than historical returns, is that they can incorporate forward-looking views and current market conditions rather than solely relying on past performance.

Sample Models

OpenGradient has produced 30-minute and 6-hour SUI/USDT example models that can be found on OpenGradient Hub. Both models take recent OHLC candles as inputs, and output forecast return for the respective timeframe. These models are available for general inference or can used as an example framework for other custom models to be run on OpenGradient's infrastructure.

Though the initial input for both models is typical canldes, the inference includes log transformation and feature processing. Both models were trained using Lasso for feature selection from the transformed feature set over multiple-sized test sets where the test set is temporally ex post the training set. After the final features were selected the model weights were optimized for least-squares for the entire dataset.

6-hour SUI/USDT Spot Forecast

The 6-hour model input is six 3-hour OHLC candles with the last row being the most recent as which can be visualized as the following:

open high low close
0.6482 0.6568 0.6482 0.6563
0.6563 0.6648 0.6541 0.6554
0.6554 0.6573 0.65 0.6517
0.6517 0.6534 0.6501 0.6501
0.6502 0.6515 0.646 0.6489
0.649 0.6555 0.6478 0.6531

however the actual input is simplified to a 2-d array:

[[0.6482, 0.6568, 0.6482, 0.6563],
 [0.6563, 0.6648, 0.6541, 0.6554],
 [0.6554, 0.6573, 0.65  , 0.6517],
 [0.6517, 0.6534, 0.6501, 0.6501],
 [0.6502, 0.6515, 0.646 , 0.6489],
 [0.649 , 0.6555, 0.6478, 0.6531]]

The 6-hour SUI/USDT model produces the following statistics on the full dataset:

  • correlation: ρ\rho(true,pred)=0.12
  • correct direction: 53%
  • MSE: 0.00081

We developed and backtested a strategy based on this model as seen below. It should be noted that this sort of performance is not guaranteed to continue, and the the results have high volatility, however this is demonstrative of how forecasting models can perform on historical data.

30-minute SUI/USDT Spot Forecast

The 30-minute model input is ten 30-minute OHLC candles with the last row being the most recent as which can be visualized as the following:

open high low close
0.8261 0.8282 0.8229 0.8234
0.8231 0.8233 0.8209 0.8213
0.8212 0.8228 0.8188 0.819
0.8189 0.8189 0.8166 0.8179
0.8179 0.8179 0.8093 0.8103
0.8101 0.8123 0.8072 0.8113
0.8111 0.8125 0.8067 0.8082
0.8084 0.8102 0.8073 0.8092
0.8092 0.8113 0.8045 0.811
0.811 0.8127 0.8068 0.81

the actual input is simplified to a 2-d array:

[[0.8261, 0.8282, 0.8229, 0.8234],
 [0.8231, 0.8233, 0.8209, 0.8213],
 [0.8212, 0.8228, 0.8188, 0.819 ],
 [0.8189, 0.8189, 0.8166, 0.8179],
 [0.8179, 0.8179, 0.8093, 0.8103],
 [0.8101, 0.8123, 0.8072, 0.8113],
 [0.8111, 0.8125, 0.8067, 0.8082],
 [0.8084, 0.8102, 0.8073, 0.8092],
 [0.8092, 0.8113, 0.8045, 0.811 ],
 [0.811 , 0.8127, 0.8068, 0.81  ]]

The 30-minut SUI/USDT model produces the following statistics on the full dataset:

  • correlation: ρ\rho(true,pred)=0.057
  • correct direction: 52.7%
  • MSE: 0.00007

Graphed results of an example backtested strategy on a sample of historical data are seen in the What is Spot Forecasting used for? section. The limitations of backtests referenced in the 6-hour model description apply just as well to the 30-minute model.

Spotlight Use Case:

DoubleUp is launching AI agents that leverages OpenGradient's spot forecasting models to set the moneyline for prediction markets on cryptoassets on their gamblefi platform.

OpenGradient's infrastructure allows DoubleUp to securely and seamlessly leverage verifiable ML workflows for their protocol, granting users access to powerful optimized features like dynamic prediction markets powered by AI.

Conclusion

Spot and price forecasting can be extremely helpful for simple trading applications as well as many more complex and nuanced uses with vaults, AI agents, yield aggregating, and more. OpenGradient has models available for use, or custom models can be built and hosted on OpenGradient. These models can be inferred from directly using a Python SDK or integrated into protocols and dApps.

About OpenGradient

OpenGradient is a leading decentralized AI platform for open-source model hosting, secure inference, agentic reasoning, and application deployment. By developing tooling and a feature-rich platform that makes developing AI workflows both secure and seamless, OpenGradient empowers developers with the ability to build in our ecosystem of intelligent and optimized AI-empowered applications. With native model hosting, permissionless composability, and secure inference execution, OpenGradient also aims to accelerate open-source AI by democratizing model ownership, improving verifiability guarantees, and promoting censorship-resistant model access.

Current live products and initiatives include:

Research - In-house research team focused on developing AI and ML models as open-sourced public goods for Web3 protocols.

Model Hub - A Web3 model repository like HuggingFace, featuring a web UI built on a completely decentralized backend including OpenGradient’s decentralized filestore and blockchain infrastructure.

OpenGradient SDK - The OpenGradient SDK allows programmatic access to our model filestore and decentralized AI infrastructure from Python or from their CLI. Model developers can use the SDK to publish and manage their model deployments on OpenGradient and integrate it directly into their AI workflows.

NeuroML - Solidity library used to expose functions that are important for running AI-driven workloads on our EVM network, e.g. Data preprocessing, data post-processing, statistical analysis, different flavors of inference…etc.

Blockchain EVM Network - Blockchain Network leveraging heterogeneous AI compute architecture (HACA) and node specialization to support features like model hosting, data access, and AI inference secure and scalable.