Beispiel #1
0
def test_prediction_mean(monkeypatch):
    params = {
        'data': {
            'ew_lags': 12.166882847847372,
            'returns_lags': 5
        },
        'model': {
            'bagging_temperature': 1.5889359773128047,
            'depth': 2,
            'ignored_features': (),
            'l2_leaf_reg': 3.0691833972589424,
            'learning_rate': 0.04230361495762283,
            'one_hot_max_size': 2,
            'random_strength': 3.6085599262888683
        }
    }
    monkeypatch.setattr(model.ReturnsModel, 'PARAMS', params)
    returns = model.ReturnsModel(('MSRS', 'MSTT', 'RTKMP', 'UPRO', 'FEES'),
                                 pd.Timestamp('2018-10-11')).prediction_mean
    assert isinstance(returns, pd.Series)
    assert len(returns) == 5
    assert returns.index.tolist() == ['MSRS', 'MSTT', 'RTKMP', 'UPRO', 'FEES']
    assert returns['MSRS'] == 0.0018521857721484048
    assert returns['MSTT'] == 0.004415906411386809
    assert returns['RTKMP'] == 0.002905142786419567
    assert returns['UPRO'] == 0.0028195209196578627
    assert returns['FEES'] == 0.0037373919332427726
Beispiel #2
0
def test_prediction_std(monkeypatch):
    params = {
        'data': {
            'ew_lags': 12.166882847847372,
            'returns_lags': 5
        },
        'model': {
            'bagging_temperature': 1.5889359773128047,
            'depth': 2,
            'ignored_features': (),
            'l2_leaf_reg': 3.0691833972589424,
            'learning_rate': 0.04230361495762283,
            'one_hot_max_size': 2,
            'random_strength': 3.6085599262888683
        }
    }
    monkeypatch.setattr(model.ReturnsModel, 'PARAMS', params)
    std = model.ReturnsModel(('MSRS', 'RTKM', 'RTKMP', 'UPRO', 'FEES'),
                             pd.Timestamp('2018-10-11')).prediction_std
    assert isinstance(std, pd.Series)
    assert len(std) == 5
    assert std.index.tolist() == ['MSRS', 'RTKM', 'RTKMP', 'UPRO', 'FEES']
    assert std['MSRS'] == 0.049892858163254374
    assert std['RTKM'] == 0.04798205289008257
    assert std['RTKMP'] == 0.03734821638483238
    assert std['UPRO'] == 0.046223684807991286
    assert std['FEES'] == 0.08119363794137813
Beispiel #3
0
def test_new_manager():
    positions = ('LSRG', 'VSMO', 'AKRN', 'GCHE', 'MTSS')
    date = pd.Timestamp('2018-10-12')
    data = manager.ReturnsMLDataManager(positions, date)
    assert data.value.params == model.ReturnsModel(positions, date).params
    assert data.value.positions == positions
    assert data.value.date == date
Beispiel #4
0
def test_make_data_space():
    returns = model.ReturnsModel(('CHMF', 'MSTT', 'RTKMP', 'UPRO', 'FEES'),
                                 pd.Timestamp('2018-10-11'))
    space = returns._make_data_space()
    assert isinstance(space, dict)
    assert len(space) == 2
    assert isinstance(space['ew_lags'], hyperopt.pyll.Apply)
    assert isinstance(space['returns_lags'], hyperopt.pyll.Apply)
Beispiel #5
0
def test_check_data_space_bounds_lower(capsys):
    returns = model.ReturnsModel(('CHMF', 'MSTT', 'RTKMP', 'UPRO', 'FEES'),
                                 pd.Timestamp('2018-10-11'))
    params = copy.deepcopy(model.PARAMS)
    params['data']['ew_lags'] /= 1 + model.EW_LAGS_RANGE * 0.91
    returns._check_data_space_bounds(params)
    captured = capsys.readouterr()
    assert 'Необходимо увеличить EW_LAGS_RANGE до' in captured.out
    assert 'Необходимо увеличить MAX_RETURNS_LAGS до' not in captured.out
Beispiel #6
0
def test_manager_change_params(monkeypatch):
    fake_params = copy.deepcopy(model.ReturnsModel.PARAMS)
    fake_params['data']['returns_lags'] += 1
    monkeypatch.setattr(model.ReturnsModel, 'PARAMS', fake_params)
    positions = ('LSRG', 'VSMO', 'MSRS', 'GCHE', 'MTSS')
    date = pd.Timestamp('2018-10-11')
    data = manager.ReturnsMLDataManager(positions, date)
    assert data.value.params == model.ReturnsModel(positions, date).params
    assert data.value.params['data']['returns_lags'] == fake_params['data']['returns_lags']
    assert data.value.positions == positions
    assert data.value.date == date
Beispiel #7
0
def test_check_data_space_bounds(capsys):
    returns = model.ReturnsModel(('CHMF', 'MSTT', 'RTKMP', 'UPRO', 'FEES'),
                                 pd.Timestamp('2018-10-11'))
    returns._check_data_space_bounds(model.PARAMS)
    captured = capsys.readouterr()
    assert captured.out == ''