Git Product home page Git Product logo

Comments (6)

Kismuz avatar Kismuz commented on May 28, 2024

@gaitay ,
can you provide more details on settings your are running? Does it happens with one of the examples or your own code and data?

from btgym.

gaitay avatar gaitay commented on May 28, 2024

yes it happens with one of the examples,
when episode finished.

import gym
from gym import spaces
import backtrader as bt
from btgym import BTgymDataset, BTgymBaseStrategy, BTgymEnv

MyCerebro = bt.Cerebro()
MyCerebro.addstrategy(BTgymBaseStrategy,
                      state_shape={'raw_state': spaces.Box(low=0,high=1,shape=(20,4))},
                      skip_frame=5,
                      state_low=None,
                      state_high=None,
                      drawdown_call=50,
                      )

MyCerebro.broker.setcash(100.0)
MyCerebro.broker.setcommission(commission=0.001)
MyCerebro.addsizer(bt.sizers.SizerFix, stake=10)
MyCerebro.addanalyzer(bt.analyzers.DrawDown)

MyDataset = BTgymDataset(filename='../examples/data/DAT_ASCII_EURUSD_M1_2016.csv',
                         start_weekdays=[0, 1, 2, 4],
                         start_00=True,
                         episode_len_days=0,
                         episode_len_hours=23,
                         episode_len_minutes=55,
                         time_gap_days=0,
                         time_gap_hours=5,
                         )

MyEnvironment = BTgymEnv(dataset=MyDataset,
                         engine=MyCerebro,
                         port=5555,
                         verbose=1,
                         )

observation = MyEnvironment.reset()
for t in range(1000):
	MyEnvironment.render()
	print(observation)
	action = MyEnvironment.action_space.sample()
	observation, reward, done, info = MyEnvironment.step(action)
	if done:
	    print("Episode finished after {} timesteps".format(t+1))

from btgym.

tmorgan4 avatar tmorgan4 commented on May 28, 2024

I just spent some time tracking down solutions to both issues.

ValueError: Axis limits cannot be NaN or Inf
This is an issue caused by taking max() of an array full of NaNs and appears to be caused by a recent update of matplotlib. It is in the process of being fixed. For the time being, I changed line 130 in backtrader/plot/scheme.py from self.volume = True to self.volume = False to disable volume plots.

AttributeError: 'FigureCanvasAgg' object has no attribute 'renderer'
This is an easy fix but took quite a bit of time to track down. Open btgym/rendering/plotter.py and add: fig.canvas.draw() before line 76 where rgb_string is called.

I'm new to Github and not familiar with pull requests so could someone else make this change? Andrew has done an amazing job so far and I'd like to contribute anything I can!

from btgym.

Kismuz avatar Kismuz commented on May 28, 2024

@tmorgan4, @gaitay,
thank you for tracking this down. Indeed BTgym was developed to use Matplotlib 2.0.2 and crashes when 2.1 version is installed.

Solution:
The easiest way until ValueError is not fixed is to use matplotlib v/2.0.2
How to do:
It is highly recommended to run BTGym in designated virtual environment.
If you reinstalling btgym from scratch - just do nothing as v.2.0.2 is now specified in package dependencies and should install correct version of Matplotlib.
Else:
downgrade your matplotlib installation (that's where virtual env is handy):

`pip install matplotlib==2.0.2`

Remark to @tmorgan4: I'm a bit paranoid about using fig.canvas.draw() as it potentially can lead to memory leaks. I had very though time fighting that issue when coding it initially. Anyway there is btgym/tests/render_memory_leak_test.ipynb you can try and see if it runs Ok.

from btgym.

gaitay avatar gaitay commented on May 28, 2024

@Kismuz @tmorgan4
Thank you for all your hard work!

from btgym.

gaitay avatar gaitay commented on May 28, 2024

@Kismuz @tmorgan4
Thank you for all your hard work!

from btgym.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.