Skip to content

SirCharan/Hype

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HYOE - Delta-Neutral Funding Rate Arbitrage Strategy Analysis

This project provides a suite of Python-based tools for backtesting and analyzing a delta-neutral funding rate arbitrage strategy for the "HYPE" cryptocurrency on the Hyperliquid exchange.

Project Overview

The core of this project is a trading strategy that aims to generate profit from cryptocurrency funding rates while neutralizing exposure to price volatility. It accomplishes this by simultaneously shorting perpetual futures contracts and buying the underlying spot asset.

The project is structured into four main stages:

  1. Data Discovery: Utility scripts to scan for available data on the exchange.
  2. Data Fetching: Scripts to download historical and live data from the Hyperliquid API.
  3. Backtesting: A simulation engine to test the trading strategy on historical data.
  4. Reporting & Analysis: Scripts to generate financial reports and visualizations from the backtest results.

The Strategy

The delta-neutral strategy is designed to be market-neutral.

  • Entry Condition: A trade is initiated when the perpetual futures price is higher than the spot price, and the funding rate is positive and above a certain threshold.
  • Exit Conditions: A position is closed if the stop-loss is triggered, if the premium between the perpetual and spot price collapses, or if the funding rate drops below the entry threshold.

Workflow and Scripts

1. Data Discovery Utilities

These scripts are used to check for data availability on Hyperliquid before fetching.

  • find_first_candle.py: Finds the earliest available candle data for "HYPE".
  • scan_candles_range.py: Scans a date range to identify periods with available candle data.
  • funding_data_range_check.py: Checks the available date range for funding rate data.

2. Data Fetching

These scripts collect data from the Hyperliquid API.

  • fetch_funding_data.py: Fetches historical funding rate data and saves it to hype_funding_rates_1min.csv.
  • fetch_candles.py: Fetches historical candle data for a specific one-hour window.
  • fetch_price_data.py: Fetches live price data for monitoring.
  • fetch.py: A general-purpose script for fetching historical candle data.

3. Backtesting Engine

The core logic for simulating the trading strategy resides in these scripts.

  • end.py: The main backtesting engine. It reads a combined data file (data (1).csv), simulates the strategy, and produces trades.csv as output.
  • endi.py: A more detailed, interactive version of the backtester with extensive analysis and plotting capabilities. It also reads data (1).csv.

IMPORTANT: The backtesting engine relies on a pre-processed file named data (1).csv, which is not generated by any script in this repository. This file must be created manually and should contain time-aligned spot prices, perpetual prices, and funding rates.

4. Reporting and Analysis

These scripts are used to analyze the results of the backtest.

  • generate_report.py: Reads trades.csv and generates a detailed backtest report in markdown format.
  • main.py & funding_analysis.py: These are identical scripts that perform statistical analysis on 15-minute funding rate data from hype_funding_rates_15min.csv.
  • resample_funding_data.py: Resamples 15-minute funding data into 24-hour intervals and generates a plot.

How to Run a Backtest

  1. Prepare the Data: Create the data (1).csv file with spot_open, perp_open, and funding_fundingRate columns.
  2. Run the Backtest:
    python end.py
    This will generate the trades.csv file.
  3. Generate the Report:
    python generate_report.py
    This will create a report.md file with a detailed analysis of the backtest results.

License

MIT License

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages