A tool to analyze leveraged liquidity mining and find optimal option combination for hedging.

Overview

LP-Option-Hedging

Description

A Python program to analyze leveraged liquidity farming/mining and find the optimal option combination for hedging impermanent loss, which may allow arbitrage. Initially written in May for personal use. Optimized by 30x with Numba. May or may not add English annotations.

Utility

The code may plot PnL graphs for leveraged LP (liquidity provider) positions on constant product Automated Market Maker (AMM), like those on Alpha Homora and Alpaca Finance. It can perform a variational search for the optimal combination of call options and put options which minimizes impermanent loss in leveraged LP. It then plots the PnL graphs for leveraged LP, the option combination with sizes and strike prices, and the combination of leveraged LP and options.

The type of leveraged LP can be borrowing USD stablecoins, borrowing cryptos like BTC, ETH, and a delta neutral combination of the two.

Parameters that need to be manually specified:

  • type of leveraged LP
  • leverage of LP
  • max LTV at liquidation
  • APRs on farming
  • annualized volatility, risk-free interest rate, and days to expiration of European options priced by the Black-Scholes model

Background

Providing liquidity on AMM is equivalent to short gamma and long theta, i.e. the LP subjects itself to impermanent loss in exchange for trading fees and liquidity mining rewards. On the other hand, long call and long put have positive gamma and negative theta. By virtue of the Carr–Madan formula, a smooth function of the underlying price, in this case the payoff of leveraged LP, can be replicated by a series of European options at continuous strikes. Hence it is possible to completely hedge leveraged LP with options. In pratice options are not available at any strike. Moreover the volatility is not constant at all strikes due to the volatility smile. Therefore the current program only considers a long call and a long put for hedging.

Disclaimer

The hedging is only approximate and theoretical. The author is not responsible for any loss caused by the use of this program. DYOR.

Reference

期权对冲LP

简介

一个分析杠杆挖矿并寻找最佳期权组合以对冲无常损失的Python程序,写于五月初,经Numba优化。

功能

画出基于恒定乘积AMM的杠杆挖矿的损益曲线,并寻找对冲无常损失的最佳期权组合,画出杠杆LP、期权组合包括张数和行权价及总仓位的损益曲线。

杠杆挖矿的类型包括借U、借币及中性敞口的组合。

需手动输入的参数:

  • 杠杆挖矿类型
  • 杠杆倍数
  • 清算时债务比例
  • 挖矿APR
  • 期权的年化波动率、无风险利率、到期日

声明

程序模拟仅为理论近似,本人不对由此造成的任何损失负责。

Owner
Aureliano
Aureliano
PyTorch code for 'Efficient Single Image Super-Resolution Using Dual Path Connections with Multiple Scale Learning'

Efficient Single Image Super-Resolution Using Dual Path Connections with Multiple Scale Learning This repository is for EMSRDPN introduced in the foll

7 Feb 10, 2022
Keras + Hyperopt: A very simple wrapper for convenient hyperparameter optimization

This project is now archived. It's been fun working on it, but it's time for me to move on. Thank you for all the support and feedback over the last c

Max Pumperla 2.1k Jan 03, 2023
Simulator for FRC 2022 challenge: Rapid React

rrsim Simulator for FRC 2022 challenge: Rapid React out-1.mp4 Usage In order to run the simulator use the following: python3 rrsim.py [config_path] wh

1 Jan 18, 2022
"Neural Turing Machine" in Tensorflow

Neural Turing Machine in Tensorflow Tensorflow implementation of Neural Turing Machine. This implementation uses an LSTM controller. NTM models with m

Taehoon Kim 1k Dec 06, 2022
Depth-Aware Video Frame Interpolation (CVPR 2019)

DAIN (Depth-Aware Video Frame Interpolation) Project | Paper Wenbo Bao, Wei-Sheng Lai, Chao Ma, Xiaoyun Zhang, Zhiyong Gao, and Ming-Hsuan Yang IEEE C

Wenbo Bao 7.7k Dec 31, 2022
MacroTools provides a library of tools for working with Julia code and expressions.

