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

Using btfeeds and saving/loading trained models #40

Closed kazi308 closed 6 years ago

kazi308 commented 6 years ago

Hi @Kismuz,

Great project! I would like to know if its possible to use the normal btfeeds for backtesting and live feeds within the gym environment?

Is it possible to save and load trained models?

Also is it possible to modify the order size on the fly eg.

            self.buyvalue = round(((self.broker.getvalue() / self.data0.close[0]) * 0.9), 1)
            self.order = self.buy(self.data,
                                  exectype=bt.Order.Limit, 
                                  size=self.buyvalue,
                                  price=self.data0.close[0],
                                  valid=datetime.now() + timedelta(minutes=10))

Thank you in advance,

Kind regards

Kismuz commented 6 years ago

@kazi308 ,

if its possible to use the normal btfeeds

Can you specify what you mean by 'normal'?

live feeds

not yet implemented; See also: #32, #13, #12

save and load trained models?

btgym relies on tensorflow training ecosystem; trained modesl are saved as checkpoints and get restored if any model get found in specified directory; at high level, when starting training use:

launcher = Launcher(
    ....
    purge_previous=1,  # ask y/n to override previously saved model and logs
    ....
)

to set desired treatment to models found. See also: tf.train.MonitoredTrainingSession

modify the order size on the fly

yes, you can define any order execution logic by subclasing any BTgymStrategy and overriding pre_next(), next(), notify_order() methods etc.; utilise any available backtrader tools and methods to shape environment logic to your needs.

kazi308 commented 6 years ago

@Kismuz thanks for the quick response.

I mean PandasData and the feeds located under bt.feeds. apologies maybe Ive missed something, the btgym examples Ive seen so far use CSV.

Can you specify what you mean by 'normal'?>

not yet implemented; See also: #32, #13, #12

save and load trained models? btgym relies on tensorflow training ecosystem; trained modesl are saved as checkpoints and get restored if any model get found in specified directory; at high level, when starting training use:

launcher = Launcher( .... purge_previous=1, # ask y/n to override previously saved model and logs .... ) to set desired treatment to models found. See also: tf.train.MonitoredTrainingSession

modify the order size on the fly yes, you can define any order execution logic by subclasing any BTgymStrategy and overriding pre_next(), next(), notify_order() methods etc.; utilise any available backtrader tools and methods to shape environment logic to your needs.

Thank you very much for that information, keep up the awesome work!

Kismuz commented 6 years ago

@kazi308 , all data classes internally uses pandas dataframes to perform data manipulations: CSV is just convenient source format. When CSV file is loaded to dataset instance it gets parsed and converted to pandas frame and stored as attribute Dataset.data.

CSV[source data]-->pandas[for efficient sampling]-->bt.feeds

So it is straightforward to modify input method do directly load pandas; as I can remember @djoffrey has done such mods; see #25

Refer to documentation https://kismuz.github.io/btgym/btgym.datafeed.html#btgym-datafeed-package for details.