MCPcopy Create free account
hub / github.com/lazyprogrammer/machine_learning_examples / step

Method step

pytorch/rl_trader.py:199–225  ·  view source on GitHub ↗
(self, action)

Source from the content-addressed store, hash-verified

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):

Callers 4

get_scalerFunction · 0.45
train_one_stepFunction · 0.45
play_one_episodeFunction · 0.45
full_gdFunction · 0.45

Calls 3

_get_valMethod · 0.95
_tradeMethod · 0.95
_get_obsMethod · 0.95

Tested by

no test coverage detected