OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Can backtrader plot only with close price?

  • Thread starter Thread starter Doodle-loo
  • Start date Start date
D

Doodle-loo

Guest
I can plot with the test data (2005-2006-day-001.txt) when read all columns.

My code is as follows:

Code:
import backtrader as bt


class St(bt.Strategy):
    def __init__(self):
        self.sma = bt.indicators.SimpleMovingAverage(self.data)



data = bt.feeds.GenericCSVData(dataname='2005-2006-day-001.txt', datetime=0, close=4, open=1, high=2, low=3, volume=5, openinterest=6, dtformat=('%Y-%m-%d'))

cerebro = bt.Cerebro()
cerebro.adddata(data)
cerebro.addstrategy(St)
cerebro.run()
cerebro.plot() # this works

But if only read close price from the test data, cerebro.plot() raise ValueError: Axis limits cannot be NaN or Inf

Code:
import backtrader as bt


class St(bt.Strategy):
    def __init__(self):
        self.sma = bt.indicators.SimpleMovingAverage(self.data)



data = bt.feeds.GenericCSVData(dataname='2005-2006-day-001.txt', datetime=0, close=4, open=-1, high=-1, low=-1, volume=-1, openinterest=-1, dtformat=('%Y-%m-%d'))

cerebro = bt.Cerebro()
cerebro.adddata(data)
cerebro.addstrategy(St)
cerebro.run()
cerebro.plot() # this raise ValueError

Common fund which I want to backtest only has close price.

Can backtrader plot only with close price? Or any other advices?
<p>I can plot with the test data <a href="https://github.com/mementum/backtrader/tree/master/datas" rel="nofollow noreferrer">(2005-2006-day-001.txt)</a> when <strong>read all columns.</strong></p>
<p>My code is as follows:</p>
<pre><code>import backtrader as bt


class St(bt.Strategy):
def __init__(self):
self.sma = bt.indicators.SimpleMovingAverage(self.data)



data = bt.feeds.GenericCSVData(dataname='2005-2006-day-001.txt', datetime=0, close=4, open=1, high=2, low=3, volume=5, openinterest=6, dtformat=('%Y-%m-%d'))

cerebro = bt.Cerebro()
cerebro.adddata(data)
cerebro.addstrategy(St)
cerebro.run()
cerebro.plot() # this works
</code></pre>
<p>But if <strong>only read close price</strong> from the test data, cerebro.plot() raise <strong>ValueError: Axis limits cannot be NaN or Inf</strong></p>
<pre><code>import backtrader as bt


class St(bt.Strategy):
def __init__(self):
self.sma = bt.indicators.SimpleMovingAverage(self.data)



data = bt.feeds.GenericCSVData(dataname='2005-2006-day-001.txt', datetime=0, close=4, open=-1, high=-1, low=-1, volume=-1, openinterest=-1, dtformat=('%Y-%m-%d'))

cerebro = bt.Cerebro()
cerebro.adddata(data)
cerebro.addstrategy(St)
cerebro.run()
cerebro.plot() # this raise ValueError
</code></pre>
<p>Common fund which I want to backtest only has close price.</p>
<p>Can backtrader plot only with close price? Or any other advices?</p>
 

Latest posts

Top