Thanks i try it but no result at all :-)
Ouput nothing :-)

Latest posts made by Aill3urs 2019
-
RE: Alpha Vantage
-
RE: Is there a template for backtesting strategy
I'm on page 486 for on python book :-)
-
RE: Alpha Vantage
oops sorry, here is the code
from alpha_vantage.timeseries import TimeSeries import backtrader as bt # Create a subclass of Strategy to define the indicators and logic class SmaCross(bt.Strategy): # list of parameters which are configurable for the strategy params = dict( pfast=10, # period for the fast moving average pslow=30 # period for the slow moving average ) def __init__(self): sma1 = bt.ind.SMA(period=self.p.pfast) # fast moving average sma2 = bt.ind.SMA(period=self.p.pslow) # slow moving average self.crossover = bt.ind.CrossOver(sma1, sma2) # crossover signal def next(self): if not self.position: # not in the market if self.crossover > 0: # if fast crosses slow to the upside self.buy() # enter long elif self.crossover < 0: # in the market & cross to the downside self.close() # close long position cerebro = bt.Cerebro() ts = TimeSeries(key='MYKEY', output_format='pandas') data = ts.get_intraday(symbol='BTCUSD',interval='1min', outputsize='full') print(data) cerebro.adddata(data) # Add the data feed cerebro.addstrategy(SmaCross) # Add the trading strategy cerebro.run() # run it all cerebro.plot() # and plot it with a single command
-
RE: Alpha Vantage
@Aill3urs-2019 My errors
File "/xxxxxx/Trading001/Entrainement_Data_Ok.py", line 64, in <module>
cerebro.adddata(data) # Add the data feedFile "/xxxxxx/site-packages/backtrader/cerebro.py", line 758, in adddata
data.setenvironment(self)File "/xxxxx/site-packages/pandas/core/generic.py", line 5274, in getattr
return object.getattribute(self, name)AttributeError: 'DataFrame' object has no attribute 'setenvironment'
-
Alpha Vantage
Hello
In this code i try to import data from alpha vantage but look like doesn't workThanks for your help
from alpha_vantage.timeseries import TimeSeries
import backtrader as btCreate a subclass of Strategy to define the indicators and logic
class SmaCross(bt.Strategy):
# list of parameters which are configurable for the strategy
params = dict(
pfast=10, # period for the fast moving average
pslow=30 # period for the slow moving average
)def __init__(self): sma1 = bt.ind.SMA(period=self.p.pfast) # fast moving average sma2 = bt.ind.SMA(period=self.p.pslow) # slow moving average self.crossover = bt.ind.CrossOver(sma1, sma2) # crossover signal def next(self): if not self.position: # not in the market if self.crossover > 0: # if fast crosses slow to the upside self.buy() # enter long elif self.crossover < 0: # in the market & cross to the downside self.close() # close long position
cerebro = bt.Cerebro() # create a "Cerebro" engine instance
Create a data feed
#data = bt.feeds.YahooFinanceData(dataname='MSFT', fromdate=datetime(2011, 1, 1), todate=datetime(2012, 12, 31))
ts = TimeSeries(key='MYKEY', output_format='pandas')
data, meta_data = ts.get_intraday(symbol='MSF',interval='1min', outputsize='full')cerebro.adddata(data) # Add the data feed
cerebro.addstrategy(SmaCross) # Add the trading strategy
cerebro.run() # run it all
cerebro.plot() # and plot it with a single command -
Is there a template for backtesting strategy
Hello,
I'm a little bit noob in python but i try :-)
I would like to know if there is a template to backtest strategy and live test it for bitmex or other exchange.
And after i would like to know if it s possible to connect it to exchange for real time trading ?Thanks a lot
-
Bug
Hello
When i try to run a just this test on Spyder , i have this error :
///-------ERROR-------------------//
File "/Users/jxx/.spyder-py3/temp.py", line 25, in <module>
cerebro.run()File "/Users/jxx/anaconda3/lib/python3.7/site-packages/backtrader/cerebro.py", line 1127, in run
runstrat = self.runstrategies(iterstrat)File "/Users/jxx/anaconda3/lib/python3.7/site-packages/backtrader/cerebro.py", line 1210, in runstrategies
data._start()File "/Users/jxx/anaconda3/lib/python3.7/site-packages/backtrader/feed.py", line 203, in _start
self.start()File "/Users/jxx/anaconda3/lib/python3.7/site-packages/backtrader/feeds/yahoo.py", line 352, in start
super(YahooFinanceData, self).start()File "/Users/jxx/anaconda3/lib/python3.7/site-packages/backtrader/feeds/yahoo.py", line 94, in start
super(YahooFinanceCSVData, self).start()File "/Users/jxxx/anaconda3/lib/python3.7/site-packages/backtrader/feed.py", line 674, in start
self.f = io.open(self.p.dataname, 'r')FileNotFoundError: [Errno 2] No such file or directory: 'BTC-USD'
///--------------------------------------------//
from datetime import datetime
import backtrader as btclass 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='BTC-USD', fromdate=datetime(2018, 1, 1),
todate=datetime(2019, 12, 31))
cerebro.adddata(data0)cerebro.run()
cerebro.plot()