For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
Print Date column from the date is in Float (737069.9999999999 ). How to get the correct date format while print
-
def __init__(self): self.datadate = self.datas[0].datetime
def next(self):
print(self.datadate[0])if name == 'main':
data = btfeeds.GenericCSVData(
dataname=datapath,
fromdate=datetime.datetime(2013,1,1),
#dtformat=('%Y-%m-%d %H:%M:%S'),
dtformat=('%m/%d/%Y'),
timestamp=0,
time=1,
high=3,
low=4,
open=2,
close=5,
volume=6,
timeframe= bt.TimeFrame.Days,
compression= 1
) -
self.data.datetime.date(x)
wherex
stand for how many periods back you want to go. -
Docs - Quickstart - Our First 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))
Also
bt
has two functions to convert date to/from numbers:date2num
andnum2date
.