Metadata-Version: 2.1
Name: zelos-demeter
Version: 1.3.0
Summary: better DEFI backtesting tool
Home-page: https://zelos-demeter.readthedocs.io
Author: zelos research
Author-email: zelos@antalpha.com
License: MIT
Platform: UNKNOWN
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE

# Demeter

## Introduction

Demeter is a backtesting framework for Defi of ethereum-like chain. It allows investors test their strategy and evaluate
return rate with real market data. At present, demeter support backtest on uniswap v3 and aave v3

Demeter's style is borrowed from backtrader, allowing developers of traditional financial engineering to get started
quickly.

Demeter has good testing accuracy, it can calculate income and net worth close to the real world. Demeter has also made
some optimizations for backtesting speed.

## Features

* **backtrader style:** Demeter's design style and operation process are modeled after Backtrader, making it easier for
  users to get started.
* **broker/market:** Demeter draws on the concepts of brokers and markets from real markets. Broker holds the asset and
  provide various market to invest. Demeter supports a variety of markets, including uniswap and aave, and more market
  is coming. Users can test strategies for investing in multiple markets.
* **Data feeding:** Backtesting requires real market data. Thanks to the transparency of blockchain, those data can be
  fetched from event logs of transaction. We provided [demeter-fetch](https://github.com/zelos-alpha/demeter-fetch) to
  do this work. It can download event logs from rpc or google big query and decode them to market data.
* **Accuracy:** In the design of demeter, accuracy is an important consideration. In order to provide higher accuracy,
  the core calculations of uniswap and aave do not follow theoretical formulas, but draw on the code of the contract.
  This allows demeter to have higher calculations accuracy.
* **Rich output:** In order to allow users to evaluate strategies intuitively, demeter provides a wealth of output,
  including asset changes in accounts and position adjustment records. With the indicator calculation module, users can
  choose the best investment strategy.
* **Indicators:** Besides the simulation of defi market, demeter also provides various indicators. Those indicators will
  help user to decide how and when to make transactions, and evaluate their strategies.
* **Rich interface in strategy:** In strategy, demeter provide a lot of interface, which help user to write strategy
  freely. With triggers, user can make transactions a specified time or price. With on_bar and after_bar function, user
  can check and calculate on each iteration. Initialize and finalize function are also provided.
* **Price:** Price is the key to calculate token net value, since it will be used among markets. We separate price from
  market.data. Prices can be downloaded from coingecko and some centralized market.
* **Decimal places:** You can define decimal places to avoid long decimal.

## Markets

* **Uniswap V3** As a popular automated market maker, uniswap is famous for its complexity. To raise fund
  utilization rate, uniswap add tick range to position, which makes it difficult to estimate the return on investment.
  Demeter provides comprehensive calculation and evaluation tools to help users test the returns of various positions.
* **Aave V3** Aave is a popular liquidity protocol which allow user to deposit and borrow assets. Through supply
  asset to aave, user can earn interest, and borrowing allow user to earn extra profit or to hedging price changes.
  Demeter support supply/repay/borrow/repay/liquidation transactions on aave.
* **Deribit**
* **Sequeeth**
* **GMX V1**
* **GMX V2**
* **Boros (experimental)**

## Boros Experimental Support

This repository now includes experimental Boros support under
`demeter.boros_v4`.

Two sample workflows are available:

* `samples/strategy-example/72_boros_funding_convergence.py`
  * Two-leg Boros spread backtest using two Boros implied-rate markets
* `samples/strategy-example/77_boros_convergence_with_perp_funding.py`
  * Four-leg style experimental backtest that keeps the two Boros legs and
    mounts Binance and Hyperliquid funding histories as synthetic perp
    cashflows

The Boros implementation currently supports:

* raw Boros event loading from `orderbook/*.csv` and `liquidity/*.csv`
* Boros settlement recovery using `latestFTime`, `floating_index`, and
  `fee_index`
* taker-only replay with `TX_REPLAY_BEST_EXEC`
* higher-fidelity event replay with `EVENT_REPLAY_FULL_PROTO`
* result exports including trade, settlement, spread, and perp funding ledgers

Mode selection and current Boros engine comparison are documented in:

* `samples/boros-backtest-modes/README.md`
* `samples/boros-backtest-modes/CURRENT_COMPARISON.md`
* `samples/boros-backtest-modes/RELEASE_GUIDANCE.md`

Current limitations:

* no standalone perp market yet
* no maker queue simulation
* no full liquidation or external margin model
* still marked experimental rather than protocol-perfect

## Conclusion

Our vision is to become the best Defi backtesting tool, you can check
our [release_note](https://github.com/zelos-alpha/demeter/blob/master/release_note.md) for the latest updates.

## Links

* website: https://zelos-demeter.readthedocs.io/
* Medium: https://medium.com/zelos-research
* Pypi: https://pypi.org/project/zelos-demeter
* demeter-fetch: https://github.com/zelos-alpha/demeter-fetch
* Deribit option data(ETH): https://www.dropbox.com/scl/fo/kwk5kgiseu5rvccjscd0f/ANswtRLzpCxOc6cMTH0oRlE?rlkey=ai071f9695uz287lt8k0bci5e&e=1&st=ntbog1sr&dl=0

Please go to the [website](https://zelos-demeter.readthedocs.io/) for a full description

## Donation

If you like this project and would like to support our development, please consider donating. Your support will help us
continue to improve and expand our features, thank you for your generosity!

| Chain    | Address                                                        |
| -------- | -------------------------------------------------------------- |
| Bitcoin  | bc1pex0d2rkpsgmwauahauxlthakqz27c0ura75zjqhmj0vet07mu65swur90n |
| Ethereum | 0x41FE1FFdF42121496b2e67287962E25Bb75dAA2D                     |
| Polygon  | 0x41FE1FFdF42121496b2e67287962E25Bb75dAA2D                     |
| TRON     | TM3DG2TzEvyv9Amv9oBHJA7Q2URJZWPFmz                             |
| Solana   | DHS2KwrNbeHEfSnfiEMNYB15dWv9qnbMSYJtayAWCw2s                   |
| BSC      | 0x41FE1FFdF42121496b2e67287962E25Bb75dAA2D                     |


