コード例 #1
0
ファイル: ut.py プロジェクト: andreplima/trend-analysis
    def test_condition04(self):  # corresponds to condition01 with inflation

        # test data
        thresholds = {}
        limits = {}

        timeline = [
            ud.datestr2ts(strdate)
            for strdate in ['2014-06-01', '2015-10-01', '2017-06-01']
        ]
        realSeries = {
            'stock1': [(0, 10.0), (1, 11.0), (2, 12.0)],
            'stock2': [(0, 10.0), (1, 11.0), (2, 12.0)],
        }

        param_adjinflat = True
        present = datetime.fromtimestamp(timeline[2])

        thresholds['stock1'] = ud.findThresholds(realSeries['stock1'],
                                                 timeline, param_adjinflat)
        thresholds['stock2'] = ud.findThresholds(realSeries['stock2'],
                                                 timeline, param_adjinflat)
        limits['stock1'] = ud.findLimits(realSeries['stock1'], timeline,
                                         param_adjinflat)
        limits['stock2'] = ud.findLimits(realSeries['stock2'], timeline,
                                         param_adjinflat)

        param_models = [('MA', None)]
        param_prices = ['close']

        weights = {(ticker, modelType, priceType): 1.0
                   for ticker in ['stock2', 'stock1']
                   for (modelType, _) in param_models
                   for priceType in param_prices}
        ws = sum(weights.values())
        nt = len(realSeries.keys())
        weights = {key: weights[key] / ws * nt for key in weights}

        # expected response
        ref_de2twMap = {
            0: ('threshold', ('stock1', None, None)),
            1: ('threshold', ('stock1', param_adjinflat, present)),
            2: ('threshold', ('stock2', None, None)),
            3: ('threshold', ('stock2', param_adjinflat, present)),
            4: ('weights', ('stock1', 'MA', 'close')),
            5: ('weights', ('stock2', 'MA', 'close'))
        }
        ref_bounds = [(0, 1), (0, 1), (0, 1), (0, 1), (0, 1), (0, 1)]
        ref_x0 = np.array([0, 1, 0, 1, 1, 1])

        # actual response
        bounds, de2twMap, x0 = ud.tw2debv(thresholds, weights, limits,
                                          param_models, param_prices)

        # compares expected and actual responses
        success = ref_bounds == bounds and ref_de2twMap == de2twMap and np.allclose(
            ref_x0, x0)
        self.assertTrue(success)
コード例 #2
0
ファイル: ut.py プロジェクト: andreplima/trend-analysis
    def test_condition06(self):  # corresponds to condition02 with inflation

        # test data
        thresholds = {}
        limits = {}

        timeline = [
            ud.datestr2ts(strdate)
            for strdate in ['2014-06-01', '2015-10-01', '2017-06-01']
        ]
        realSeries = {
            'stock1': [(0, 10.0), (1, 11.0), (2, 12.0)],
            'stock2': [(0, 10.0), (1, 11.0), (2, 12.0)],
        }

        param_adjinflat = True
        present = datetime.fromtimestamp(timeline[2])

        thresholds['stock1'] = ud.findThresholds(realSeries['stock1'],
                                                 timeline, param_adjinflat)
        thresholds['stock2'] = ud.findThresholds(realSeries['stock2'],
                                                 timeline, param_adjinflat)
        limits['stock1'] = ud.findLimits(realSeries['stock1'], timeline,
                                         param_adjinflat)
        limits['stock2'] = ud.findLimits(realSeries['stock2'], timeline,
                                         param_adjinflat)

        param_models = [('MA', None), ('ARIMA', None)]
        param_prices = ['close', 'open']

        weights = {(ticker, modelType, priceType): 1.0
                   for ticker in ['stock2', 'stock1']
                   for (modelType, _) in param_models
                   for priceType in param_prices}
        ws = sum(weights.values())
        nt = len(realSeries.keys())
        weights = {key: weights[key] / ws * nt for key in weights}

        bounds, de2twMap, x0 = ud.tw2debv(thresholds, weights, limits,
                                          param_models, param_prices)

        # expected response
        ref_de2twMap = (thresholds, weights)

        # actual response
        (_thresholds, _weights) = ud.dev2tw(x0, de2twMap, limits)

        # compares expected and actual responses
        success = thresholds == _thresholds and weights == _weights
        self.assertTrue(success)
コード例 #3
0
ファイル: ut.py プロジェクト: andreplima/trend-analysis
    def test_condition02(self):

        # test data
        timeline = [
            ud.datestr2ts(strdate)
            for strdate in ['2014-06-01', '2015-10-01', '2017-06-01']
        ]
        series = [(0, 10.0), (1, 11.0), (2, 12.0)]
        param_adjinflat = True
        present = datetime.fromtimestamp(timeline[2])

        # expected response
        ref = (10.28, 12.0, param_adjinflat, present)

        # actual response
        val = ud.findLimits(series, timeline, param_adjinflat)

        # compares expected and actual responses
        res = [ref[i] == val[i] for i in range(len(ref))]
        success = reduce(__and__, res)
        self.assertTrue(success)
コード例 #4
0
ファイル: ut.py プロジェクト: andreplima/trend-analysis
    def test_condition03(self):

        # test data
        timeline = [
            ud.datestr2ts(strdate)
            for strdate in ['2014-06-01', '2015-10-01', '2017-06-01']
        ]
        series = [(0, 10.0), (1, 11.0), (2, 12.0)]
        param_adjinflat = True
        thresholds = ud.findThresholds(series, timeline, param_adjinflat)

        # expected response
        ref = [(0, 'Down'), (1, 'Stable'), (2, 'Up')]

        # actual response
        val = ud.classify(series, timeline, thresholds)

        # compares expected and actual responses
        res = [ref[i] == val[i] for i in range(len(ref))]
        success = reduce(__and__, res)
        self.assertTrue(success)