-
-
Notifications
You must be signed in to change notification settings - Fork 92
Open
Description
import datetime
import backtrader as bt
from btplotting import BacktraderPlotting
class MyStrategy(bt.Strategy):
def init(self):
sma1 = bt.indicators.SMA(period=11, subplot=True)
bt.indicators.SMA(period=17, plotmaster=sma1)
bt.indicators.RSI()
def next(self):
pos = len(self.data)
if pos == 45 or pos == 145:
self.buy(self.datas[0], size=None)
if pos == 116 or pos == 215:
self.sell(self.datas[0], size=None)
class MyStrategy2(bt.Strategy):
def init(self):
sma1 = bt.indicators.SMA(period=11, subplot=True)
def next(self):
pos = len(self.data)
if pos == 10 or pos == 145:
self.buy(self.datas[0], size=None)
if pos == 116 or pos == 215:
self.sell(self.datas[0], size=None)
if name == 'main':
cerebro = bt.Cerebro()
cerebro.addstrategy(MyStrategy)
cerebro.addstrategy(MyStrategy2)
data = bt.feeds.YahooFinanceCSVData(
dataname="datas/orcl-1995-2014.txt",
fromdate=datetime.datetime(2000, 1, 1),
todate=datetime.datetime(2001, 2, 28),
reverse=False,
swapcloses=True,
)
cerebro.adddata(data)
cerebro.addanalyzer(bt.analyzers.SharpeRatio)
cerebro.run()
p = BacktraderPlotting(style='bar')
cerebro.plot(p)
plz, how can i get two different exported htmls?
Metadata
Metadata
Assignees
Labels
No labels