(self, action)
| 179 | |
| 180 | |
| 181 | def step(self, action): |
| 182 | assert action in self.action_space |
| 183 | |
| 184 | # get current value before performing the action |
| 185 | prev_val = self._get_val() |
| 186 | |
| 187 | # perform the trade |
| 188 | self._trade(action) |
| 189 | |
| 190 | # update price, i.e. go to the next day |
| 191 | self.cur_step += 1 |
| 192 | self.stock_price = self.stock_price_history[self.cur_step] |
| 193 | |
| 194 | # get the new value after taking the action |
| 195 | cur_val = self._get_val() |
| 196 | |
| 197 | # reward is the increase in porfolio value |
| 198 | reward = cur_val - prev_val |
| 199 | |
| 200 | # done if we have run out of data |
| 201 | done = self.cur_step == self.n_step - 1 |
| 202 | |
| 203 | # store the current value of the portfolio here |
| 204 | info = {'cur_val': cur_val} |
| 205 | |
| 206 | # conform to the Gym API |
| 207 | return self._get_obs(), reward, done, info |
| 208 | |
| 209 | |
| 210 | def _get_obs(self): |
no test coverage detected