Kismuz / btgym

Scalable, event-driven, deep-learning-friendly backtesting library
https://kismuz.github.io/btgym/
GNU Lesser General Public License v3.0
985 stars 260 forks source link

Issue while running code #29

Closed Nicolas99-9 closed 6 years ago

Nicolas99-9 commented 6 years ago

I have two issues while running the code, first one is when I try to run a basic environment. After performing the first action, I receive the following error : ValueError: too many values to unpack (expected 4) and when I print the output of env.step(action) : "No key received:Server Control mode: received <{'action': 'hold'}>"

from btgym import BTgymEnv from policy_gradient import PolicyGradient import numpy as np env = BTgymEnv(filename='../examples/data/DAT_ASCII_EURUSD_M1_2016.csv',) done = False while not done: action = env.action_space.sample() obs, reward, done, info = env.step(action) print(reward)

Second issue is related to the rewards, the are equal to 0 whatever the actions I choose.

Kismuz commented 6 years ago

@Nicolas99-9 ,

Due to Gym API convention it is essential to call env.reset() before taking steps. Try this way:

from btgym import BTgymEnv

env = BTgymEnv(filename='../examples/data/DAT_ASCII_EURUSD_M1_2016.csv',) 

done = False 

init_obs = env.reset()

while not done: 
    action = env.action_space.sample() 
    obs, reward, done, info = env.step(action) 
    print('action: {}\nreward: {}\ninfo: {}'.format(action, reward, info))

env.close()

Anyway error message you receive trying to run uninitialised environment should be more informative. Need to sort it out.

As for zero-reward, see related question: #27 . Pay attention to broker message part of info output when running script above - you'll see 'ORDER FAILED with status: Margin', cause no sufficient cash has been set.