daily pastebin goal
60%
SHARE
TWEET

Untitled

a guest Feb 14th, 2017 142 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import backtrader as bt
  2. import backtrader.feeds as btfeeds
  3. import datetime
  4.  
  5. data = btfeeds.YahooFinanceCSVData(dataname='DASH.csv')
  6.  
  7. cerebro = bt.Cerebro()
  8.  
  9. cerebro.adddata(data)
  10.  
  11. data = btfeeds.GenericCSVData(
  12.     dataname='DASH.csv',
  13.  
  14.     fromdate=datetime.datetime(2014, 2, 10),
  15.     todate=datetime.datetime(2017, 2, 5),
  16.  
  17.     nullvalue=0.0,
  18.  
  19.     dtformat=('%Y-%m-%d'),
  20.     tmformat=('%H.%M.%S'),
  21.  
  22.     datetime=2,
  23.     #time=1,
  24.     high=3,
  25.     low=4,
  26.     open=5,
  27.     close=1,
  28.     volume=6,
  29.     #openinterest=-1
  30. )
  31.  
  32. class SmaCross(bt.SignalStrategy):
  33.     params = (('pfast', 10), ('pslow', 30),)
  34.     def __init__(self):
  35.         sma1, sma2 = bt.ind.SMA(period=self.p.pfast), bt.ind.SMA(period=self.p.pslow)
  36.         self.signal_add(bt.SIGNAL_LONG, bt.ind.CrossOver(sma1, sma2))
  37.  
  38. cerebro = bt.Cerebro()
  39.  
  40. #data = df#bt.feeds.YahooFinanceData(dataname='YHOO', fromdate=datetime(2011, 1, 1),todate=datetime(2012, 12, 31))
  41. cerebro.adddata(data)
  42. cerebro.addstrategy(SmaCross)
  43. print('Starting Portfolio Value: %.2f' % cerebro.broker.getvalue())
  44. cerebro.run()
  45. print('Final Portfolio Value: %.2f' % cerebro.broker.getvalue())
  46. cerebro.plot()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top