class StrategyAnalyzer(): """ Executes the trading strategies and analyzes the results. """ def __init__(self, config): self.exchange_aggregator = ExchangeInterface(config) self.logger = structlog.get_logger() def analyze_breakout(self, coin_pair, period_count=5, time_unit='5m'): breakout_analyzer = Breakout() historical_data = self.exchange_aggregator.get_historical_data( coin_pair=coin_pair, period_count=period_count, time_unit=time_unit) breakout_value, is_breaking_out = breakout_analyzer.find_breakout(historical_data) return breakout_value, is_breaking_out def analyze_rsi(self, coin_pair, period_count=18, time_unit='1h'): rsi_analyzer = RelativeStrengthIndex() historical_data = self.exchange_aggregator.get_historical_data( coin_pair=coin_pair, period_count=period_count, time_unit=time_unit ) rsi_value = rsi_analyzer.find_rsi(historical_data) return rsi_value def analyze_moving_averages(self, coin_pair, period_count=20, time_unit='5m'): ma_analyzer = MovingAverages() historical_data = self.exchange_aggregator.get_historical_data( coin_pair=coin_pair, period_count=period_count, time_unit=time_unit ) sma_value = ma_analyzer.calculate_sma(period_count, historical_data) ema_value = ma_analyzer.calculate_ema(period_count, historical_data) return sma_value, ema_value def analyze_ichimoku_cloud(self, coin_pair): ic_analyzer = IchimokuCloud() base_line_data = self.exchange_aggregator.get_historical_data( coin_pair=coin_pair, period_count=26, time_unit='1d' ) conversion_line_data = self.exchange_aggregator.get_historical_data( coin_pair=coin_pair, period_count=9, time_unit='1d' ) span_b_data = self.exchange_aggregator.get_historical_data( coin_pair=coin_pair, period_count=52, time_unit='1d' ) leading_span_a = ic_analyzer.calculate_leading_span_a(base_line_data, conversion_line_data) leading_span_b = ic_analyzer.calculate_leading_span_b(span_b_data) return leading_span_a, leading_span_b
def main(): with open("app/config.yml", 'r') as stream: data_loaded = yaml.load(stream) exchangeInterface = ExchangeInterface(data_loaded['exchanges']) exchange = list(data_loaded['exchanges'].keys())[0] market_pair = data_loaded['settings']['market_pairs'][0] interval = data_loaded['settings']['update_interval'] max_periods = data_loaded['settings']['backtest_periods'] ohlcv = exchangeInterface.get_historical_data(exchange, market_pair, interval, max_periods) first = CDL_Test(ohlcv) cdl_list = list(map(lambda x: eval('talib.' + x), cdl)) params_list = {'trailing_window': [10, 15], 'indicator': cdl_list} #result = first.run_algorithm(params_list) best_sharpe, params = first.optim_algo(params_list) first.optim_grid.sort_values(by='sharpe', ascending=False) result = first.run_algorithm(params) pf.create_full_tear_sheet(result.returns)