Giter Club home page Giter Club logo

revert-backtester's Introduction

revert-backtester

A fast backtester for Uniswap v3 positions.

Using the backtester on a browser-connected REPL

(def pool-address "0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640")

(def token0-address "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48")

(def token1-address "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2")

(go (def pool-periods
        (<! (backtester/<historic-states
             "mainnet" pool-address token0-address token1-address))))
             
             
(def backtest-options {:tick-lower 193380
                       :tick-upper 200310
                       :liquidity "326453009134297"
                       :first-ts (:timestamp (first pool-periods))
                       :dilute-fees? false
                       :reference-price :hodl})
                         
                         
                         
(def backtest-results (backtester/backtest-position
                         pool-periods backtest-options []))
                         
                                     
                                     
(u/dejs (last backtest-results))

{:price1 "2800.561447581661804800445923843118",
 :position-active? true,
 :date 1645203600,
 :apr "40.798756877089499992439067416587414203",
 :accum-fees0 "166.08025426813868469377",
 :fees0 "0.05728121020264660731",
 :amount1 "1.013650509408661188",
 :pnl "259.307971699411288081104982934500459025162314463603570623",
 :liquidity "326453009134297",
 :price0 "0.9999999999999999999999999999999999",
 :accum-fees1 "0.06097927761789486278",
 :il "-77.548496566783063288340422500588600828351985579876",
 :amount0 "2656.898529",
 :timestamp #inst "2022-02-18T17:00:00.000-00:00",
 :fees1 "0.00001831200180145388"}

Testing the backtester against a set of relevant open positions

Testing against the full set of open mainnet positions that meet the following criteria:

  • Were minted in the last 30 days
  • Only have one mint (deposit)
  • Have no withdrawals

scatterplot-full png

Histogram of a subset from the above set that also match the following criteria:

  • Were in range 100% of the time since they were minted.

histogram-full

Replicating tests on a browser-connected repl

get the full testing set
(go (def tracked-positions (<! (backtester-tester/<fetch-testing-set))))`
                                    (take 100 tracked-positions) 20 println))))
backrtest a specific position
(go (def p0 (<! (<test-pos- 191651 tracked-positions))))`
                                    (take 100 tracked-positions) 20 println))))
test the first 100 positions of the testing set (this will take a minute)
(go (def tested-positions100 (<! (backtester-tester/<backtest-positions-chunked
                                    (take 100 tracked-positions) 20 println))))
test the full testing set (this will take a few minutes)
(go (def tested-positions (<! (backtester-tester/<backtest-positions-chunked
                                 (identity tracked-positions) 20 println))))
render accuarcy plot
(render-accuracy-plot tested-positions100)
render accuracy histogram for position 100% time in range
(render-accuracy-histogram (filter #(bn/= (:time-in-range (:results %)) 100)
                                     tested-positions100))

License

Copyright © 2022 Revert Labs Inc

Distributed under the MIT License

revert-backtester's People

Contributors

gacosta89 avatar kalinbas avatar mariorz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.