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