コード例 #1
0
ファイル: TradingEnv.py プロジェクト: yhzhang1/RLTrader-my
    def _next_observation(self):
        self.current_ohlcv = self.data_provider.next_ohlcv()
        self.timestamps.append(
            pd.to_datetime(self.current_ohlcv.Date.item(), unit='s'))
        self.observations = self.observations.append(self.current_ohlcv,
                                                     ignore_index=True)

        if self.stationarize_obs:
            observations = log_and_difference(self.observations, inplace=False)
        else:
            observations = self.observations

        if self.normalize_obs:
            observations = max_min_normalize(observations)

        obs = observations.values[-1]

        if self.stationarize_obs:
            scaled_history = log_and_difference(self.account_history,
                                                inplace=False)
        else:
            scaled_history = self.account_history

        if self.normalize_obs:
            scaled_history = max_min_normalize(scaled_history, inplace=False)

        obs = np.insert(obs, len(obs), scaled_history.values[-1], axis=0)

        obs = np.reshape(obs.astype('float16'), self.obs_shape)
        obs[np.bitwise_not(np.isfinite(obs))] = 0

        return obs
コード例 #2
0
    def _next_observation(self):
        self.current_ohlcv = self.data_provider.next_ohlcv()
        self.timestamps.append(pd.to_datetime(
            self.current_ohlcv.Date.item(), unit='s'))
        self.observations = self.observations.append(
            self.current_ohlcv, ignore_index=True)

        obs = log_values(
            self.observations.loc[:, self.feature_columns]).values[-1]

        obs_diff = log_and_difference(self.observations, inplace=False)
        obs = np.insert(obs, len(
            obs), obs_diff.loc[:, self.feature_columns].values[-1], axis=0)

        history = self.account_history
        history["balance_ratio"] = history["balance"] / \
            history["current_net_worth"]

        scaled_history = history.loc[:, [
            "balance", "asset_held", "current_net_worth", "balance_ratio"]]

        obs = np.insert(obs, len(obs), scaled_history.values[-1], axis=0)

        obs = np.reshape(obs.astype('float16'), self.obs_shape)
        obs[np.bitwise_not(np.isfinite(obs))] = 0

        return obs
コード例 #3
0
    def _next_observation(self):
        self.current_ohlcv = self.data_provider.next_ohlcv()
        self.observations = self.observations.append(self.current_ohlcv,
                                                     ignore_index=True)

        if self.enable_stationarization:
            observations = log_and_difference(self.observations)
        else:
            observations = self.observations

        observations = max_min_normalize(observations)

        obs = observations.values[-1]

        scaled_history = max_min_normalize(self.account_history)

        obs = np.insert(obs, len(obs), scaled_history.values[-1], axis=0)

        obs = np.reshape(obs.astype('float16'), self.obs_shape)
        obs[np.bitwise_not(np.isfinite(obs))] = 0

        return obs