Sorry, I didn't have access to a computer at the time I was writing. Here is what I was trying to do. Assuming I was running the sample code given by backtrader front page:
from datetime import datetime
import backtrader as bt
class SmaCross(bt.SignalStrategy):
params = (('pfast', 10), ('pslow', 30),)
def __init__(self):
sma1, sma2 = bt.ind.SMA(period=self.p.pfast), bt.ind.SMA(period=self.p.pslow)
self.signal_add(bt.SIGNAL_LONG, bt.ind.CrossOver(sma1, sma2))
cerebro = bt.Cerebro()
data = bt.feeds.YahooFinanceData(dataname='YHOO', fromdate=datetime(2011, 1, 1), todate=datetime(2012, 12, 31))
cerebro.adddata(data)
cerebro.addstrategy(SmaCross)
cerebro.run()
Now, assuming that I want to adjust various pfast
and pslow
value using the optstrategy function.
When I replace
cerebro.addstrategy(SmaCross)
cerebro.run()
with
cerebro.optstrategy(SmaCross, pfast=(10,20,30), pslow=(60, 80, 100))
cerebro.run()
the code just keeps running for a long time without printing out anything. I'm just wondering if I'm missing something. Thanks.