Example #1
0
def test_quotes_download_update():
    mng = moex.Quotes(db="test")
    # noinspection PyProtectedMember
    data = mng._download("MSTT", last_index=pd.Timestamp("2019-09-13"))
    assert len(data)
    assert data[0][CLOSE] == 88.7
    assert data[0][TURNOVER] == 1106728
Example #2
0
def test_quotes_no_data():
    """Некоторые бумаги не имеют котировок."""
    mng = moex.Quotes(db="test")
    for ticker in ("KSGR", "KMTZ", "TRFM"):
        df = mng[ticker]
        assert isinstance(df, pd.DataFrame)
        assert df.empty
Example #3
0
def test_not_unique():
    """Некоторые бумаги со старой историей торговались одновременно под несколькими тикерами."""
    mng = moex.Quotes(db="test")
    for ticker in ("PRMB", "OGKB"):
        df = mng[ticker]
        assert isinstance(df, pd.DataFrame)
        assert df.index.is_unique
        assert df.index.is_monotonic_increasing
Example #4
0
async def test_not_unique():
    """Некоторые бумаги со старой историей торговались одновременно под несколькими тикерами."""
    mgr = moex.Quotes(("PRMB", "OGKB"))
    for ticker in ("PRMB", "OGKB"):
        await mgr.create(ticker)
        await mgr.update(ticker)
    dfs = await mgr.get()
    for df in dfs:
        assert isinstance(df, pd.DataFrame)
        assert df.index.is_unique
        assert df.index.is_monotonic_increasing
Example #5
0
async def test_no_data():
    """Некоторые бумаги не имеют котировок."""
    mgr = moex.Quotes(("KSGR", "KMTZ", "TRFM"))
    for ticker in ("KSGR", "KMTZ", "TRFM"):
        await mgr.create(ticker)
        await mgr.update(ticker)
    dfs = await mgr.get()
    for df in dfs:
        assert isinstance(df, pd.DataFrame)
        assert df.empty
        assert list(df.columns) == [CLOSE, TURNOVER]
Example #6
0
def test_quotes_create():
    mng = moex.Quotes(db="test")
    df = mng["MSTT"]

    assert isinstance(df, pd.DataFrame)
    assert df.shape[0] > 1000
    assert df.index[0] == pd.to_datetime("2010-11-03")
    assert df.loc["2013-03-27", CLOSE] == pytest.approx(136.3)
    assert df.loc["2014-06-09", CLOSE] == pytest.approx(110.48)
    assert df.loc["2018-09-07", CLOSE] == pytest.approx(92.0)
    assert df.loc["2018-03-09", CLOSE] == 148.8
    assert df.loc["2018-03-09", TURNOVER] == 439722
Example #7
0
def test_quotes_late_reg_number():
    """Под тикером IRAO обращалось две бумаги с разными регистрационными номерами.

    Это вызывало скачек котировок в сто раз.
    """
    mng = moex.Quotes(db="test")
    df = mng["IRAO"]

    assert isinstance(df, pd.DataFrame)
    assert df.shape[0] > 1270
    assert df.index[0] == pd.to_datetime("2015-01-20")
    assert df.loc["2015-01-20", CLOSE] == pytest.approx(0.7641)
    assert df.loc["2015-01-20", TURNOVER] == pytest.approx(55127750.3)
    assert df.loc["2020-02-03", CLOSE] == pytest.approx(5.8285)
    assert df.loc["2020-02-03", TURNOVER] == pytest.approx(1156252597.5)
Example #8
0
def test_no_reg_number():
    mng = moex.Quotes(db="test")
    with pytest.raises(POptimizerError) as error:
        # noinspection PyStatementEffect
        mng["YNDX"]
    assert "YNDX - акция без регистрационного номера" == str(error.value)
Example #9
0
def test_quotes_find_aliases():
    mng = moex.Quotes(db="test")
    # noinspection PyProtectedMember
    tickers, date = mng._find_aliases("UPRO")
    assert set(tickers) == {"UPRO", "EONR", "OGK4"}
    assert date == pd.Timestamp("2007-04-19")
Example #10
0
async def test_quotes_start_of_download_update():
    mng = moex.Quotes(("MSTT", ))
    await mng.get()
    # noinspection PyProtectedMember
    update = await mng._download_update("MSTT")
    assert update.index[0] >= pd.Timestamp("2018-12-10")