Skip to content

Instantly share code, notes, and snippets.

@spideyspideyspidey
Last active May 17, 2021 01:53
Show Gist options
  • Save spideyspideyspidey/08f8d92b7bf966d09a15ba019708a96b to your computer and use it in GitHub Desktop.
Save spideyspideyspidey/08f8d92b7bf966d09a15ba019708a96b to your computer and use it in GitHub Desktop.
Benchmark Jesse

1. Create a file called routes-benchmark.py and copy the following contents to it.

Note: before doing this, create a copy of your existing routes.py as the script will overwrite routes.py

from jesse.utils import anchor_timeframe
routes = [
    ('Binance', '<coin>', '<timeframe>', 'Bitcoin_Strategy'),
]

2. Create a script called benchmark.sh and copy the following contents to it.

#!/bin/bash
# Usage: ./benchmark.sh


coins=("DOGE-USDT" "BTC-USDT" "ETH-USDT")         # edit the coin list
timeframes=("15m" "30m" "1h")                     # edit the timeframes you care about

start="2021-05-01"                                # edit the start date
end="2021-05-11"                                  # edit the end date
for coin in "${coins[@]}";
do
    for tf in "${timeframes[@]}";
    do
        sed 's/<coin>/'$coin'/g' routes-benchmark.py > routes.py
        sed -i '' 's/<timeframe>/'$tf'/g' routes.py 
        results=`jesse backtest $start $end | grep -E "Net Profit|Market"`
        profit=`echo $results | grep "Profit" | awk -F"Profit" '{print $2}' | awk -F"|" '{print $2}' | xargs | awk -F"Market" '{print $1}' | xargs`
        marketChange=`echo $results | grep "Market" | awk -F"Market" '{print $2}' | awk -F"|" '{print $2}' | xargs`
        echo "$coin for $tf, p/l= ${profit}, Market Change= ${marketChange}"
    done
done

Output

DOGE-USDT for 15m, p/l= 250.2759 (25.03%), Market Change= 33.36%
DOGE-USDT for 30m, p/l= 212.69 (21.27%), Market Change= 33.36%
DOGE-USDT for 1h, p/l= 478.6765 (47.87%), Market Change= 33.36%
BTC-USDT for 15m, p/l= -99.2274 (-9.92%), Market Change= -3.0%
BTC-USDT for 30m, p/l= -64.5765 (-6.46%), Market Change= -3.0%
BTC-USDT for 1h, p/l= -38.3264 (-3.83%), Market Change= -3.0%
ETH-USDT for 15m, p/l= 215.7698 (21.58%), Market Change= 42.48%
ETH-USDT for 30m, p/l= 208.6741 (20.87%), Market Change= 42.48%
ETH-USDT for 1h, p/l= 194.8079 (19.48%), Market Change= 42.48%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment