def run(strategy_name): """ Run transformation and model seletion for each strategy. Args: strategy_name: string. Name of the strategy. e.g. 'Euler'. Returns: void. """ # Find the transformer and the strategy module. module_name = strategy_name.lower() # The transformer. malt = __import__('malt.strategies.' + module_name + '.transformer') strategies = getattr(malt, 'strategies') transformer = getattr(getattr(strategies, module_name), 'transformer') # The strategy module. strategy_module = common.get_strategy_module(strategy_name) # Run their respective main functions. transformer.main() strategy_module.main() return
def run_at_day_open(executor, instrument): """ Run the operations at day's open. Gather yesterday's prices, predict today's price changes and take appropriate actions. Args: executor: exec.Executor. The object for executing trades. instrument: string. The currency pair. e.g. 'EUR_USD'. Returns: void. """ # Log. logger.info("Daily run: On %s.", instrument) # Get yesterday's candle first. yesterdays_candle = get_yesterdays_candle(instrument) # Load the model strategy parameters. model_loc, param_loc = common.get_strategy_loc(instrument) model = joblib.load(model_loc) strategy_params = json.load(open(param_loc, 'r')) logger.info("Strategy: %s.", str(strategy_params)) # Instantiate the right strategy object from name. name = strategy_params['name'] module = common.get_strategy_module(name) strategy = getattr(module, name)(instrument) # Set the parameters. strategy.set_params(**strategy_params) strategy.model = model logger.info("Model: %s.", str(model)) # Execute. strategy.execute(executor, yesterdays_candle) return