MacroTools.jl MacroTools provides a library of tools for working with Julia code and expressions. This includes a powerful template-matching system an

FluxML 278 Dec 11, 2022
Real-Time Multi-Contact Model Predictive Control via ADMM

Here, you can find the code for the paper 'Real-Time Multi-Contact Model Predictive Control via ADMM'. Code is currently being cleared up and optimize

17 Dec 28, 2022
a pytorch implementation of auto-punctuation learned character by character

Learning Auto-Punctuation by Reading Engadget Articles Link to Other of my work 🌟 Deep Learning Notes: A collection of my notes going from basic mult

Ge Yang 137 Nov 09, 2022
Official code for NeurIPS 2021 paper "Towards Scalable Unpaired Virtual Try-On via Patch-Routed Spatially-Adaptive GAN"

Towards Scalable Unpaired Virtual Try-On via Patch-Routed Spatially-Adaptive GAN Official code for NeurIPS 2021 paper "Towards Scalable Unpaired Virtu

68 Dec 21, 2022
Bootstrapped Representation Learning on Graphs

Bootstrapped Representation Learning on Graphs This is the PyTorch implementation of BGRL Bootstrapped Representation Learning on Graphs The main scri

NerDS Lab :: Neural Data Science Lab 55 Jan 07, 2023
PyTorch implementation of the paper: Label Noise Transition Matrix Estimation for Tasks with Lower-Quality Features

Label Noise Transition Matrix Estimation for Tasks with Lower-Quality Features Estimate the noise transition matrix with f-mutual information. This co

<a href=[email protected]"> 1 Jun 05, 2022
Covid-19 Test AI (Deep Learning - NNs) Software. Accuracy is the %96.5, loss is the 0.09 :)

Covid-19 Test AI (Deep Learning - NNs) Software I developed a segmentation algorithm to understand whether Covid-19 Test Photos are positive or negati

Emirhan BULUT 28 Dec 04, 2021
A library that can print Python objects in human readable format

objprint A library that can print Python objects in human readable format Install pip install objprint Usage op Use op() (or objprint()) to print obj

319 Dec 25, 2022
Weakly Supervised Posture Mining with Reverse Cross-entropy for Fine-grained Classification

Fine-grainedImageClassification Weakly Supervised Posture Mining with Reverse Cross-entropy for Fine-grained Classification We trained model here: lin

ZhenchaoTang 14 Oct 21, 2022
Discord bot for notifying on github events

Git-Observer Discord bot for notifying on github events ⚠️ This bot is meant to write messages to only one channel (implementing this for multiple pro

ilu_vatar_ 0 Apr 19, 2022
Python port of R's Comprehensive Dynamic Time Warp algorithm package

Welcome to the dtw-python package Comprehensive implementation of Dynamic Time Warping algorithms. DTW is a family of algorithms which compute the loc

Dynamic Time Warping algorithms 154 Dec 26, 2022
QuALITY: Question Answering with Long Input Texts, Yes!

QuALITY: Question Answering with Long Input Texts, Yes! Authors: Richard Yuanzhe Pang,* Alicia Parrish,* Nitish Joshi,* Nikita Nangia, Jason Phang, An

ML² AT CILVR 61 Jan 02, 2023
DR-GAN: Automatic Radial Distortion Rectification Using Conditional GAN in Real-Time

DR-GAN: Automatic Radial Distortion Rectification Using Conditional GAN in Real-Time Introduction This is official implementation for DR-GAN (IEEE TCS

Kang Liao 18 Dec 23, 2022
A PyTorch implementation of "Graph Classification Using Structural Attention" (KDD 2018).

GAM ⠀⠀ A PyTorch implementation of Graph Classification Using Structural Attention (KDD 2018). Abstract Graph classification is a problem with practic

Benedek Rozemberczki 259 Dec 05, 2022
Improving Convolutional Networks via Attention Transfer (ICLR 2017)

Attention Transfer PyTorch code for "Paying More Attention to Attention: Improving the Performance of Convolutional Neural Networks via Attention Tran

Sergey Zagoruyko 1.4k Dec 23, 2022