backtrader的设计很新颖。
两个基础
1. lines
Data Feeds, Indicators and Strategies have lines.
A line is a succession of points that when joined together form this line. When talking about the markets, a Data Feed has usually the following set of points per day:
Open, High, Low, Close, Volume, OpenInterest
The series of “Open”s along time is a Line. And therefore a Data Feed has usually 6 lines.
If we also consider “DateTime” (which is the actual reference for a single point), we could count 7 lines.
backtraders 自己创造了个“线”的概念,数据是由 Open, High, Low, Close, Volume, OpenInterest 这6个元素构成,每个元素的序列就是一条“线”
DataFeeds, Indicators, Strategies 都有“线”。
2. index 0
backtrader的索引和python不同,索引0指向当前的数值,-1是倒数第二个数值。
之所以这样做,是方便在时间序列里获取当前的数值。我认为
其他方面
-
system clock (backtrader立时)
无论是回测或者实盘,都需要参考、计算历史数据。
backtrader则把bar称之为system clock。也就是bar为backtrader交易世界里的时钟。
bar,可以是1秒,1分,5分,10分之类。 -
self.data[0].close 返回类型
self.data[0].close 返回的是 close的line序列。 -
如何判断读取了多少根bar
backtrader 并没有提供一个变量来更新读取了多根bar,它是通过len(self)来计算的。len(self)表示对象的个数。此处我不是十分明白其意