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

Method step

tf2.0/keras_trader.py:181–207  ·  view source on GitHub ↗
(self, action)

Source from the content-addressed store, hash-verified

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