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
  • 期权的年化波动率、无风险利率、到期日

声明

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

You might also like...
Code and models used in "MUSS Multilingual Unsupervised Sentence Simplification by Mining Paraphrases".

Multilingual Unsupervised Sentence Simplification Code and pretrained models to reproduce experiments in "MUSS: Multilingual Unsupervised Sentence Sim

This project provides an unsupervised framework for mining and tagging quality phrases on text corpora with pretrained language models (KDD'21).
This project provides an unsupervised framework for mining and tagging quality phrases on text corpora with pretrained language models (KDD'21).

UCPhrase: Unsupervised Context-aware Quality Phrase Tagging To appear on KDD'21...[pdf] This project provides an unsupervised framework for mining and

Code for our NeurIPS 2021 paper  Mining the Benefits of Two-stage and One-stage HOI Detection
Code for our NeurIPS 2021 paper Mining the Benefits of Two-stage and One-stage HOI Detection

CDN Code for our NeurIPS 2021 paper "Mining the Benefits of Two-stage and One-stage HOI Detection". Contributed by Aixi Zhang*, Yue Liao*, Si Liu, Mia

Code for Mining the Benefits of Two-stage and One-stage HOI Detection

Status: Archive (code is provided as-is, no updates expected) PPO-EWMA [Paper] This is code for training agents using PPO-EWMA and PPG-EWMA, introduce

Using machine learning to predict and analyze high and low reader engagement for New York Times articles posted to Facebook.
Using machine learning to predict and analyze high and low reader engagement for New York Times articles posted to Facebook.

How The New York Times can increase Engagement on Facebook Using machine learning to understand characteristics of news content that garners "high" Fa

POT : Python Optimal Transport

POT: Python Optimal Transport This open source Python library provide several solvers for optimization problems related to Optimal Transport for signa

Official implementation of our CVPR2021 paper
Official implementation of our CVPR2021 paper "OTA: Optimal Transport Assignment for Object Detection" in Pytorch.

OTA: Optimal Transport Assignment for Object Detection This project provides an implementation for our CVPR2021 paper "OTA: Optimal Transport Assignme

Exact Pareto Optimal solutions for preference based Multi-Objective Optimization

Exact Pareto Optimal solutions for preference based Multi-Objective Optimization

Code for paper "Vocabulary Learning via Optimal Transport for Neural Machine Translation"

**Codebase and data are uploaded in progress. ** VOLT(-py) is a vocabulary learning codebase that allows researchers and developers to automaticaly ge

Owner
Aureliano
Aureliano
LIAO Shuiying 6 Dec 1, 2022
Official page of Struct-MDC (RA-L'22 with IROS'22 option); Depth completion from Visual-SLAM using point & line features

Struct-MDC (click the above buttons for redirection!) Official page of "Struct-MDC: Mesh-Refined Unsupervised Depth Completion Leveraging Structural R

Urban Robotics Lab. @ KAIST 37 Dec 22, 2022
Code in PyTorch for the convex combination linear IAF and the Householder Flow, J.M. Tomczak & M. Welling

VAE with Volume-Preserving Flows This is a PyTorch implementation of two volume-preserving flows as described in the following papers: Tomczak, J. M.,

Jakub Tomczak 87 Dec 26, 2022
MAGMA - a GPT-style multimodal model that can understand any combination of images and language

MAGMA -- Multimodal Augmentation of Generative Models through Adapter-based Finetuning Authors repo (alphabetical) Constantin (CoEich), Mayukh (Mayukh

Aleph Alpha GmbH 331 Jan 3, 2023
A Planar RGB-D SLAM which utilizes Manhattan World structure to provide optimal camera pose trajectory while also providing a sparse reconstruction containing points, lines and planes, and a dense surfel-based reconstruction.

ManhattanSLAM Authors: Raza Yunus, Yanyan Li and Federico Tombari ManhattanSLAM is a real-time SLAM library for RGB-D cameras that computes the camera

null 117 Dec 28, 2022
Developed an optimized algorithm which finds the most optimal path between 2 points in a 3D Maze using various AI search techniques like BFS, DFS, UCS, Greedy BFS and A*

Developed an optimized algorithm which finds the most optimal path between 2 points in a 3D Maze using various AI search techniques like BFS, DFS, UCS, Greedy BFS and A*. The algorithm was extremely optimal running in ~15s to ~30s for search spaces as big as 10000000 nodes where a set of 18 actions could be performed at each node in the 3D Maze.

null 1 Mar 28, 2022
Universal Probability Distributions with Optimal Transport and Convex Optimization

Sylvester normalizing flows for variational inference Pytorch implementation of Sylvester normalizing flows, based on our paper: Sylvester normalizing

Rianne van den Berg 172 Dec 13, 2022
Web mining module for Python, with tools for scraping, natural language processing, machine learning, network analysis and visualization.

Pattern Pattern is a web mining module for Python. It has tools for: Data Mining: web services (Google, Twitter, Wikipedia), web crawler, HTML DOM par

Computational Linguistics Research Group 8.4k Jan 3, 2023
An efficient and effective learning to rank algorithm by mining information across ranking candidates. This repository contains the tensorflow implementation of SERank model. The code is developed based on TF-Ranking.

SERank An efficient and effective learning to rank algorithm by mining information across ranking candidates. This repository contains the tensorflow

Zhihu 44 Oct 20, 2022