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

Method step

rl/linear_rl_trader.py:168–194  ·  view source on GitHub ↗
(self, action)

Source from the content-addressed store, hash-verified

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