Ejemplo n.º 1
0
    def make_env():
        run_name = "yt1"
        saves_path = AppConfig.SAVES_DIR / f"simple-{run_name}"
        saves_path.mkdir(parents=True, exist_ok=True)

        data_path = pathlib.Path(AppConfig.STOCKS)
        val_path = pathlib.Path(AppConfig.VAL_STOCKS)
        year = 2016

        if year is not None or data_path.is_file():
            if year is not None:
                print('load stock data...')
                stock_data = BarData.load_year_data(year)
            else:
                stock_data = {"YNDX": BarData.load_relative(data_path)}
            env = MinuteBarEnv(stock_data,
                               bars_count=AppConfig.BARS_COUNT,
                               volumes=True)
            env_tst = MinuteBarEnv(stock_data,
                                   bars_count=AppConfig.BARS_COUNT,
                                   volumes=True)
        elif data_path.is_dir():
            env = MinuteBarEnv.from_dir(data_path,
                                        bars_count=AppConfig.BARS_COUNT)
            env_tst = MinuteBarEnv.from_dir(data_path,
                                            bars_count=AppConfig.BARS_COUNT)
        else:
            raise RuntimeError("No data to train on")

        env = gym.wrappers.TimeLimit(env, max_episode_steps=1000)
        val_data = {"YNDX": BarData.load_relative(val_path)}
        env_val = MinuteBarEnv(val_data,
                               bars_count=AppConfig.BARS_COUNT,
                               volumes=True)
        return env, env_val, env_tst
Ejemplo n.º 2
0
 def from_dir(cls, data_dir, **kwargs):
     prices = {
         file: BarData.load_relative(file)
         for file in BarData.price_files(data_dir)
     }
     return MinuteBarEnv(prices, **kwargs)