kh-kim / stock_market_reinforcement_learning

This project provides a stock market environment using OpenGym with Deep Q-learning and Policy Gradient.
791 stars 321 forks source link

IndexError: list index out of range #10

Open david200340105 opened 6 years ago

david200340105 commented 6 years ago
(tensorflow) linyikuandeAir:stock_market_reinforcement_learning KUAN$ python market_pg.py ./kospi_10.csv pg.h5
Using TensorFlow backend.
[Errno 2] No such file or directory: './data/./005930.csv'
[Errno 2] No such file or directory: './data/./012330.csv'
[Errno 2] No such file or directory: './data/./000660.csv'
[Errno 2] No such file or directory: './data/./005380.csv'
[Errno 2] No such file or directory: './data/./015760.csv'
[Errno 2] No such file or directory: './data/./028260.csv'
[Errno 2] No such file or directory: './data/./032830.csv'
[Errno 2] No such file or directory: './data/./005935.csv'
[Errno 2] No such file or directory: './data/./090430.csv'
[Errno 2] No such file or directory: './data/./035420.csv'
Traceback (most recent call last):
  File "market_pg.py", line 147, in <module>
    env = MarketEnv(dir_path = "./data/", target_codes = codeMap.keys(), input_codes = [], start_date = "2010-08-25", end_date = "2015-08-25", sudden_death = -1.0)
  File "/Users/KUAN/Desktop/cse/hw/what/stock_market_reinforcement_learning/market_env.py", line 72, in __init__
    self.reset()
  File "/anaconda/envs/tensorflow/lib/python3.5/site-packages/gym/core.py", line 104, in reset
    return self._reset()
  File "/Users/KUAN/Desktop/cse/hw/what/stock_market_reinforcement_learning/market_env.py", line 131, in _reset
    self.targetCode = self.targetCodes[int(random() * len(self.targetCodes))]
IndexError: list index out of range

I use the python3 to run the code, but I have some problem, please help me! thx.

fi000 commented 6 years ago

Hi David, have you solved this problem (python 3.5.3)? I have similar problem but a bit different! Kim have you any suggestion? Sorry for this stupid question!

python market_pg.py ./kospi_10.csv pg.h5 Using TensorFlow backend. [Errno 2] No such file or directory: 'C:/Users/fi/Desktop/ll/code/stock_market_reinforcement_learning-master/stock_market_reinforcement_learning-master/data/./028260.csv' [Errno 2] No such file or directory: 'C:/Users/fi/Desktop/ll/code/stock_market_reinforcement_learning-master/stock_market_reinforcement_learning-master/data/./005930.csv' [Errno 2] No such file or directory: 'C:/Users/fi/Desktop/ll/code/stock_market_reinforcement_learning-master/stock_market_reinforcement_learning-master/data/./035420.csv' [Errno 2] No such file or directory: 'C:/Users/fi/Desktop/ll/code/stock_market_reinforcement_learning-master/stock_market_reinforcement_learning-master/data/./012330.csv' [Errno 2] No such file or directory: 'C:/Users/fi/Desktop/ll /code/stock_market_reinforcement_learning-master/stock_market_reinforcement_learning-master/data/./000660.csv' [Errno 2] No such file or directory: 'C:/Users/fiDesktop/ll/code/stock_market_reinforcement_learning-master/stock_market_reinforcement_learning-master/data/./005380.csv' [Errno 2] No such file or directory: 'C:/Users/fi/Desktop/ll/code/stock_market_reinforcement_learning-master/stock_market_reinforcement_learning-master/data/./090430.csv' [Errno 2] No such file or directory: 'C:/Users/fi/Desktop/ll/code/stock_market_reinforcement_learning-master/stock_market_reinforcement_learning-master/data/./015760.csv' [Errno 2] No such file or directory: 'C:/Users/fi/Desktop/ll/code/stock_market_reinforcement_learning-master/stock_market_reinforcement_learning-master/data/./032830.csv' [Errno 2] No such file or directory: 'C:/Users/fi/Desktop/ll/code/stock_market_reinforcement_learning-master/stock_market_reinforcement_learning-master/data/./005935.csv' WARN: gym.spaces.Box autodetected dtype as <class 'numpy.float32'>. Please provide explicit dtype. Traceback (most recent call last): File "market_pg.py", line 147, in env = MarketEnv(dir_path = "C:/Users/fi/Desktop/ll/code/stock_market_reinforcement_learning-master/stock_market_reinforcement_learning-master/data/", target_codes = codeMap.keys(), input_codes = [], start_date = "2010-08-25", end_date = "2015-08-25", sudden_death = -1.0) File "C:\Users\fi\Desktop\ll\code\stock_market_reinforcement_learning-master\market_env.py", line 72, in init self.reset() File "C:\Users\fi\Anaconda30\envs\tensorflow\lib\site-packages\gym\core.py", line 70, in reset raise NotImplementedError NotImplementedError

fi000 commented 6 years ago

???

jorddenn commented 6 years ago

@fi000 The problem you're having is because line 72 should read "self._reset()" not "self.reset()". "self.reset()" is the abstract function that needs to be implemented and it is, as "self._reset()" but the line calling it is not correct. Once you do this you will get the error that @david200340105 got, the list index out of range error. This I haven't been able to fix yet, I'll report back if I can.

Also the error of "No such directory" is because the data is in a folder called "sample_data" and the program looks for it to be in the "data" folder. Simply change the name or create a new folder to fix it

jeffreyely commented 6 years ago

There's so many changes from Keras 1 to 2 that I spent 2 hours trying to make it work. For one thing "border_mode = valid " has changed to "padding = same". "Convolution2D" needs to be changed to "Conv2D". There's a problem with the kernel_size needing to be changed to stride. So many changes I couldn't even figure out how to make it work with Keras 2.. Sooooo

I just did this:

pip install keras==1.2.2 (I'll change it back if I want later)

As Jordenn said: "self._reset()" not "self.reset()"

Because of the:

"[Errno 2] No such file or directory: './data/./005930.csv' [Errno 2] No such file or directory: './data/./012330.csv' [Errno 2] No such file or directory: './data/./000660.csv' [Errno 2] No such file or directory: './data/./005380.csv' [Errno 2] No such file or directory: './data/./015760.csv' [Errno 2] No such file or directory: './data/./028260.csv' [Errno 2] No such file or directory: './data/./032830.csv' [Errno 2] No such file or directory: './data/./005935.csv' [Errno 2] No such file or directory: './data/./090430.csv' [Errno 2] No such file or directory: './data/./035420.csv'"

Rename "sample_data" folder to "data"

"border_mode = valid" change to "border_mode = same"

Change "env.reset()" to "env._reset()"

Change "self.env.step" to "self._env.step"

And it's Aliiiiiiiiive xD

Although I need to change some stuff to make it actually useful in real life trading. But good job to the kh-kim for the effort. I really appreciate it because messing around with the code in general helped me learn a lot about Python and Keras. :)

jeffreyely commented 6 years ago

Something's a little strange tough... The pg model trains fine but the dq model says:

2018-03-28 02:28:02.607022: I tensorflow/core/platform/cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.2 AVX AVX2 FMA Killed: 9

And it's a little cryptic... I don't know what it means. Who did it kill? For all I know, I set off a bomb in another universe and it's like "Mission accomplished. Killed 9" lmao

stevexxs commented 5 years ago

@jeffreyely

Could you please tell me the reason of modify by this ?

"border_mode = valid" change to "border_mode = same"

have you succeed to build by keras 2 now ?

Thanks !