With my data it prints only portfolio value
-
I have tried this code with two diiferent data.
'AAPL.csv' from yahoo finance (daily) and a csv from alphavantage (minute). I need to work with minutes, the strategy works with the daily csv and not with the other csv.
I have tried also with the strategy from the quickstartguide, the result is the same, with the csv from yahoo everything is fine, with the one from alphavantage the strategy seems not to run.import backtrader as bt import backtrader.feeds as btfeeds import datetime class StrategiaProva1(bt.Strategy): def next(self): if self.data.close > 126: print(dataYF.datetime) if __name__ == '__main__': cerebro = bt.Cerebro() cerebro.addstrategy(StrategiaProva1) dataAP = btfeeds.GenericCSVData( dataname = 'extended_intraday_AAPL_1min_year1month1_adjusted.csv', fromdate = datetime.datetime(2020, 8, 24, 4, 1, 00), todate = datetime.datetime(2020, 9, 21, 20, 00, 00), openinterest = -1 ) dataYF = bt.feeds.GenericCSVData( dataname = 'AAPL.csv', dtformat = ('%Y-%m-%d'), fromdate = datetime.datetime(2020, 8, 24), todate = datetime.datetime(2020, 9, 18), openinterest = -1 ) cerebro.adddata(dataYF) cerebro.broker.setcash(1000.00) print('Saldo pre-trading: %.2f' %cerebro.broker.getvalue()) cerebro.run() print('Saldo post-trading: %.2f' %cerebro.broker.getvalue())
The output when I use AlphaVantage data is this:
Saldo pre-trading: 1000.00 Saldo post-trading: 1000.00
The output when I use Yahoo data is correct and is this:
Saldo pre-trading: 1000.00 <backtrader.linebuffer.LineBuffer object at 0x05252FD0> <backtrader.linebuffer.LineBuffer object at 0x05252FD0> <backtrader.linebuffer.LineBuffer object at 0x05252FD0> <backtrader.linebuffer.LineBuffer object at 0x05252FD0> Saldo post-trading: 1000.00
Here's the datas:
This daily 20 row csv from yahoo finance
And this 18147 rows csv from AlphaVantage
It's a lot of days I'm working on this, please help. -
@mattewannabe said in With my data it prints only portfolio value:
dataYF = bt.feeds.GenericCSVData(
dataname = 'AAPL.csv',
dtformat = ('%Y-%m-%d'),
fromdate = datetime.datetime(2020, 8, 24),
todate = datetime.datetime(2020, 9, 18),
openinterest = -1
)On this page look for Data Feed Common Parameters.
timeframe (default: TimeFrame.Days)
Potential values: Ticks, Seconds, Minutes, Days, Weeks, Months and Years
-
@run-out Thank you so much!!!!