コード例 #1
0
ファイル: euler.py プロジェクト: yizhang7210/MaLT
    def serialize(self):
        """ Serialize this strategy to the designated location.

            Args:
                void.

            Returns:
                void.
        """
        # Get the designated locations.
        model_loc, param_loc = common.get_strategy_loc(self.instrument)

        # Dump the data.
        joblib.dump(self.model, model_loc)
        json.dump(self.params, open(param_loc, 'w'))

        return
コード例 #2
0
ファイル: daily_run.py プロジェクト: yizhang7210/MaLT
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