@Jiayu-Chen said in [Errno 2] No such file or directory:
@vladisld said in [Errno 2] No such file or directory:
['text/csv', 'text/plain']
Thanks! It worked!
It still doesn't work for me.
Could you attach the yahoo.py to me?
@Jiayu-Chen said in [Errno 2] No such file or directory:
@vladisld said in [Errno 2] No such file or directory:
['text/csv', 'text/plain']
Thanks! It worked!
It still doesn't work for me.
Could you attach the yahoo.py to me?
@vladisld I have modified the code as you suggest me, but now i obtain anoyher error:
( image url)
ps
forgive again what are trivial things for you, for me they are blocks to continue, I am trying to do everything possible
Thanks for the reply. Forgive my perhaps trivial questions but as said I am a neophyte.
So I have to modify the yahoo.py code that derives from the installation of backtrader?
@vladisld
I don't understand how I can act on downloading Yahoo data. But then now it is not possible to use cerebro all over the world? Or is there an alternative system to be able to give cerebro data input to make strategies work?
@vladisld said in [Errno 2] No such file or directory:
Usually it means that something wrong happened during data download from Yahoo services. It could be a wrong proxy, encoding error or even Yahoo API version change. Fortunately it is easy to debug - just stop inside the
YahooFinanceData.start_v7
(in yahoo.py file) and you will see what's going wrong.
Thanks, but unfortunately I can't understand what's wrong. Could you give me some suggestions?
I state that I am a beginner with cerebro.
I don't understand why this error with this "base" code that worked in the past:
FileNotFoundError: [Errno 2] No such file or directory: 'BYND'
import backtrader as bt
from datetime import datetime
import datetime
class firstStrategy(bt.Strategy):
def __init__(self):
self.dataclose= self.datas[0].close #2
self.rsi = bt.indicators.RSI_SMA(self.data.Close, period=14)
def next(self):
if not self.position:# se non siamo in posizione
if self.rsi < 30:
self.buy(size=100) #compro 100 azioni
else: #cosa succede quando SIAMO già in una posizione
if self.rsi > 80:
self.sell(size=100) #vendo 100 azioni
startcash = 10000
cerebro = bt.Cerebro()
cerebro.addstrategy(firstStrategy)
#data = bt.feeds.BacktraderCSVData(dataname='C:/dati/test/finance/fca.csv')
# Inseriamo i dati
start_dt = datetime.datetime(2018, 12, 1)
end_dt = datetime.datetime(2020, 1, 12)
data = bt.feeds.YahooFinanceData(dataname='BYND',
fromdate=start_dt,
todate=end_dt)
cerebro.adddata(data)
# Set our desired cash start
cerebro.broker.setcash(startcash)
# Run over everything
cerebro.run()
@Mario-Pellegrini said in float division by zero:
from pandas_datareader import data,wb
import datetimeimport backtrader as bt
from datetime import datetime
data = bt.feeds.Quandl(dataname='FCA.MI',
fromdate = datetime(2017,1,1),
todate = datetime(2018,12,31),
buffered= True )class MyStrategy(bt.Strategy):
def init(self):
self.rsi = bt.indicators.RSI_SMA(self.data.close, period=14)
def next(self):
if not self.position:
if self.rsi < 30:
self.buy(size=100)
else:
if self.rsi > 70:
self.sell(size=100)cerebro = bt.Cerebro()
cerebro.addstrategy(MyStrategy)
cerebro.adddata(data)
cerebro.broker.setcash(10000)
cerebro.run()
cerebro.plot()
does it work for you? to me, I repeat, it gives this error, when I execute "cerebro.run ()":
AttributeError: 'NoneType' object has no attribute 'close'
It is not a random code since you also say that the ticker works
Error:
AttributeError: 'NoneType' object has no attribute 'close'
for ENEL.MI, FCA.MI, UCG.MI, ....
maybe on Italian titles?
the code is correct, there must be some problem with this ticker in particular, because with others it works. The fact is that I really wanted this FCA.MI, and with this ticker it returns an error
from pandas_datareader import data,wb
import datetime
import backtrader as bt
from datetime import datetime
data = bt.feeds.Quandl(dataname='FCA.MI',
fromdate = datetime(2017,1,1),
todate = datetime(2018,12,31),
buffered= True )
class MyStrategy(bt.Strategy):
def __init__(self):
self.rsi = bt.indicators.RSI_SMA(self.data.close, period=14)
def next(self):
if not self.position:
if self.rsi < 30:
self.buy(size=100)
else:
if self.rsi > 70:
self.sell(size=100)
cerebro = bt.Cerebro()
cerebro.addstrategy(MyStrategy)
cerebro.adddata(data)
cerebro.broker.setcash(10000)
cerebro.run()
cerebro.plot()