Skip to main content

crypto-strategy

A repository to perform backtests and create trading strategies for cryptocurrencies.

Dependency Review Python package pypi-upload

Install

pip install crypto-strategy[full]

Usage

Backtest Strategy

  1. Moving Average Strategy
  • Description

    BestMaStrategy(symbols, freq, res_dir, flag_filter, flag_stop)
    
    • symbols: asset name, e.g., BTCUSDT
    • freq: data frequency to use, 1h | 4h
    • res_dir: results directory
    • flag_filter: filter to use, [mmi | ang]
      • mmi: Market Meanness Index filter
      • ang: Linear Regression Angle filter
    • flag_stop: early stop flag, [ts_stop | sl_stop | tp_stop]
      • ts_stop: trailing stop
      • sl_stop: stop loss
      • tp_stop: take profit
  • Example: Find the best params using 1h data with mmi filter and ts_stop

    BestMaStrategy(
        symbols=['BTCUSDT', 'ETHUSDT'], 
        freq='1h', 
        res_dir='results/best-1h-ma-mmi-filter', 
        flag_filters='mmi',
        flag_stop='ts_stop'
    )
    
  1. Breakout Strategy
    • Description: A method to optimize the BO strategy

      • symbols: a list of symbols to be optimzied on, e.g., 'BTCUSDT'
      • freq: currently supported values: '1h' or '4h'
      • res_dir: the output directory
      • flag_filter: currently supported filters: 'vol', 'ang', default: None
      • flag_stop: early stop flag, [ts_stop | sl_stop | tp_stop]
        • ts_stop: trailing stop
        • sl_stop: stop loss
        • tp_stop: take profit
    • Example: Find the best params for bo strategy with vol filter using BTCUSDT 4h data and sl_stop

      BestBoStrategy(
          symbols = 'BTCUSDT',
          freq = '4h', 
          res_dir = 'results/best-4h-bo_rev-vol-filter', 
          flag_filters = 'vol',
          flag_stop = 'sl_stop',
      )
      
      
      
  2. MACD Strategy
BestMacdStrategy(symbols, freq, res_dir, flag_filter)
  • symbols: asset name, e.g., BTCUSDT
  • freq: data frequency to use, 1h | 4h
  • res_dir: results directory
  • flag_filter: filter to use, [mmi | ang | stoch | sma]
    • vol: Volume filter
    • ang: Linear Regression Angle filter

Inspect Strategy

  1. MA Strategy

    • Description: A method to inspect the MA strategy with given params
      InspectMaStrategy(symbols, freq, name, n1, n2, timeperiod, threshold, flag_filter, stop_vars)
      
      • symbol: the name of the crypto, e.g., 'BTCUSDT'
      • freq: currently supported values are '1h' or '4h'
      • name, n1, n2: the name and the params of the ma strategy, e.g., 'sma', 100, 50
      • timeperiod: param used in either mmi or ang filter
      • threshold: param used in ang filter
      • flag_filter: currently supported fitlers: 'mmi', 'ang', default: None
      • stop_vars: dictionary of stop vars, currently support 'ts_stop', 'sl_stop', 'tp_stop', default None
    • Example: Inspect MA strategy linear_reg with n1=30 & n2=280 and sl_stop=0.1 & tp_stop=0.1
      InspectMaStrategy(
          symbols, 
          freq='4h', 
          name='linear_reg', n1=30, n2=280, 
          stop_vars={'sl_stop':0.1, 'tp_stop':0.1})
      
  2. BO Strategy

    • Description: A method to inspect the BO strategy

      InspectBoStrategy(symbol, freq, long_window, short_window, ts_stop, timeperiod, multiplier, threshold, flag_filter, flag_ts_stop)
      
      • symbols: a list of symbols to be optimzied on, e.g., 'BTCUSDT'
      • freq: currently supported values: '1h' or '4h'
      • long_window, short_window: breakout params
      • flag_filter: currently supported fitlers: 'vol', 'ang', default: None
      • timeperiod, multiplier: volume filter params
      • timeperiod, threshold: angle filter params
      • stop_vars: dictionary of stop vars, currently support 'ts_stop', 'sl_stop', 'tp_stop', default None
    • Example: Inspect 4h BTCUSDT breakout strategy with volume filter and trailing stop

      InspectBoStrategy(
          'BTCUSDT', 
          freq='4h', 
          long_window=100, short_window=50,
          flag_filter='vol', timeperiod=20, multiplier=2,
          stop_vars={'ts_stop':0.1})
      

CLI

Backtests can also be carried out in command line. To find out more

crypto --help

Example 1: Find the best params for BO strategy with vol filter using 4h data

crypto best-bo-strategy -f 4h -r results/best-4h-bo-vol-filter -g vol -e bo

Example 2: Find the best params for MA strategy with mmi filter and ts_stop using 1h data

crypto best-ma-strategy -f 1h -r results/best-1h-ma-mmi-filter -g mmi -t ts_stop

Tests

pytest

Release files for crypto-strategy 0.1.20

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for crypto-strategy 0.1.20
File Size Uploaded
crypto-strategy-0.1.20.tar.gz 51.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for crypto-strategy 0.1.20
File Interpreter ABI Platform
crypto_strategy-0.1.20-py3-none-any.whl Python 3 none any Details

Total release size: 111.8 kB

Release files / crypto-strategy-0.1.20.tar.gz

Download URL crypto-strategy-0.1.20.tar.gz
Size 51.4 kB
Tags Source
SHA-256 checksum
How to use checksums
6c64b339b61a606b5214d6200f3597bf73da9e9fd5a634a574afbcf08eb5da66
BLAKE2b-256 checksum
How to use checksums
30fb4110838303778af751ac6a5eb4f3b9c415f2c1818feab9b3805272272f26
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Release files / crypto_strategy-0.1.20-py3-none-any.whl

Download URL crypto_strategy-0.1.20-py3-none-any.whl
Size 60.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4621f810f942fa6f31ac2b97a2ee32fb45da28c7df81e412b41299d15aa9506c
BLAKE2b-256 checksum
How to use checksums
f90fa00f624c49149e3f976a5f132c3deaf126cfeca1f78fc8f5bb3ab1a1e6ef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Release history Release notifications | RSS feed

This release

0.1.20 This release

2 release files

0.1.19

2 release files

0.1.18

2 release files

0.1.15

2 release files

0.1.14

2 release files

0.1.13

2 release files

0.1.12

2 release files

0.1.11

2 release files

0.1.10

2 release files

0.1.9

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page