| 156 | - 2 = buy |
| 157 | """ |
| 158 | def __init__(self, data, initial_investment=20000): |
| 159 | # data |
| 160 | self.stock_price_history = data |
| 161 | self.n_step, self.n_stock = self.stock_price_history.shape |
| 162 | |
| 163 | # instance attributes |
| 164 | self.initial_investment = initial_investment |
| 165 | self.cur_step = None |
| 166 | self.stock_owned = None |
| 167 | self.stock_price = None |
| 168 | self.cash_in_hand = None |
| 169 | |
| 170 | self.action_space = np.arange(3**self.n_stock) |
| 171 | |
| 172 | # action permutations |
| 173 | # returns a nested list with elements like: |
| 174 | # [0,0,0] |
| 175 | # [0,0,1] |
| 176 | # [0,0,2] |
| 177 | # [0,1,0] |
| 178 | # [0,1,1] |
| 179 | # etc. |
| 180 | # 0 = sell |
| 181 | # 1 = hold |
| 182 | # 2 = buy |
| 183 | self.action_list = list(map(list, itertools.product([0, 1, 2], repeat=self.n_stock))) |
| 184 | |
| 185 | # calculate size of state |
| 186 | self.state_dim = self.n_stock * 2 + 1 |
| 187 | |
| 188 | self.reset() |
| 189 | |
| 190 | |
| 191 | def reset(self): |