miroblog / tf_deep_rl_trader

Trading Environment(OpenAI Gym) + PPO(TensorForce)
239 stars 64 forks source link

render() got an unexpected keyword argument 'close' #1

Open greg2paris opened 5 years ago

greg2paris commented 5 years ago

first I want to thank you for your great share. It very rare to find trading reinforcement learning system with ppo. I have an error when I run this code. SInce i dont have talib installed i replaced this line : import talib by this import ta as talib

I have then an error when i launch the code : render() got an unexpected keyword argument 'close' from core.py line 164 and 203 and closer line 67

how can i fix it?

Thank you, Greg

miroblog commented 5 years ago

sorry for the late response,
try installing talib from
https://www.lfd.uci.edu/~gohlke/pythonlibs/#ta-lib

windowshopr commented 5 years ago

I followed the install instructions mentioned on that page as well, and I receive the same error. Windows 10 64-bit. TA-Lib did install successfully. Any further suggestions? Would love to get this working.

This is the full error I receive on mine:

python ppo_trader.py Traceback (most recent call last): File "ppo_trader.py", line 134, in main() File "ppo_trader.py", line 59, in main environment = create_btc_env(window_size=TIMESTEP, path=PATH_TRAIN, train=True) File "C:\Users...\tf_deep_rl_trader-master\env\gymWrapper.py", line 239, in create_btc_env raw_env = OhlcvEnv(window_size=window_size, path=path, train=train) File "C:\Users...\tf_deep_rl_trader-master\env\TFTraderEnv.py", line 43, in init self.observation_space = spaces.Box(low=-np.inf, high=np.inf, shape=self.shape, dtype=np.float32) TypeError: init() got an unexpected keyword argument 'dtype' Error in atexit._run_exitfuncs: Traceback (most recent call last): File "C:\Users...\AppData\Local\Programs\Python\Python36\lib\site-packages\gym\utils\closer.py", line 67, in close closeable.close() File "C:\Users...\AppData\Local\Programs\Python\Python36\lib\site-packages\gym\core.py", line 164, in close self.render(close=True) TypeError: render() got an unexpected keyword argument 'close' Exception ignored in: <bound method Env.del of <env.TFTraderEnv.OhlcvEnv object at 0x00000223D69C55C0>> Traceback (most recent call last): File "C:\Users...\AppData\Local\Programs\Python\Python36\lib\site-packages\gym\core.py", line 203, in del self.close() File "C:\Users...\AppData\Local\Programs\Python\Python36\lib\site-packages\gym\core.py", line 164, in close self.render(close=True) TypeError: render() got an unexpected keyword argument 'close'

windowshopr commented 5 years ago

Yeah I can't seem to get this to work. Seems like there's issues with other people having similar issues. I've tried completely uninstalling my Visual Studio 2017, reinstalling 2015, following the install guide as described above, along with others I've found online. Nothing seems to fix this error. Must be something to do with trying to install ta-lib on Windows 64 bit. If there are some other suggestions, I would love to see them. Thanks!

miroblog commented 5 years ago

If installing the "python wrapper for talib" on windows is a problem, try replacing talib functions (talib.MA , talib.RSI ...etc) written purely in numpy or pandas.

windowshopr commented 5 years ago

This is a great idea. When I get some time, I will tweak it to get it working without TA-Lib. I saw in the issues of TA-Lib that people with 64 bit operating systems are having some issues installing it as TA-Lib was first compiled in a 32 bit env? Either way, thanks for the suggestion!

windowshopr commented 5 years ago

Looks like I was able to get it working. In the "process_data.py" file, I used pandas to calculate the moving averages, and then I utilized the "ta" library instead of the "ta-lib" library where applicable.

    def add_ta_features(self):

        self.df['bmidband'] = ta.bollinger_mavg(self.close, n=20)
        self.df['blowband'] = ta.bollinger_hband(self.close, n=20, nbdev=2)
        self.df['bupband'] = ta.bollinger_lband(self.close, n=20, nbdev=2)
        self.df['pctB'] = (self.close - self.df.blowband) / (self.df.bupband - self.df.blowband)
        self.df['rsi14'] = ta.rsi(self.close, n=14)
        self.df['rsi14'] = rsi14

        self.df['macd_diff'] = ta.macd_diff(self.close, n_fast=12, n_slow=26, n_sign=9)
        self.df['macd'] = ta.macd(self.close, n_fast=12, n_slow=26, fillna=False)
        self.df['signal'] = ta.macd_signal(self.close, n_fast=12, n_slow=26, n_sign=9)

        ## addtional info
        self.df['adx'] = ta.adx(self.high, self.low, self.close, n=14)
        self.df['cci'] = ta.cci(self.high, self.low, self.close, n=14)

        ## maximum profit
        #self.df['plus_di'] = ta.PLUS_DI(self.high, self.low, self.close, timeperiod=14)

        ## lower_bound
        self.df['lower_bound'] = self.df['open'] - self.df['low'] + 1

        ## ATR
        self.df['atr'] = ta.atr(self.high, self.low, self.close, n=14)

        ## STOCH momentum
        self.df = ta.stochastic_oscillator_k(self.df)
        self.df = ta.stochastic_oscillator_d(self.df, n=10)

        ## TRIX
        self.df['trix'] = ta.trix(self.close, n=15)
        self.df['trix_signal'] = ta.moving_average(self.df['trix'], n=3)
        self.df['trix_hist'] = self.df['trix'] - self.df['trix_signal']

        ## MFI
        self.df['mfi14'] = ta.money_flow_index(self.high, self.low, self.close, self.volume, n=14)

Then I had to update the "gymWrapper.py" by editing

import gym
from gym import wrappers

...and then just replacing the gym.wrappers instances with just wrappers, and it looks like it's running now. Hopefully this helps someone who stumbles across this! Thanks @miroblog