Love the work you've posted! Super thorough.
I'm trying to implement the Trading with RL notebook into Google Colab but running into an issue. I will document my moves here for reproducibility.
Basically, I copied, cell for cell, the notebook from this repository into a Google Colab notebook.
First, you have to install backtrader into the environment. I did this by putting this at the very beginning of the imports:
try:
import backtrader as bt
except:
print('Backtrader not installed yet. Installing now...')
!pip install backtrader
print('Backtrader installed.')
print('Restart and Run All now.')
exit()
This way, it'll prompt the user to Restart and Run All once Backtrader is installed.
Second issue I figured out was to make sure this notebook is being run with eager execution disabled, so I added:
from tensorflow.compat import v1
v1.disable_eager_execution()
...to the imports at the top as well.
Now my issue is this error:
TypeError Traceback (most recent call last)
<ipython-input-21-e8262df5188b> in <module>()
38
39 if e and (e+1) % agent.save_interval == 0:
---> 40 agent.save()
41
42 elapsed_time = time.time() - start_time
<ipython-input-20-21179c258b19> in save(self)
149 self.predict_model.save("%s_predict.h5" % fullname)
150 # can't save / load train model due to custom loss
--> 151 pickle.dump(self, open("%s.p" % fullname, "wb"))
152
153 def load(filename, memory=True):
TypeError: can't pickle _thread.RLock objects
This happens when the cell with this at the beginning is run (i.e. the cell after the class REINFORCE_Agent(Agent):
cell) :
N_EPISODES = 2000
ticks_per_episode = 1256
nstocks = 1
lag = 1
Googling that error, I found this answer that might help? But hoping to get some help troubleshooting this one? Would greatly appreciate it as I can't wait to get this working online.
Thanks!