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

Method step

tf2.0/mlp_trader.py:162–188  ·  view source on GitHub ↗
(self, action)

Source from the content-addressed store, hash-verified

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

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