Example #1
0
def test_string_to_daterange_raises():
    with pytest.raises(ValueError) as e:
        string_to_daterange('20120101-20130101-20140101')
    assert str(
        e.value
    ) == "Too many dates in input string [20120101-20130101-20140101] with delimiter (-)"
Example #2
0
def test_string_to_daterange(instr, expected_ts, expected_dt):
    assert string_to_daterange(instr) == expected_ts
    assert string_to_daterange(instr, as_dates=True) == expected_dt
Example #3
0
def test_string_to_daterange(instr, expected_ts, expected_dt):
    assert string_to_daterange(instr) == expected_ts
    assert string_to_daterange(instr, as_dates=True) == expected_dt
Example #4
0
def test_string_to_daterange_raises():
    with pytest.raises(ValueError) as e:
        string_to_daterange('20120101-20130101-20140101')
    assert str(e.value) == "Too many dates in input string [20120101-20130101-20140101] with delimiter (-)"
Example #5
0
# 6307
#for i in range(4000, 6307):
for i in range(0, len(Ativos)):
    Ati_ = Ativos[i]
    print('Adicionando o ativo:', Ati_)
    data = pd.DataFrame()

    for lib_ in all_libs:
        library = store[lib_]
        mes = int(lib_[-2:])
        ano = int(lib_[-6:-2])
        mes2 = mes + 1 if mes + 1 <= 12 else 1
        ano2 = ano if mes2 != 1 else ano + 1
        rng = [datetime.date(ano, mes, 1), datetime.date(ano2, mes2, 1)]
        date_range = string_to_daterange("%s-%s" %
                                         (rng[0].strftime("%Y%m%d%H%M%z"),
                                          rng[-1].strftime("%Y%m%d%H%M%z")))

        try:
            in_data_raw = library.read(Ati_, date_range=date_range)
            in_data_raw = in_data_raw[in_data_raw.Direct !=
                                      1]  # Exclui diretas
            in_data_raw[
                'Fin'] = in_data_raw.Qtd * in_data_raw.Price  # Volume financeiro

            in_data = in_data_raw['Price'].resample('1Min').ohlc()
            in_data['volume'] = in_data_raw['Fin'].resample('1Min', how='sum')
            in_data['total_qtd'] = in_data_raw['Qtd'].resample('1Min',
                                                               how='sum')
            in_data['volume'].fillna(value=0, inplace=True)
            data = pd.concat(