MCPcopy Index your code
hub / github.com/lazyprogrammer/machine_learning_examples / step

Method step

tf2.0/rl_trader.py:174–200  ·  view source on GitHub ↗
(self, action)

Source from the content-addressed store, hash-verified

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

Callers 2

get_scalerFunction · 0.45
play_one_episodeFunction · 0.45

Calls 3

_get_valMethod · 0.95
_tradeMethod · 0.95
_get_obsMethod · 0.95

Tested by

no test coverage detected