This repository contains python scripts that are used by Brahma Finance to simulate the performance of synthetic short put option strategies and evaluate risks. The repo is structured as follows:
data/ folder contains the csv files related to swap data of ETH-USDC 0.3%
pool and average gas cost per block.
notebooks/ folder contains the jupyter notebook files used for simulation and backtesting the put selling strategy.
Coming to python files:
- strategy.py base code for
strategy
, conducting either back-testing for put selling or range selection strategies (run_put_strategy
function and passing in historical swap data) - loader.py contains all functions for processing the swap data gathered from flipside crypto
- simulation.py contains all the helper functions used for monte calro simulations.
- utils.py contains all the helper functions used for updating the state of holdings during backtest.
- liquidity.py a modified python implementation of Uniswap v3's liquidity math.
In order to run the backtest for put selling option :
- backtest.ipynb runs the analysis explained in the Aastra article.
- monte_carlo_simulation.ipynb runs the simulations and backtest the put selling strategy on the simulated prices
We have developed a good strategy framework for eth-put selling strategy which backtests on the real Uniswap v3 swap history with gas prices in order to improve accurracy of yield's generated. Thefore simulations are ensured to be as realistic as possible considering real time gas fees of the network for the operations used by strategy and slippage costs for any swap involved with available time period since Unsiwap v3 was released (May 5th 2021 is when swap data starts to show up consistently).
There are several potential sources for imprecision, as for example gas fees are averaged, and can have a significant impact on performance in particular for small positions in high fee regimes.