示例#1
0
    def test_dry_run(self):
        """ Test dry run in euler. Check that it tests a model on historical
            data properly.
        """
        # Initialize model with fixed random state.
        model = tree.DecisionTreeRegressor(random_state=888)

        # Initialize learner and force load test data.
        learner = Learner("GBP_USD")
        learner.data_mat = base.read_features(self.tmp_clean_file)

        # Build model and test preliminary results.
        learner.build_model(model, 0.78)
        pred, _ = learner.test_model(model)

        # Initialize Euler and force load test data.
        strategy = euler.Euler("GBP_USD")
        strategy.set_params(unit_shape=common.UNIT_LINEAR, threshold=85)
        strategy.test_data = transformer.read_raw_file(self.tmp_raw_file)
        balance = strategy.dry_run(pred)

        # Test the results.
        self.assertEqual(balance.size, 628)
        self.assertEqual(round(balance[0], 4), -0.1965)
        self.assertEqual(round(balance[210], 4), 0.3467)
        self.assertEqual(round(balance[-143], 4), -19.6579)
        self.assertEqual(round(balance[-30], 4), -20.7953)
        self.assertEqual(round(sum(balance), 4), -4088.2712)

        return
示例#2
0
    def __init__(self, instrument):
        """ Initialize the Learner class.

            Args:
                instrument: string. The currency pair. e.g. 'EUR_USD'.

            Returns:
                void.
        """
        self.instrument = instrument
        self.data_file = util.get_clean_data(instrument)
        self.data_mat = base.read_features(self.data_file)
        self.sample_index = 0

        # Checking input read from file.
        assert self.data_mat.shape[1] == 8

        return
示例#3
0
    def test_leaner_tree_regressor(self):
        """ Test the learner builds and tests a tree regressor properly."""
        # Initialize model with fixed random state.
        model = tree.DecisionTreeRegressor(random_state=888)

        # Initialize learner and force load test data.
        learner = Learner("GBP_USD")
        learner.data_mat = base.read_features(self.tmp_file)

        # Build model and test preliminary results.
        learner.build_model(model, 0.78)
        pred, result = learner.test_model(model)

        # Test the results.
        self.assertEqual(pred.size, 628)
        self.assertEqual(pred[0], -160.2)
        self.assertEqual(pred[200], -31.0)
        self.assertEqual(pred[-30], -53.6)
        self.assertEqual(len(result), 2)
        self.assertEqual(round(result['ave_diff'], 4), 88.3980)
        self.assertEqual(round(result['prop_op'], 4), 0.4341)

        return