How to read data feeds of more than two years?
-
Hi everyone, I am new to Backtrader and have faced an issue.
I need to load a 5-years historical data using GenericCSVData. However, the output only shows the last two years of data.
I assigned "fromdate" to 2015 and "todate" to 2020, but the output prints data from 2018 till 2020.Here is how I read the data feed:
datapath = os.path.join(modpath, 'data', 'yahoo_AAPL_2015_2020.txt') data = btfeeds.GenericCSVData( dataname= datapath, fromdate=datetime.datetime(2015, 1, 1), todate=datetime.datetime(2020, 1, 1), nullvalue=0.0, dtformat=('%Y-%m-%d'), datetime=0, high=1, low=2, open=3, close=4, volume=5, openinterest=-1)
Any help would be appreciated!
-
Would need to see your data. Maybe try removing fromdate & todate arguments. That will use all available data by default
-
@hghhgghdf-dfdf I did what you suggested but it didn't work.
Data is a text file as below:Date,High,Low,Open,Close,Volume,Adj Close 2015-01-02,27.860000610351562,26.837499618530273,27.84749984741211,27.332500457763672,212818400.0,24.89855194091797 2015-01-05,27.162500381469727,26.352500915527344,27.072500228881836,26.5625,257142000.0,24.19711685180664 2015-01-06,26.857500076293945,26.157499313354492,26.635000228881836,26.565000534057617,263188400.0,24.199399948120117 2015-01-07,27.049999237060547,26.674999237060547,26.799999237060547,26.9375,160423600.0,24.538728713989258 2015-01-08,28.037500381469727,27.174999237060547,27.3075008392334,27.97249984741211,237458000.0,25.481557846069336 2015-01-09,28.3125,27.552499771118164,28.167499542236328,28.002500534057617,214798000.0,25.508888244628906 2015-01-12,28.157499313354492,27.200000762939453,28.149999618530273,27.3125,198603200.0,24.88033103942871 2015-01-13,28.200000762939453,27.227500915527344,27.857500076293945,27.55500030517578,268367600.0,25.101242065429688 2015-01-14,27.622499465942383,27.125,27.260000228881836,27.450000762939453,195826400.0,25.00558853149414 2015-01-15,27.514999389648438,26.665000915527344,27.5,26.704999923706055,240056000.0,24.32692527770996 2015-01-16,26.895000457763672,26.299999237060547,26.75749969482422,26.497499465942383,314053200.0,24.137907028198242 2015-01-20,27.24250030517578,26.625,26.959999084472656,27.18000030517578,199599600.0,24.759626388549805 2015-01-21,27.764999389648438,27.0674991607666,27.237499237060547,27.387500762939453,194303600.0,24.948652267456055 2015-01-22,28.11750030517578,27.43000030517578,27.565000534057617,28.100000381469727,215185600.0,25.597705841064453 2015-01-23,28.4375,27.88249969482422,28.075000762939453,28.2450008392334,185859200.0,25.72978973388672 2015-01-26,28.59000015258789,28.200000762939453,28.434999465942383,28.274999618530273,222460000.0,25.757123947143555 2015-01-27,28.1200008392334,27.25749969482422,28.104999542236328,27.28499984741211,382274800.0,24.855283737182617 2015-01-28,29.530000686645508,28.827499389648438,29.407499313354492,28.827499389648438,585908400.0,26.260419845581055 2015-01-29,29.797500610351562,28.889999389648438,29.079999923706055,29.725000381469727,337745600.0,27.0779972076416 2015-01-30,30.0,29.212499618530273,29.600000381469727,29.290000915527344,334982000.0,26.68173599243164 2015-02-02,29.792499542236328,29.020000457763672,29.512500762939453,29.657499313354492,250956400.0,27.016510009765625 2015-02-03,29.772499084472656,29.40250015258789,29.625,29.662500381469727,207662800.0,27.021060943603516 2015-02-04,30.127500534057617,29.577499389648438,29.625,29.889999389648438,280598800.0,27.22830581665039 2015-02-05,30.0575008392334,29.8125,30.0049991607666,29.985000610351562,168984800.0,27.422645568847656 2015-02-06,30.0625,29.612499237060547,30.0049991607666,29.732500076293945,174826400.0,27.191726684570312 2015-02-09,29.959999084472656,29.607500076293945,29.637500762939453,29.93000030517578,155559200.0,27.372344970703125 2015-02-10,30.537500381469727,30.040000915527344,30.042499542236328,30.5049991607666,248034000.0,27.898208618164062 2015-02-11,31.229999542236328,30.625,30.6924991607666,31.219999313354492,294247200.0,28.552112579345703 2015-02-12,31.8700008392334,31.392499923706055,31.514999389648438,31.614999771118164,297898000.0,28.913358688354492 2015-02-13,31.81999969482422,31.412500381469727,31.81999969482422,31.770000457763672,217088800.0,29.055112838745117 2015-02-17,32.220001220703125,31.729999542236328,31.872499465942383,31.957500457763672,252609600.0,29.22658920288086 2015-02-18,32.19499969482422,31.862499237060547,31.907499313354492,32.18000030517578,179566800.0,29.430076599121094 2015-02-19,32.25749969482422,32.08250045776367,32.119998931884766,32.11249923706055,149449600.0,29.368343353271484 2015-02-20,32.375,32.01250076293945,32.154998779296875,32.375,195793600.0,29.60841178894043 2015-02-23,33.25,32.415000915527344,32.505001068115234,33.25,283896400.0,30.408634185791016 2015-02-24,33.400001525878906,32.79249954223633,33.23500061035156,33.04249954223633,276912400.0,30.2188720703125 2015-02-25,32.900001525878906,32.037498474121094,32.88999938964844,32.1974983215332,298846800.0,29.446073532104492 2015-02-26,32.717498779296875,31.65250015258789,32.1974983215332,32.60499954223633,365150000.0,29.818758010864258 2015-02-27,32.64250183105469,32.060001373291016,32.5,32.1150016784668,248059200.0,29.370628356933594 2015-03-02,32.56999969482422,32.07500076293945,32.3125,32.272499084472656,192386800.0,29.51466941833496 2015-03-03,32.380001068115234,32.022499084472656,32.2400016784668,32.34000015258789,151265200.0,29.576406478881836 2015-03-04,32.38999938964844,32.08000183105469,32.275001525878906,32.1349983215332,126665200.0,29.388917922973633 2015-03-05,32.1875,31.440000534057617,32.14500045776367,31.602500915527344,226068400.0,28.901926040649414 2015-03-06,32.342498779296875,31.565000534057617,32.099998474121094,31.649999618530273,291368400.0,28.945363998413086 2015-03-09,32.39250183105469,31.264999389648438,31.989999771118164,31.78499984741211,354114000.0,29.068830490112305 2015-03-10,31.80500030517578,30.950000762939453,31.602500915527344,31.127500534057617,275426400.0,28.46751594543457 2015-03-11,31.1924991607666,30.52750015258789,31.1875,30.559999465942383,275756000.0,27.948511123657227 2015-03-12,31.225000381469727,30.407499313354492,30.577499389648438,31.112499237060547,193450800.0,28.453798294067383 2015-03-13,31.350000381469727,30.645000457763672,31.100000381469727,30.897499084472656,207309200.0,28.257169723510742 2015-03-16,31.237499237060547,30.717500686645508,30.969999313354492,31.237499237060547,143497200.0,28.568111419677734 2015-03-17,31.829999923706055,31.412500381469727,31.475000381469727,31.760000228881836,204092400.0,29.04596519470215 2015-03-18,32.290000915527344,31.592500686645508,31.75,32.11750030517578,261083600.0,29.37291717529297 2015-03-19,32.3125,31.850000381469727,32.1875,31.875,183238000.0,29.151140213012695 2015-03-20,32.099998474121094,31.290000915527344,32.0625,31.475000381469727,274780400.0,28.78531837463379 2015-03-23,31.962499618530273,31.6299991607666,31.780000686645508,31.802499771118164,150838800.0,29.084835052490234 2015-03-24,32.0099983215332,31.639999389648438,31.8075008392334,31.672500610351562,131369200.0,28.965940475463867 2015-03-25,31.704999923706055,30.844999313354492,31.635000228881836,30.844999313354492,206620800.0,28.209152221679688 2015-03-26,31.219999313354492,30.649999618530273,30.690000534057617,31.059999465942383,190291600.0,28.405780792236328 2015-03-27,31.174999237060547,30.727500915527344,31.142499923706055,30.8125,158184800.0,28.179433822631836 2015-03-30,31.600000381469727,31.0,31.012500762939453,31.592500686645508,188398800.0,28.892780303955078 2015-03-31,31.622499465942383,31.09000015258789,31.522499084472656,31.107500076293945,168362400.0,28.449222564697266 2015-04-01,31.280000686645508,30.774999618530273,31.204999923706055,31.0625,162485600.0,28.408071517944336 2015-04-02,31.389999389648438,31.047500610351562,31.25749969482422,31.329999923706055,128880400.0,28.652708053588867 2015-04-06,31.877500534057617,31.082500457763672,31.11750030517578,31.837499618530273,148776000.0,29.116844177246094 2015-04-07,32.029998779296875,31.4950008392334,31.90999984741211,31.502500534057617,140049200.0,28.810468673706055 2015-04-08,31.600000381469727,31.24250030517578,31.462499618530273,31.399999618530273,149316800.0,28.716732025146484 2015-04-09,31.645000457763672,31.165000915527344,31.462499618530273,31.639999389648438,129936000.0,28.936214447021484 2015-04-10,31.802499771118164,31.315000534057617,31.487499237060547,31.774999618530273,160752000.0,29.059680938720703 2015-04-13,32.14250183105469,31.65250015258789,32.092498779296875,31.712499618530273,145460400.0,29.00252342224121 2015-04-14,31.822500228881836,31.477500915527344,31.75,31.575000762939453,102098400.0,28.876771926879883 2015-04-15,31.782499313354492,31.502500534057617,31.602500915527344,31.69499969482422,115881600.0,28.986515045166016 2015-04-16,31.774999618530273,31.52750015258789,31.56999969482422,31.542499542236328,113476000.0,28.847049713134766 2015-04-17,31.53499984741211,31.114999771118164,31.387500762939453,31.1875,207828000.0,28.522384643554688 2015-04-20,32.029998779296875,31.292499542236328,31.392499923706055,31.899999618530273,188217200.0,29.173999786376953 2015-04-21,32.04999923706055,31.667499542236328,32.025001525878906,31.727500915527344,129740400.0,29.016244888305664 2015-04-22,32.217498779296875,31.579999923706055,31.747499465942383,32.154998779296875,150618000.0,29.407215118408203 2015-04-23,32.60499954223633,32.03499984741211,32.07500076293945,32.41749954223633,183083600.0,29.647281646728516 2015-04-24,32.657501220703125,32.307498931884766,32.622501373291016,32.56999969482422,178103600.0,29.786746978759766 2015-04-27,33.282501220703125,32.787498474121094,33.07749938964844,33.162498474121094,387816800.0,30.328609466552734 2015-04-28,33.6349983215332,32.39250183105469,33.6150016784668,32.63999938964844,475696000.0,29.85076141357422 2015-04-29,32.897499084472656,32.07500076293945,32.540000915527344,32.15999984741211,253544400.0,29.411785125732422 2015-04-30,32.15999984741211,31.145000457763672,32.15999984741211,31.287500381469727,332781600.0,28.613842010498047 2015-05-01,32.532501220703125,31.325000762939453,31.524999618530273,32.23749923706055,234050400.0,29.48265838623047 2015-05-04,32.64250183105469,32.064998626708984,32.375,32.17499923706055,203953200.0,29.425500869750977 2015-05-05,32.11249923706055,31.44499969482422,32.037498474121094,31.450000762939453,197085600.0,28.76245880126953 2015-05-06,31.6875,30.84000015258789,31.639999389648438,31.252500534057617,288564000.0,28.58183479309082 2015-05-07,31.520000457763672,31.0049991607666,31.1924991607666,31.315000534057617,175763600.0,28.75861930847168 2015-05-08,31.905000686645508,31.52750015258789,31.670000076293945,31.905000686645508,222201600.0,29.300458908081055 2015-05-11,31.889999389648438,31.407499313354492,31.84749984741211,31.579999923706055,168143200.0,29.00198745727539 2015-05-12,31.719999313354492,31.204999923706055,31.399999618530273,31.467500686645508,192640000.0,28.8986759185791 2015-05-13,31.797500610351562,31.467500686645508,31.537500381469727,31.502500534057617,138776800.0,28.930809020996094 2015-05-14,32.23749923706055,31.790000915527344,31.852500915527344,32.23749923706055,180814000.0,29.605806350708008 2015-05-15,32.372501373291016,32.0525016784668,32.26750183105469,32.192501068115234,152832000.0,29.56448745727539 2015-05-18,32.68000030517578,32.09000015258789,32.095001220703125,32.54750061035156,203531600.0,29.890506744384766 2015-05-19,32.720001220703125,32.40999984741211,32.67250061035156,32.51750183105469,178532800.0,29.862958908081055 2015-05-20,32.744998931884766,32.334999084472656,32.5,32.51499938964844,145819600.0,29.860654830932617 2015-05-21,32.907501220703125,32.45750045776367,32.51750183105469,32.84749984741211,158921600.0,30.1660213470459 2015-05-22,33.24250030517578,32.849998474121094,32.900001525878906,33.1349983215332,182384000.0,30.4300479888916 2015-05-26,33.227500915527344,32.279998779296875,33.150001525878906,32.404998779296875,282790400.0,29.75963020324707 2015-05-27,33.064998626708984,32.51250076293945,32.584999084472656,33.0099983215332,183332800.0,30.315250396728516 2015-05-28,32.98749923706055,32.775001525878906,32.96500015258789,32.94499969482422,122933200.0,30.25554656982422 2015-05-29,32.86249923706055,32.474998474121094,32.807498931884766,32.56999969482422,203538000.0,29.911170959472656 2015-06-01,32.84749984741211,32.51250076293945,32.56999969482422,32.6349983215332,128451200.0,29.97086524963379 2015-06-02,32.665000915527344,32.33000183105469,32.46500015258789,32.4900016784668,134670400.0,29.837703704833984 2015-06-03,32.73500061035156,32.474998474121094,32.665000915527344,32.529998779296875,123934000.0,29.874433517456055 2015-06-04,32.64500045776367,32.227500915527344,32.39500045776367,32.34000015258789,153800400.0,29.699947357177734 2015-06-05,32.42250061035156,32.09000015258789,32.375,32.162498474121094,142507200.0,29.53693389892578 2015-06-08,32.3025016784668,31.707500457763672,32.224998474121094,31.950000762939453,210699200.0,29.34178352355957 2015-06-09,32.02000045776367,31.405000686645508,31.674999237060547,31.854999542236328,224301600.0,29.254535675048828 2015-06-10,32.334999084472656,31.962499618530273,31.979999542236328,32.220001220703125,156349200.0,29.589736938476562 2015-06-11,32.54499816894531,32.119998931884766,32.29499816894531,32.147499084472656,141563600.0,29.523157119750977 2015-06-12,32.08250045776367,31.77750015258789,32.04750061035156,31.792499542236328,147544800.0,29.197141647338867 2015-06-15,31.809999465942383,31.427499771118164,31.524999618530273,31.729999542236328,175955600.0,29.139741897583008 2015-06-16,31.962499618530273,31.592500686645508,31.75749969482422,31.899999618530273,125976400.0,29.295862197875977 2015-06-17,31.969999313354492,31.684999465942383,31.93000030517578,31.825000762939453,131672400.0,29.22698211669922 2015-06-18,32.07749938964844,31.80500030517578,31.8075008392334,31.969999313354492,141628800.0,29.360151290893555 2015-06-19,31.954999923706055,31.600000381469727,31.927499771118164,31.649999618530273,218867600.0,29.066267013549805 2015-06-22,32.01499938964844,31.770000457763672,31.872499465942383,31.90250015258789,136157200.0,29.29815673828125 2015-06-23,31.90250015258789,31.719999313354492,31.8700008392334,31.75749969482422,121075600.0,29.164993286132812 2015-06-24,32.45000076293945,31.780000686645508,31.802499771118164,32.02750015258789,221123600.0,29.41295623779297 2015-06-25,32.29999923706055,31.875,32.21500015258789,31.875,127752400.0,29.272903442382812 2015-06-26,31.997499465942383,31.627500534057617,31.917499542236328,31.6875,176267200.0,29.100709915161133 2015-06-29,31.61750030517578,31.1200008392334,31.364999771118164,31.13249969482422,196645600.0,28.59101676940918 2015-06-30,31.530000686645508,31.21500015258789,31.392499923706055,31.357500076293945,177482800.0,28.797649383544922 2015-07-01,31.735000610351562,31.497499465942383,31.725000381469727,31.649999618530273,120955200.0,29.066267013549805 2015-07-02,31.672500610351562,31.4424991607666,31.607500076293945,31.610000610351562,108844000.0,29.029537200927734 2015-07-06,31.5575008392334,31.212499618530273,31.235000610351562,31.5,112241600.0,28.92851448059082 2015-07-07,31.537500381469727,30.9424991607666,31.47249984741211,31.422500610351562,187787200.0,28.857349395751953 2015-07-08,31.15999984741211,30.635000228881836,31.1200008392334,30.642499923706055,243046400.0,28.141019821166992 2015-07-09,31.014999389648438,29.80500030517578,30.962499618530273,30.017499923706055,314380000.0,27.567041397094727 2015-07-10,30.962499618530273,30.302499771118164,30.485000610351562,30.81999969482422,245418000.0,28.304025650024414 2015-07-13,31.440000534057617,31.079999923706055,31.25749969482422,31.415000915527344,165762000.0,28.85045623779297 2015-07-14,31.592500686645508,31.260000228881836,31.510000228881836,31.40250015258789,127072400.0,28.838979721069336 2015-07-15,31.787500381469727,31.395000457763672,31.43000030517578,31.704999923706055,134596800.0,29.116783142089844 2015-07-16,32.14250183105469,31.837499618530273,31.934999465942383,32.127498626708984,144889600.0,29.504793167114258 2015-07-17,32.404998779296875,32.07749938964844,32.27000045776367,32.404998779296875,184658800.0,29.75963020324707 2015-07-20,33.24250030517578,32.67499923706055,32.74250030517578,33.01750183105469,235600800.0,30.322134017944336 2015-07-21,33.22999954223633,32.58000183105469,33.212501525878906,32.6875,307025600.0,30.01907730102539 2015-07-22,31.375,30.497499465942383,30.497499465942383,31.30500030517578,461802400.0,28.74943733215332 2015-07-23,31.772499084472656,31.264999389648438,31.549999237060547,31.290000915527344,203998000.0,28.735660552978516 2015-07-24,31.434999465942383,30.975000381469727,31.329999923706055,31.125,168649200.0,28.584131240844727 2015-07-27,30.90250015258789,30.530000686645508,30.772499084472656,30.6924991607666,177822000.0,28.186941146850586 2015-07-28,30.977500915527344,30.637500762939453,30.844999313354492,30.844999313354492,134472400.0,28.32698631286621 2015-07-29,30.875,30.5674991607666,30.787500381469727,30.747499465942383,148046800.0,28.23744773864746 2015-07-30,30.642499923706055,30.427499771118164,30.579999923706055,30.592500686645508,134513200.0,28.09510040283203 2015-07-31,30.65999984741211,30.227500915527344,30.649999618530273,30.325000762939453,171540000.0,27.849435806274414 2015-08-03,30.642499923706055,29.3799991607666,30.375,29.610000610351562,279904000.0,27.192806243896484 2015-08-04,29.424999237060547,28.3125,29.354999542236328,28.65999984741211,496554400.0,26.320362091064453 2015-08-05,29.360000610351562,28.024999618530273,28.237499237060547,28.850000381469727,397250400.0,26.49484634399414 2015-08-06,29.125,28.530000686645508,28.99250030517578,28.782499313354492,211612000.0,26.55250358581543 2015-08-07,29.0625,28.625,28.645000457763672,28.8799991607666,154681600.0,26.64244842529297 2015-08-10,29.997499465942383,29.13249969482422,29.13249969482422,29.93000030517578,219806400.0,27.611099243164062 2015-08-11,29.545000076293945,28.332500457763672,29.452499389648438,28.372499465942383,388331200.0,26.174270629882812 2015-08-12,28.854999542236328,27.407499313354492,28.13249969482422,28.809999465942383,404870000.0,26.5778751373291 2015-08-13,29.100000381469727,28.635000228881836,29.010000228881836,28.787500381469727,194143200.0,26.5571231842041 2015-08-14,29.077499389648438,28.502500534057617,28.579999923706055,28.989999771118164,171718000.0,26.743925094604492 2015-08-17,29.412500381469727,28.875,29.010000228881836,29.290000915527344,163538800.0,27.02068519592285 2015-08-18,29.360000610351562,29.002500534057617,29.107500076293945,29.125,138242800.0,26.868467330932617 2015-08-19,29.1299991607666,28.670000076293945,29.024999618530273,28.752500534057617,193146000.0,26.524829864501953 2015-08-20,28.587499618530273,27.907499313354492,28.520000457763672,28.162500381469727,274006400.0,25.98053550720215 2015-08-21,27.975000381469727,26.412500381469727,27.607500076293945,26.440000534057617,513102000.0,24.391490936279297 2015-08-24,27.200000762939453,23.0,23.717500686645508,25.780000686645508,648825200.0,23.78263282775879 2015-08-25,27.77750015258789,25.875,27.77750015258789,25.934999465942383,414406400.0,23.92562484741211 2015-08-26,27.47249984741211,26.262500762939453,26.772499084472656,27.422500610351562,387098400.0,25.297876358032227 2015-08-27,28.309999465942383,27.5049991607666,28.0575008392334,28.229999542236328,338464400.0,26.042810440063477 2015-08-28,28.327499389648438,27.885000228881836,28.042499542236328,28.322500228881836,212657600.0,26.128145217895508 2015-08-31,28.63249969482422,28.0,28.00749969482422,28.190000534057617,224917200.0,26.00591468811035 2015-09-01,27.969999313354492,26.84000015258789,27.537500381469727,26.93000030517578,307383600.0,24.84353256225586 2015-09-02,28.084999084472656,27.282499313354492,27.5575008392334,28.084999084472656,247555200.0,25.909042358398438 2015-09-03,28.19499969482422,27.510000228881836,28.122499465942383,27.592500686645508,212935600.0,25.454700469970703 2015-09-04,27.612499237060547,27.127500534057617,27.24250030517578,27.3174991607666,199985200.0,25.201007843017578 2015-09-08,28.139999389648438,27.579999923706055,27.9375,28.077499389648438,219374400.0,25.902128219604492 2015-09-09,28.5049991607666,27.4424991607666,28.440000534057617,27.537500381469727,340043200.0,25.403963088989258 2015-09-10,28.31999969482422,27.475000381469727,27.5674991607666,28.142499923706055,251571200.0,25.962093353271484 2015-09-11,28.552499771118164,27.940000534057617,27.947500228881836,28.552499771118164,199662000.0,26.340322494506836 2015-09-14,29.22249984741211,28.71500015258789,29.145000457763672,28.827499389648438,233453600.0,26.59401512145996 2015-09-15,29.13249969482422,28.604999542236328,28.982500076293945,29.06999969482422,173364800.0,26.817729949951172 2015-09-16,29.135000228881836,28.860000610351562,29.0625,29.102500915527344,148694000.0,26.84771728515625 2015-09-17,29.122499465942383,28.43000030517578,28.915000915527344,28.479999542236328,256450400.0,26.2734432220459 2015-09-18,28.575000762939453,27.967500686645508,28.052499771118164,28.362499237060547,297141200.0,26.1650447845459 2015-09-21,28.842500686645508,28.415000915527344,28.417499542236328,28.802499771118164,200888000.0,26.570955276489258 2015-09-22,28.545000076293945,28.1299991607666,28.344999313354492,28.350000381469727,201384800.0,26.153520584106445 2015-09-23,28.68000030517578,28.325000762939453,28.407499313354492,28.579999923706055,143026800.0,26.365690231323242 2015-09-24,28.875,28.092500686645508,28.3125,28.75,200878000.0,26.522523880004883 2015-09-25,29.172500610351562,28.5049991607666,29.110000610351562,28.677499771118164,224607600.0,26.455642700195312 2015-09-28,28.642499923706055,28.110000610351562,28.462499618530273,28.110000610351562,208436000.0,25.932111740112305 2015-09-29,28.377500534057617,26.96500015258789,28.207500457763672,27.264999389648438,293461600.0,25.152576446533203 2015-09-30,27.885000228881836,27.1825008392334,27.542499542236328,27.575000762939453,265892000.0,25.43856430053711 2015-10-01,27.405000686645508,26.827499389648438,27.267499923706055,27.395000457763672,255716400.0,25.27250862121582 2015-10-02,27.752500534057617,26.887500762939453,27.002500534057617,27.594999313354492,232079200.0,25.457008361816406 2015-10-05,27.842500686645508,27.267499923706055,27.469999313354492,27.69499969482422,208258800.0,25.54926300048828 2015-10-06,27.934999465942383,27.4424991607666,27.657499313354492,27.827499389648438,192787200.0,25.671497344970703 2015-10-07,27.9424991607666,27.352500915527344,27.934999465942383,27.69499969482422,187062400.0,25.54926300048828 2015-10-08,27.547500610351562,27.052499771118164,27.547500610351562,27.375,247918400.0,25.25405502319336 2015-10-09,28.06999969482422,27.372499465942383,27.5,28.030000686645508,211064400.0,25.858308792114258 2015-10-12,28.1875,27.860000610351562,28.1825008392334,27.899999618530273,121868800.0,25.738378524780273 2015-10-13,28.112499237060547,27.670000076293945,27.704999923706055,27.947500228881836,132197200.0,25.782197952270508 2015-10-14,27.8799991607666,27.389999389648438,27.822500228881836,27.552499771118164,177849600.0,25.417804718017578 2015-10-15,28.024999618530273,27.622499465942383,27.732500076293945,27.96500015258789,150694000.0,25.79834747314453 2015-10-16,28.0,27.63249969482422,27.94499969482422,27.760000228881836,156930400.0,25.609230041503906 2015-10-19,27.9375,27.52750015258789,27.700000762939453,27.9325008392334,119036800.0,25.76836585998535 2015-10-20,28.542499542236328,27.704999923706055,27.834999084472656,28.4424991607666,195871200.0,26.238849639892578 2015-10-21,28.895000457763672,28.424999237060547,28.5,28.440000534057617,167180800.0,26.236543655395508 2015-10-22,28.875,28.524999618530273,28.582500457763672,28.875,166616400.0,26.637842178344727 2015-10-23,29.8075008392334,29.082500457763672,29.174999237060547,29.770000457763672,237467600.0,27.46349334716797 2015-10-26,29.532499313354492,28.729999542236328,29.520000457763672,28.81999969482422,265335200.0,26.587100982666016 2015-10-27,29.135000228881836,28.497499465942383,28.850000381469727,28.637500762939453,279537600.0,26.418745040893555 2015-10-28,29.825000762939453,29.014999389648438,29.232500076293945,29.8174991607666,342205600.0,27.50731658935547 2015-10-29,30.172500610351562,29.5674991607666,29.674999237060547,30.13249969482422,204909200.0,27.797910690307617 . . . 2019-12-31,73.41999816894531,72.37999725341797,72.48249816894531,73.4124984741211,100805600.0,72.783935546875
-
Could you post all of your code together please?
-
@run-out Yes, here is the code:
from __future__ import (absolute_import, division, print_function, unicode_literals) import datetime # For datetime objects import os.path # To manage paths import sys # To find out the script name (in argv[0]) # Import the backtrader platform import backtrader as bt import backtrader.feeds as btfeeds # Create a Stratey class TestStrategy(bt.Strategy): def log(self, txt, dt=None): ''' Logging function for this strategy''' dt = dt or self.datas[0].datetime.date(0) print('%s, %s' % (dt.isoformat(), txt)) def __init__(self): # Keep a reference to the "close" line in the data[0] dataseries self.dataclose = self.datas[0].close def next(self): # Simply log the closing price of the series from the reference self.log('Close, %.2f' % self.dataclose[0]) if __name__ == '__main__': # Create a cerebro entity cerebro = bt.Cerebro() cerebro.addstrategy(TestStrategy) # Datas are in a subfolder of the samples. Need to find where the script is # because it could have been called from anywhere modpath = os.path.dirname(os.path.abspath(sys.argv[0])) datapath = os.path.join(modpath, 'data', 'yahoo_AAPL_2015_2020.txt') data = btfeeds.GenericCSVData( dataname= datapath, reverse = False, fromdate=datetime.datetime(2015, 1, 1), todate=datetime.datetime(2020, 1, 1), nullvalue=0.0, dtformat=('%Y-%m-%d'), datetime=0, high=1, low=2, open=3, close=4, volume=5, openinterest=-1 ) # Add the Data Feed to Cerebro cerebro.adddata(data) # Set our desired cash start cerebro.broker.setcash(100000.0) # Print out the starting conditions print('Starting Portfolio Value: %.2f' % cerebro.broker.getvalue()) # Run over everything cerebro.run() # Print out the final result print('Final Portfolio Value: %.2f' % cerebro.broker.getvalue())
-
Your code is fine. I just ran it with your data above, what's there anyway. And it prints all of it and also allows for changed dates.
You should try it on a different data file. Or perhaps your terminal is only displaying the last 'n' results? Try reducing the date range.
-
@run-out Thanks! Is there any way that I can save the output of the code to check if it reads all data or not? In this way I can make sure that it's terminal issue.
-
Just try it in smaller date ranges, maybe try one year at a time.