Created
February 4, 2019 08:45
-
-
Save rolandkofler/21826dfb74cfbe56b894cef51a2ff368 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime | |
import backtrader as bt | |
class SmaCross(bt.SignalStrategy): | |
def init(self): | |
sma1, sma2 = bt.ind.SMA(period=10), bt.ind.SMA(period=30) | |
crossover = bt.ind.CrossOver(sma1, sma2) | |
self.signal_add(bt.SIGNAL_LONG, crossover) | |
cerebro = bt.Cerebro() | |
cerebro.addstrategy(SmaCross) | |
data0 = bt.feeds.YahooFinanceData(dataname='MSFT', fromdate=datetime(2011, 1, 1), | |
todate=datetime(2012, 12, 31)) | |
cerebro.adddata(data0) | |
cerebro.run() | |
cerebro.plot() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment