FinRL
FinRL copied to clipboard
Working copy of FinRL_PaperTrading_Demo.ipynb
Does anyone have a working copy of FinRL_PaperTrading_Demo.ipynb
Could you please specify the error you're experiencing?
I am also facing error while running this jupyter notebook. In Part 2 train the agent, after executing the train function, the following error is displayed :- Alpaca successfully connected
TypeError Traceback (most recent call last)
2 frames
TypeError: tuple indices must be integers or slices, not tuple
The error you've posted, TypeError, is raised when an operation or function is applied to an object of an inappropriate type.
The traceback suggests the issue is happening at the line:
python Copy code agent.states = env.reset()[np.newaxis, :] Given the error and the line it's pointing to, a few possibilities come to mind:
Issue with env.reset(): This method might not be returning a value that can be indexed or isn't returning a numpy array (or something similar). For example, if env.reset() returns None, this line would throw an error.
Usage of np.newaxis: This is generally used with numpy arrays to increase the dimensionality of the existing array, making it effectively a row vector/column vector. It's possible that the output of env.reset() isn't compatible with this numpy operation.
Here's what you can do to debug:
Check the output of env.reset(): Add a debug statement before the problematic line to inspect the output.
python Copy code reset_val = env.reset() print(type(reset_val), reset_val) This will give you the type and value of the returned object. Based on that, you can deduce whether it's something that can be indexed or not.
Ensure Compatibility: If env.reset() isn't returning a numpy array, consider converting it into one. For instance, if it's a list:
python Copy code import numpy as np agent.states = np.array(env.reset())[np.newaxis, :] Environment Definition: Check the definition of the reset method in your environment (env). Make sure it's returning the expected value. It's common for environments in reinforcement learning (like those in Gym) to return an initial state when reset.
By taking these steps, you should be able to pinpoint the source of the error and address it. If the problem persists or the root cause isn't clear, please share more details about the code, especially the definitions of the environment and the reset method.
I did tried to debug it, but that led to another error. env.reset() is returning a tuple of numpy error and a empty disctionary. So to solve it I did the folllowing
x=env.reset()
x=x[0]
agent.states = x[np.newaxis, :]
Above replacements removed the error from here but led to the following error:-
The code where error occured is highlighted:-
Here there are 4 variables to recieve the tuple returned by env.step(). When then I checked the definition of env.step() function, it was returning a tuple of size 4 and hence there should be no issue, but still I got "too many values to unpack error".
I am stuck here, and not able to proceed.
1min interval can only be pulled within 60 days from current date.
If I put end date to 7 september 2023, then it give error that it cnnot send data from withing 15 minutes, since the day is yet to finish.
So I gave start date = 1 september 2023 and end date = 6 september 2023, but I still get the same error.
If I put end date to 7 september 2023, then it give error that it cnnot send data from withing 15 minutes, since the day is yet to finish. So I gave start date = 1 september 2023 and end date = 6 september 2023, but I still get the same error.
Were you able to solve this issue?
See Sivesh Pandey's comments here. That fixes it https://github.com/AI4Finance-Foundation/FinRL/issues/1011