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