(self, action)
| 197 | |
| 198 | |
| 199 | def step(self, action): |
| 200 | assert action in self.action_space |
| 201 | |
| 202 | # get current value before performing the action |
| 203 | prev_val = self._get_val() |
| 204 | |
| 205 | # update price, i.e. go to the next day |
| 206 | self.cur_step += 1 |
| 207 | self.stock_price = self.stock_price_history[self.cur_step] |
| 208 | |
| 209 | # perform the trade |
| 210 | self._trade(action) |
| 211 | |
| 212 | # get the new value after taking the action |
| 213 | cur_val = self._get_val() |
| 214 | |
| 215 | # reward is the increase in porfolio value |
| 216 | reward = cur_val - prev_val |
| 217 | |
| 218 | # done if we have run out of data |
| 219 | done = self.cur_step == self.n_step - 1 |
| 220 | |
| 221 | # store the current value of the portfolio here |
| 222 | info = {'cur_val': cur_val} |
| 223 | |
| 224 | # conform to the Gym API |
| 225 | return self._get_obs(), reward, done, info |
| 226 | |
| 227 | |
| 228 | def _get_obs(self): |
no test coverage detected