def test_cpi(date, cpi): """Проверка, что первые данные обрезаны и их нужное количество.""" df = crop.cpi() assert isinstance(df, pd.Series) assert df.index.is_monotonic_increasing today = datetime.date.today() start = bootstrap.get_start_date() months = (today.year - start.year) * 12 months += today.month - start.month assert months - 1 <= len(df) <= months assert df.index[0] >= bootstrap.get_start_date() assert df.loc[date] == pytest.approx(cpi)
def index() -> pd.Series: """Загрузка данных по индексу полной доходности с учетом российских налогов - MCFTRR.""" table_name = outer.TableName(outer.INDEX, outer.INDEX) requests_handler = bootstrap.get_handler() df = requests_handler.get_df(table_name) start_date = bootstrap.get_start_date() return df.loc[start_date:, col.CLOSE] # type: ignore
def cpi() -> pd.Series: """Потребительская инфляция.""" table_name = outer.TableName(outer.CPI, outer.CPI) requests_handler = bootstrap.get_handler() df = requests_handler.get_df(table_name) start_date = bootstrap.get_start_date() return df.loc[start_date:, col.CPI] # type: ignore
def dividends(ticker: str, force_update: bool = False) -> pd.DataFrame: """Дивиденды для данного тикера.""" table_name = outer.TableName(outer.DIVIDENDS, ticker) requests_handler = bootstrap.get_handler() df = requests_handler.get_df(table_name, force_update) start_date = bootstrap.get_start_date() return df.loc[start_date:] # type: ignore
def dohod(ticker: str) -> pd.DataFrame: """Информация по дивидендам с dohod.ru.""" table_name = outer.TableName(outer.DOHOD, ticker) requests_handler = bootstrap.get_handler() df = requests_handler.get_df(table_name) start_date = bootstrap.get_start_date() return df.loc[start_date:] # type: ignore
def test_index(date, index): """Проверка, что первые данные обрезаны.""" df = crop.index() assert isinstance(df, pd.Series) assert df.index.is_monotonic_increasing assert df.index[0] >= bootstrap.get_start_date() assert df.name == col.CLOSE assert df.loc[date] == pytest.approx(index)
def test_dohod(ticker, div_data): """Проверка, что первые дивиденды после даты обрезки.""" df = crop.dohod(ticker) assert isinstance(df, pd.DataFrame) assert df.index.is_monotonic_increasing assert df.index[0] >= bootstrap.get_start_date() assert df.columns.tolist() == [ticker] date, div = div_data assert df.loc[date, ticker] == div
def test_quotes(tickers, pos, loc, quote): """Проверка, что первые данные обрезаны.""" dfs = crop.quotes(tickers) assert len(dfs) == len(tickers) df = dfs[pos] assert df.index.is_monotonic_increasing assert df.index[0] >= bootstrap.get_start_date() columns = [col.OPEN, col.CLOSE, col.HIGH, col.LOW, col.TURNOVER] assert df.columns.tolist() == columns assert df.loc[loc] == pytest.approx(quote)
def quotes(tickers: Tuple[str, ...]) -> List[pd.DataFrame]: """Информация о котировках для заданных тикеров. :param tickers: Перечень тикеров, для которых нужна информация. :return: Список с котировками. """ group: outer.GroupName = outer.QUOTES requests_handler = bootstrap.get_handler() dfs = requests_handler.get_dfs(group, tickers) start_date = bootstrap.get_start_date() return [df.loc[start_date:] for df in dfs] # type: ignore