Beispiel #1
0
def load_from_yaml(date: Union[str, pd.Timestamp],
                   ports: set = None) -> Portfolio:
    """Загружает информацию о портфеле из yaml-файлов."""
    usd = indexes.usd(pd.Timestamp(date))
    usd = usd.iloc[-1]
    cash = 0
    value = 0

    positions = collections.Counter()
    name = list()
    for path in sorted(config.PORT_PATH.glob("*.yaml")):
        if ports is None or path.name in ports:
            name.append(path.stem)
            with path.open() as port:
                port = yaml.safe_load(port)
                positions.update(port.pop("positions"))
                cash += port.get("USD", 0) * usd + port.get("RUR", 0)
                value += port.get("value", 0)

            if value:
                LOGGER.info(f"Проверка стоимости: {path}")
                try:
                    Portfolio([path.stem], date, cash, positions, value)
                except config.POptimizerError as err:
                    LOGGER.error(err)
                    continue
                LOGGER.info("OK")

    if not value:
        value = None

    return Portfolio(name, date, cash, positions, value)
Beispiel #2
0
def test_usd(date, usd):
    """Проверка, что первые данные обрезаны, а последние соответствуют аргументу."""
    date = pd.Timestamp(date)
    df = indexes.usd(date)

    assert isinstance(df, pd.Series)
    assert df.index.is_monotonic_increasing and df.name == col.CLOSE

    assert df.index[0] >= bootstrap.START_DATE
    assert df.index[-1] == pd.Timestamp(date)

    assert df.loc[date] == pytest.approx(usd)
Beispiel #3
0
 def __init__(self, ticker: str, params: DataParams):
     """Сохраняет данные о курсе."""
     super().__init__(ticker, params)
     usd = indexes.usd(params.end)
     price = params.price(ticker)
     usd = usd.reindex(
         price.index,
         method="ffill",
         axis=0,
     )
     self.usd = torch.tensor(usd.values, dtype=torch.float, device=DEVICE)
     self.history_days = params.history_days