zelos-alpha / demeter

Better backtest toolkit for Uniswap v3 and Aave.
https://medium.com/zelos-research
MIT License
32 stars 7 forks source link

Multiple markets in one strategy #12

Closed youbrain closed 4 months ago

youbrain commented 4 months ago

Is there any way to run back test with multiple markets at the same time?
Interesting in Deribit+Uniswap v3 pools

youbrain commented 4 months ago

I add to actuator my uniswap and deribit markets. And I think I got an error because of price course.

actuator.set_price(deribit_market.get_price_from_data())

image
youbrain commented 4 months ago
    # settings 
    timeframe = [
        datetime(2024, 2, 15), 
        datetime(2024, 2, 20)
    ]

    actuator = Actuator()
    broker = actuator.broker

    usdt = TokenInfo(name="USDT", decimal=6)
    eth = TokenInfo(name="WETH", decimal=18)

    uni_market = UniLpMarket(
        MarketInfo("uni_market3"), 
        UniV3Pool(eth, usdt, 0.05, usdt),  # declare pool 0.005% 
        data_path="uniswap_dataset"
    )

    uni_market.load_data(
        ChainType.ethereum.name, 
        "0x11b815efb8f581194ae79006d24e0d814b7697f6", 
        timeframe[0], timeframe[1]
    )

    broker.add_market(uni_market)
    broker.set_balance(usdt, 490.994339)
    broker.set_balance(eth, 0.11837137182367227)

    deribit_market = DeribitOptionMarket(
        MarketInfo("option_test"), 
        DeribitOptionMarket.ETH,
        data_path="deribit_orderbook"
    )

    deribit_market.load_data(
        timeframe[0], timeframe[1]
    )
    broker.add_market(deribit_market)
    broker.set_balance(DeribitOptionMarket.ETH, 100)

    actuator.strategy = DeribitStrategy(timeframe[0])
    actuator.set_price(deribit_market.get_price_from_data())
    actuator.run()

Thats my code

32ethers commented 4 months ago
  1. Sure demeter supports backtesting on multiple market. Here is an example
  2. You got price from deribit market. but price here is hourly, and uniswap market requires minutely price. So you had better uni_market.get_price(), this will extract price of two tokens from uniswap pool swap.
  3. deribit market extract price from "underlying price" in orderbook. so It has eth price only. Uniswap extract price from swap, so it will return price of two tokens, and base token will always be 1