Skip to content

jacarandastock/Quant_Crypto

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Quantitative trading on Cryptocurrency

Author: Cholian (Chao Li)

Emial: cholianli970518@gmail.com

All the code is just a free version with basic functions, but still can be run and...make a profit

If you want the completed code, please contact with me.

Table of Contents

Introduction

Different quantitative strategies on the cryptocurrency, where has been verified with real trading.

Exchange: Binance

API: Binance API

Open an account

Binance

Click: Open an account in Binance

EMA strategy

Reference: https://learn.bybit.com/trading/exponential-moving-average-ema-crypto/

What is the EMA strategy?

An exponential moving average is a technical indicator that gives greater weighting to recent prices in its calculation. As a result, EMA responds more quickly to the latest price changes, as compared to a simple moving average (SMA), which has a bigger lag.... Read more

How to build a quantitative strategy with EMA?

When one moving average moves above another, it creates a profitable trading opportunity. One of the most effective crossover strategies is known as the golden cross. When the 50 EMA moves above the 200 SMA, it indicates that short-term bulls are becoming more aggressive, while long-term traders are still bullish....Read more

EMA plot Reference: https://learn.bybit.com/trading/exponential-moving-average-ema-crypto/

Strategy parameters

symbol = 'BTCUSDT'

This is the trading symbol.

quantity = 0.037 

This is the trading quantity.

Trading notional value = Market price * quantity.

interval = '6h'

This is the trading based frequency, for more frequency, please refer to the Binance API doc

ema_a_period = 36
ema_b_period = 60

ema_a refers to the faster line while ema_b refer to the slow line.

Run the strategy

Create the Binance API key and Secret in Link

KEY = 'your API KEY'
SECRET = 'your API SECRET'

Then,

python Binance_EMA_trading_update_20220114.py

Backtesting parameters

Parameter Description
Backtesting framework Backtrader
Trading pair BTCUSDT-Perpetual future contract
Data frequency 6h
Training set 2019-09-08 17:59:59 - 2021-04-25 23:59:59
Test set 2021-04-26 05:59:59 - 2021-12-31 17:59:59
Starting Cash $100
Leverage X1
Commission 0.04%

Backtesting result:

Sharp Ratio: 3.56
Final return(2021-04-26 - 2021-12-31):77.36%
Maximum Drawdown: 11.71%
......

Funding rate strategy

What is the Funding rate?

Funding rates are periodic payments either to traders that are long or short based on the difference between perpetual contract markets and spot prices. Therefore, depending on open positions, traders will either pay or receive funding...... Read more

How to make an strategy with funding rate?

Funding rates on Binance are collected every hour and we can see that some crypto assets have reached more than 1% a day. Essentially anyone who is short on the DEFI-USDT contract will be collecting 0.3714% every eight hours to hold that position.......Read more

EMA plot data: coinglass

What is the daily return or annual return could be?

Given an example with the XEMUSDT (fundingrate: -0.3193%)

Term Calculation Profit Note
Funding rate yield 0.3193%*3 + 0.9579% Three collection on funding rate for a day
Transaction fee 0.02% * 2 * 3 -0.12% Buy and sell for each collection
95% confidence price change 0.08% * 3 -0.24% The price of certain trading pair will fluctuate between [-0.053, 0.0253], with 5% significant level
Daily profit - 0.5979%
Annual return (1.005979)^{365} 8.8096

Theoretically, it could achieve a very high return.

About this strategy

Before the funding collection time point, selecting the highest funding rate pair, then opening a long / short position according to the negative / positive funding rate.

After the funding rate collection finished, closing the current position.

Strategy parameters

KEY = 'your API KEY'
SECRET = 'your API SECRET'

Create the Binance API key and Secret in Link

leverage = 3

The maximum amount of Leverage available depends on the notional value of your position—the larger the position, the lower the leverage.

trading_amount = 300 # e.g 100 -> $100

Total size = trading_amount * entry Price * leverage

funding_rate_bound = 0.0020

The minimum absolute funding rate. e.g: abs(-0.3193%)>0.002, if there is no pair satisfied the minimum funding rate bound, nothing will be executed during this strategy.

advance_time = 1
lag_time = 15

Given an example:

7:59:00 Open a position MARKET order

(1 minute)

8:00:00 Funding rate collection

8:01:00 Close the position with a LIMIT order

(15 minutes)

8:16:00 If the LIMIT order is not executed, then execute a MARKET order for stopping loss of holding position.

note: LIMIT order will have lower commission fee than MARKET order

How to run the strategy

python Funding_rate_trading_update_20210121.py

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%