Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume De Saint Martin committed Oct 4, 2018
2 parents 831847f + bb33a09 commit 05adf7d
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 33 deletions.
4 changes: 2 additions & 2 deletions Evaluator/Strategies/move_signals_strategy_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ class MoveSignalsStrategyEvaluator(MixedStrategiesEvaluator):
MEDIUM_PERIOD_WEIGHT = 0.30
LONG_PERIOD_WEIGHT = 0.30

SIGNAL_MINIMUM_THRESHOLD = 0.35
SIGNAL_MINIMUM_THRESHOLD = 0.15

DESCRIPTION = "MoveSignalsStrategyEvaluator is a fractal strategy (strategy using different time frames to " \
"balance decisions). It is using KlingerOscillatorMomentumEvaluator (momentum evaluator) " \
"to know when to start a trade and BBMomentumEvaluator (bollinger momentum evaluator) " \
"to know how much weight giving to this trade. Uses InstantFluctuationsEvaluator to spot " \
"sudden market changes within timeframes. Warning: Works only on liquid markets"
"sudden market changes within timeframes. Warning: Works only on liquid markets."

def __init__(self):
super().__init__()
Expand Down
12 changes: 7 additions & 5 deletions Evaluator/TA/momentum_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,17 +303,19 @@ def eval_impl(self):
zero_crossing_indexes = TrendAnalysis.get_threshold_change_indexes(ema_difference, 0)

current_difference = ema_difference[-1]
significant_move_threshhold = numpy.std(ema_difference)
significant_move_threshold = numpy.std(ema_difference)

factor = 0.2

if TrendAnalysis.peak_has_been_reached_already(ema_difference[zero_crossing_indexes[-1]:]):
if abs(current_difference) > significant_move_threshhold:
if abs(current_difference) > significant_move_threshold:
factor = 1
else:
factor = 0.5

eval_proposition = current_difference*factor/(significant_move_threshhold)
eval_proposition = current_difference*factor/significant_move_threshold

if abs(eval_proposition) > 1:
eval_proposition = 1 if eval_proposition > 0 else -1
if abs(eval_proposition) > 1:
eval_proposition = 1 if eval_proposition > 0 else -1

self.eval_note = eval_proposition
5 changes: 4 additions & 1 deletion Evaluator/Util/trend_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ def peak_has_been_reached_already(data):
min_val = min(data)
max_val = max(data)
current_val = data[-1] / 0.8
return current_val > min_val or current_val < max_val
if current_val > 0:
return current_val < max_val
else:
return current_val > min_val
else:
return False

Expand Down
26 changes: 20 additions & 6 deletions Trading/Mode/signal_trading_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

class SignalTradingMode(AbstractTradingMode):
DESCRIPTION = "SignalTradingMode is a low risk trading mode adapted to flat markets. It's using the daily " \
"trading mode orders system with adapted parameters. Warning: Works only on liquid markets"
"trading mode orders system with adapted parameters. Warning: Works only on liquid markets."

def __init__(self, config, exchange):
super().__init__(config, exchange)
Expand All @@ -31,16 +31,30 @@ def create_creators(self, symbol, symbol_evaluator):


class SignalTradingModeCreator(DailyTradingModeCreator):
pass
def __init__(self, trading_mode):
super().__init__(trading_mode)

self.STOP_LOSS_ORDER_MAX_PERCENT = 0.99
self.STOP_LOSS_ORDER_MIN_PERCENT = 0.95

self.QUANTITY_MIN_PERCENT = 0.1
self.QUANTITY_MAX_PERCENT = 0.9

self.QUANTITY_MARKET_MIN_PERCENT = 0.5
self.QUANTITY_MARKET_MAX_PERCENT = 1
self.QUANTITY_BUY_MARKET_ATTENUATION = 0.2

self.BUY_LIMIT_ORDER_MAX_PERCENT = 0.995
self.BUY_LIMIT_ORDER_MIN_PERCENT = 0.99


class SignalTradingModeDecider(DailyTradingModeDecider):
def __init__(self, trading_mode, symbol_evaluator, exchange):
super().__init__(trading_mode, symbol_evaluator, exchange)

# If final_eval not is < X_THRESHOLD --> state = X
self.VERY_LONG_THRESHOLD = -0.9
self.LONG_THRESHOLD = -0.45
self.NEUTRAL_THRESHOLD = 0.45
self.SHORT_THRESHOLD = 0.9
self.VERY_LONG_THRESHOLD = -0.88
self.LONG_THRESHOLD = -0.4
self.NEUTRAL_THRESHOLD = 0.4
self.SHORT_THRESHOLD = 0.88
self.RISK_THRESHOLD = 0.15
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,28 @@ class TestMoveSignalsStrategyEvaluator(AbstractStrategyTest):

