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