Merge commit 'aa7aeb046ef72412cadd094666efc8e4c503ef2d' into feature/objectify

This commit is contained in:
Gerald Lonlas 2018-03-02 23:28:36 -08:00
commit 0632cf0f44
5 changed files with 17 additions and 24 deletions

View File

@ -177,15 +177,15 @@ class Analyze(object):
return True
# Check if time matches and current rate is above threshold
time_diff = (current_time - trade.open_date).total_seconds() / 60
for duration, threshold in sorted(self.strategy.minimal_roi.items()):
if time_diff > float(duration) and current_profit > threshold:
time_diff = (current_time.timestamp() - trade.open_date.timestamp()) / 60
for duration_string, threshold in self.strategy.minimal_roi.items():
duration = float(duration_string)
if time_diff > duration and current_profit > threshold:
return True
self.logger.debug(
'Threshold not reached. (cur_profit: %1.2f%%)',
float(current_profit) * 100.0
)
if time_diff < duration:
return False
return False
def tickerdata_to_dataframe(self, tickerdata: Dict[str, List]) -> Dict[str, DataFrame]:

View File

@ -114,15 +114,13 @@ class Backtesting(object):
)
# calculate win/lose forwards from buy point
sell_subset = ticker[ticker.index > row.Index][['close', 'sell']]
sell_subset = ticker[ticker.index > row.Index][['close', 'sell', 'buy']]
for row2 in sell_subset.itertuples(index=True):
if max_open_trades > 0:
# Increase trade_count_lock for every iteration
trade_count_lock[row2.Index] = trade_count_lock.get(row2.Index, 0) + 1
# Buy is on is in the buy_subset there is a row that matches the date
# of the sell event
buy_signal = (buy_subset.index == row2.Index).any()
buy_signal = row2.buy
if(
self.analyze.should_sell(
trade=trade,

View File

@ -194,8 +194,8 @@ class Trade(_DECL_BASE):
"""
open_trade_price = self.calc_open_trade_price()
close_trade_price = self.calc_close_trade_price(
rate=Decimal(rate or self.close_rate),
fee=Decimal(fee or self.fee)
rate=(rate or self.close_rate),
fee=(fee or self.fee)
)
return float("{0:.8f}".format(close_trade_price - open_trade_price))
@ -213,8 +213,8 @@ class Trade(_DECL_BASE):
open_trade_price = self.calc_open_trade_price()
close_trade_price = self.calc_close_trade_price(
rate=Decimal(rate or self.close_rate),
fee=Decimal(fee or self.fee)
rate=(rate or self.close_rate),
fee=(fee or self.fee)
)
return float("{0:.8f}".format((close_trade_price / open_trade_price) - 1))

View File

@ -6,6 +6,7 @@ This module load custom strategies
import importlib
import os
import sys
from collections import OrderedDict
from pandas import DataFrame
from freqtrade.logger import Logger
from freqtrade.constants import Constants
@ -56,7 +57,9 @@ class Strategy(object):
)
# Minimal ROI designed for the strategy
self.minimal_roi = self.custom_strategy.minimal_roi
self.minimal_roi = OrderedDict(sorted(
self.custom_strategy.minimal_roi.items(),
key=lambda tuple: float(tuple[0]))) # sort after converting to number
# Optimal stoploss designed for the strategy
self.stoploss = self.custom_strategy.stoploss

View File

@ -271,10 +271,6 @@ def test_calc_profit(limit_buy_order, limit_sell_order):
# Lower than open rate
assert trade.calc_profit(rate=0.00000123, fee=0.003) == -0.00089092
# Only custom fee without sell order applied
with pytest.raises(TypeError):
trade.calc_profit(fee=0.003)
# Test when we apply a Sell order. Sell higher than open rate @ 0.00001173
trade.update(limit_sell_order)
assert trade.calc_profit() == 0.00006217
@ -299,10 +295,6 @@ def test_calc_profit_percent(limit_buy_order, limit_sell_order):
# Get percent of profit with a custom rate (Lower than open rate)
assert trade.calc_profit_percent(rate=0.00000123) == -0.88863827
# Only custom fee without sell order applied
with pytest.raises(TypeError):
trade.calc_profit_percent(fee=0.003)
# Test when we apply a Sell order. Sell higher than open rate @ 0.00001173
trade.update(limit_sell_order)
assert trade.calc_profit_percent() == 0.06201057