@staticmethod
def test_default_run(strategy_tester):
strategy_tester.run_test_default_run(-13)
strategy_tester.run_test_default_run(-8)

@staticmethod
def test_slow_downtrend(strategy_tester):
strategy_tester.run_test_slow_downtrend(-13, -5, -17.5, 0)
strategy_tester.run_test_slow_downtrend(-8, -7, -22, 0)

@staticmethod
def test_sharp_downtrend(strategy_tester):
strategy_tester.run_test_sharp_downtrend(-12, -18)
strategy_tester.run_test_sharp_downtrend(-9.5, -15)

@staticmethod
def test_flat_markets(strategy_tester):
strategy_tester.run_test_flat_markets(-3, -0.5, -15, -6)
strategy_tester.run_test_flat_markets(-2, 1, -13.5, 0.1)

@staticmethod
def test_slow_uptrend(strategy_tester):
strategy_tester.run_test_slow_uptrend(-4, 5)
strategy_tester.run_test_slow_uptrend(-2, 2.5)

@staticmethod
def test_sharp_uptrend(strategy_tester):
strategy_tester.run_test_sharp_uptrend(20, 14)
strategy_tester.run_test_sharp_uptrend(27, 14)

@staticmethod
def test_up_then_down(strategy_tester):
strategy_tester.run_test_up_then_down(-3.5)
strategy_tester.run_test_up_then_down(-6)
24 changes: 12 additions & 12 deletions tests/Evaluator/TA/test_klinger_TA_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,35 @@ def test_stress_test(evaluator_tester):

@staticmethod
def test_reactions_to_dump(evaluator_tester):
evaluator_tester.run_test_reactions_to_dump(0.1, START_PENDING_EVAL_NOTE, -1, -1, -1)
evaluator_tester.run_test_reactions_to_dump(0, 0, -0.2, -0.4, -0.55)

@staticmethod
def test_reactions_to_pump(evaluator_tester):
evaluator_tester.run_test_reactions_to_pump(-0.1, -0.1, START_PENDING_EVAL_NOTE, 0.2, 0.5,
START_PENDING_EVAL_NOTE, -1)
evaluator_tester.run_test_reactions_to_pump(-0.1, -0.1, 0, 0.1, 0.2,
0, -0.5)

@staticmethod
def test_reaction_to_rise_after_over_sold(evaluator_tester):
evaluator_tester.run_test_reactions_to_rise_after_over_sold(-0.3, -1, -1, -1, START_PENDING_EVAL_NOTE)
evaluator_tester.run_test_reactions_to_rise_after_over_sold(-0.2, -0.6, -1, -1, 0.1)

@staticmethod
def test_reaction_to_over_bought_then_dip(evaluator_tester):
evaluator_tester.run_test_reactions_to_over_bought_then_dip(-1, START_PENDING_EVAL_NOTE, 1, 1, -1, -1)
evaluator_tester.run_test_reactions_to_over_bought_then_dip(-1, 0, 0.5, 0.5, -0.8, -1)

@staticmethod
def test_reaction_to_flat_trend(evaluator_tester):
evaluator_tester.run_test_reactions_to_flat_trend(
# eval_start_move_ending_up_in_a_rise,
START_PENDING_EVAL_NOTE,
0.9,
# eval_reaches_flat_trend, eval_first_micro_up_p1, eval_first_micro_up_p2,
1, 1, 0.3,
0.7, 0.55, 0.3,
# eval_micro_down1, eval_micro_up1, eval_micro_down2, eval_micro_up2,
-1, -0.25, -0.4, -0.1,
-0.3, -0.25, -0.4, -0.1,
# eval_micro_down3, eval_back_normal3, eval_micro_down4, eval_back_normal4,
0, -0.2, 0.1, 0.1,
0, -0.1, 0.1, 0.1,
# eval_micro_down5, eval_back_up5, eval_micro_up6, eval_back_down6,
-0.4, -0.1, 0.2, 0.25,
-0.1, -0.1, 0.1, 0.25,
# eval_back_normal6, eval_micro_down7, eval_back_up7, eval_micro_down8,
0, 0.1, -0.2, START_PENDING_EVAL_NOTE,
0, 0.1, -0.2, 0,
# eval_back_up8, eval_micro_down9, eval_back_up9
0.1, -0.2, 0.25)
0, 0, 0.1)

0 comments on commit 05adf7d

Please sign in to comment.