Merge branch 'develop' into plot_profit
This commit is contained in:
@@ -3,14 +3,23 @@
|
||||
import sys
|
||||
import logging
|
||||
import argparse
|
||||
|
||||
import matplotlib
|
||||
# matplotlib.use("Qt5Agg")
|
||||
import matplotlib.dates as mdates
|
||||
import matplotlib.pyplot as plt
|
||||
from pandas import DataFrame
|
||||
import talib.abstract as ta
|
||||
|
||||
import freqtrade.vendor.qtpylib.indicators as qtpylib
|
||||
from freqtrade import exchange, analyze
|
||||
from freqtrade.misc import common_args_parser
|
||||
from freqtrade.strategy.strategy import Strategy
|
||||
import freqtrade.misc as misc
|
||||
import freqtrade.optimize as optimize
|
||||
import freqtrade.analyze as analyze
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -21,7 +30,7 @@ def plot_parse_args(args):
|
||||
return parser.parse_args(args)
|
||||
|
||||
|
||||
def plot_analyzed_dataframe(args):
|
||||
def plot_analyzed_dataframe(args) -> None:
|
||||
"""
|
||||
Calls analyze() and plots the returned dataframe
|
||||
:param pair: pair as str
|
||||
@@ -31,35 +40,40 @@ def plot_analyzed_dataframe(args):
|
||||
pairs = [pair]
|
||||
timerange = misc.parse_timerange(args.timerange)
|
||||
|
||||
# Init strategy
|
||||
strategy = Strategy()
|
||||
strategy.init({'strategy': args.strategy})
|
||||
tick_interval = strategy.ticker_interval
|
||||
|
||||
tickers = {}
|
||||
if args.live:
|
||||
logger.info('Downloading pair.')
|
||||
# Init Bittrex to use public API
|
||||
exchange._API = exchange.Bittrex({'key': '', 'secret': ''})
|
||||
tickers[pair] = exchange.get_ticker_history(pair, args.ticker_interval)
|
||||
tickers[pair] = exchange.get_ticker_history(pair, tick_interval)
|
||||
else:
|
||||
tickers = optimize.load_data(args.datadir, pairs=pairs,
|
||||
ticker_interval=args.ticker_interval,
|
||||
ticker_interval=tick_interval,
|
||||
refresh_pairs=False,
|
||||
timerange=timerange)
|
||||
dataframes = optimize.tickerdata_to_dataframe(tickers)
|
||||
dataframe = dataframes[pair]
|
||||
dataframe = analyze.populate_buy_trend(dataframe)
|
||||
dataframe = analyze.populate_sell_trend(dataframe)
|
||||
|
||||
dates = misc.datesarray_to_datetimearray(dataframe['date'])
|
||||
|
||||
dataframe.loc[dataframe['buy'] == 1, 'buy_price'] = dataframe['close']
|
||||
dataframe.loc[dataframe['sell'] == 1, 'sell_price'] = dataframe['close']
|
||||
|
||||
# Two subplots sharing x axis
|
||||
fig, (ax1, ax2, ax3) = plt.subplots(3, sharex=True)
|
||||
fig.suptitle(pair + " " + str(args.ticker_interval), fontsize=14, fontweight='bold')
|
||||
fig.suptitle(pair + " " + str(tick_interval), fontsize=14, fontweight='bold')
|
||||
|
||||
ax1.plot(dates, dataframe['close'], label='close')
|
||||
# ax1.plot(dates, dataframe['sell'], 'ro', label='sell')
|
||||
ax1.plot(dates, dataframe['sma'], '--', label='SMA')
|
||||
ax1.plot(dates, dataframe['tema'], ':', label='TEMA')
|
||||
ax1.plot(dates, dataframe['blower'], '-.', label='BB low')
|
||||
ax1.plot(dates, dataframe['buy_price'], 'bo', label='buy')
|
||||
ax1.plot(dates, dataframe['close'] * dataframe['buy'], 'bo', label='buy')
|
||||
ax1.plot(dates, dataframe['close'] * dataframe['sell'], 'ro', label='sell')
|
||||
|
||||
ax1.legend()
|
||||
|
||||
ax2.plot(dates, dataframe['adx'], label='ADX')
|
||||
@@ -81,7 +95,6 @@ def plot_analyzed_dataframe(args):
|
||||
plt.setp([a.get_xticklabels() for a in fig.axes[:-1]], visible=False)
|
||||
plt.show()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
args = plot_parse_args(sys.argv[1:])
|
||||
plot_analyzed_dataframe(args)
|
||||
|
@@ -1,7 +1,6 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import sys
|
||||
import argparse
|
||||
import json
|
||||
import matplotlib.pyplot as plt
|
||||
import matplotlib.dates as mdates
|
||||
@@ -10,6 +9,7 @@ import numpy as np
|
||||
import freqtrade.optimize as optimize
|
||||
import freqtrade.misc as misc
|
||||
import freqtrade.exchange as exchange
|
||||
from freqtrade.strategy.strategy import Strategy
|
||||
|
||||
|
||||
def plot_parse_args(args):
|
||||
@@ -44,7 +44,7 @@ def make_profit_array(data, px, filter_pairs=[]):
|
||||
# total profits at each timeframe
|
||||
# to accumulated profits
|
||||
pa = 0
|
||||
for x in range(0,len(pg)):
|
||||
for x in range(0, len(pg)):
|
||||
p = pg[x] # Get current total percent
|
||||
pa += p # Add to the accumulated percent
|
||||
pg[x] = pa # write back to save memory
|
||||
@@ -67,7 +67,14 @@ def plot_profit(args) -> None:
|
||||
filter_pairs = args.pair
|
||||
|
||||
config = misc.load_config(args.config)
|
||||
config.update({'strategy': args.strategy})
|
||||
|
||||
# Init strategy
|
||||
strategy = Strategy()
|
||||
strategy.init(config)
|
||||
|
||||
pairs = config['exchange']['pair_whitelist']
|
||||
|
||||
if filter_pairs:
|
||||
filter_pairs = filter_pairs.split(',')
|
||||
pairs = list(set(pairs) & set(filter_pairs))
|
||||
@@ -75,7 +82,7 @@ def plot_profit(args) -> None:
|
||||
|
||||
timerange = misc.parse_timerange(args.timerange)
|
||||
tickers = optimize.load_data(args.datadir, pairs=pairs,
|
||||
ticker_interval=args.ticker_interval,
|
||||
ticker_interval=strategy.ticker_interval,
|
||||
refresh_pairs=False,
|
||||
timerange=timerange)
|
||||
dataframes = optimize.preprocess(tickers)
|
||||
@@ -96,7 +103,7 @@ def plot_profit(args) -> None:
|
||||
for pair, pair_data in dataframes.items():
|
||||
close = pair_data['close']
|
||||
maxprice = max(close) # Normalize price to [0,1]
|
||||
print('Pair %s has length %s' %(pair, len(close)))
|
||||
print('Pair %s has length %s' % (pair, len(close)))
|
||||
for x in range(0, len(close)):
|
||||
avgclose[x] += close[x] / maxprice
|
||||
# avgclose += close
|
||||
@@ -108,7 +115,7 @@ def plot_profit(args) -> None:
|
||||
|
||||
filename = 'backtest-result.json'
|
||||
with open(filename) as file:
|
||||
data = json.load(file)
|
||||
data = json.load(file)
|
||||
pg = make_profit_array(data, max_x, filter_pairs)
|
||||
|
||||
#
|
||||
|
Reference in New Issue
Block a user