Be kind, I'm new to TensorFlow. I have found a project that trains a Policy Gradient agent to trade the stock market, trained on only the daily Close prices. And I'm interested in making it train on the Open, High, Low, and Volume features as well, so I'm attempting to add them in to the existing code. I've stripped away most of the project to leave only what's necessary for diagnosis.
You can find my Colab notebook here. And I have done my best to comment each section to make it easier to browse, and where I THINK the issues are, but I need someone to show me where and why.
I'm currently getting the error:
ValueError: Cannot feed value of shape (30, 5) for Tensor 'Placeholder:0', which has shape '(?, 30)'
...which makes sense because the self.X = tf.compat.v1.placeholder(tf.float32, (None, self.state_size))
is designed for the only feature (Close), but I'm trying to add in the other features into the state as well. The state_size
is the window_size
of 30
(to look back 30 rows during training). And I'm trying to change the state to include the added features. So I try to change the placeholder to self.state_size,5
, but then I get the error:
ValueError: Cannot feed value of shape (35760, 5) for Tensor 'Placeholder:0', which has shape '(30, 5)'
...which I'm a little unclear about, but I don't think that's the issue. I know I'm trying to feed the tensor data in a shape that it's not expecting, but I don't know how to adapt this on my own. (I think) What I'm looking to do is add in those extra features into the get_state
function so that each row is 1 window_size, and each column represents the features. Then the training should take place over the iterations.
I've found similar questions/answers at the below links to help someone who knows more about this than me out. Most of them talk about reshaping the data at the placeholder, which I thought I had tried, but now I've just outrun my knowledge. Thanks in advance.
UPDATE
Boy I'm sure struggling to figure this out on my own, but I appreciate the guidance thus far and I think I'm getting close, I just have limited knowledge of what to change. Given the answer below, I understand that my window_size/number of rows can change depending on what the window_size/lookback value is, so that would be the None part of my the placeholder, and in this particular case, I WOULD know the number of features (in this case 5) ahead of time so setting that as a static number (5) would suffice. So I'm trying to not have individual placeholders for each new feature I want to add.
So trying to use the new placeholder self.X = tf.compat.v1.placeholder(tf.float32, (None,5))
now the error I'm getting is:
InvalidArgumentError: Incompatible shapes: [3270,3] vs. [98100,3]
[[{{node sub}}]]
During handling of the above exception, another exception occurred:
InvalidArgumentError Traceback (most recent call last)
<ipython-input-4-78f4afe280e1> in <module>()
22 skip = skip)
23
---> 24 agent.train(iterations = 500, checkpoint = 10, initial_money = initial_money)
<ipython-input-3-1788840ff10e> in train(self, iterations, checkpoint, initial_money)
135 cost, _ = self.sess.run([self.cost, self.optimizer], feed_dict={self.X:np.vstack(ep_history[:,0]),
136 self.REWARDS:ep_history[:,2],
--> 137 self.ACTIONS:ep_history[:,1]})
138
139
...so I get the printed output of the ep_history
array to check its shape, which has a starting shape of :
array([[0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0.],
...
[0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0.]]) # which is the current state (5x30)
0 10000 # which is the action and reward/starting_money
array([[ 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00,
0.000000e+00],
[ 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00,
0.000000e+00],
....
[ 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00,
0.000000e+00],
[ 6.000060e-01, 1.669999e+00, 4.899980e-01, 2.309998e+00,
-2.135710e+07]])] # which is the NEXT state
...which acts as the state (5 columns of features and 30 rows of window_size), action (0), starting_money (10,000), and next_state (again 5 x 30 with the next/future row of the dataset).
So what seems to be the issue now? Is it the array? I apologize for the lengthy code, but I want to be thorough for those helping me and to show that I'm actually trying to understand the logic behind the fix so I can apply it later. Any further input? Would it be something to do with get_state
function? (I've added a couple of extra comments to the colab book as I work through this). Thanks a lot.