Backtrader obtains market data from tushare or baostock

The first step in learning backtrader is to obtain market data, and many beginners are stuck in this step. In fact, you can write a piece of python code to download market data from online apis such as tushare or baostock to local CSV files. There are text introductions on the Internet, but they are often not comprehensive. Please refer to Lesson 2 of this course for step-by-step video instructions .

Here are a few points to note:

1 Downloading data from tushare requires registration, and the initial points are not enough. You need to follow the instructions on its website to get extra points to download. And baostock is completely free to download

2 The data of tushare is in descending order by date, which does not meet the requirements of backtrader, so it needs to be rearranged

3. The original data of baostock contains the suspension record, and the backtrader does not need the suspension record, so it is necessary to delete the suspension record.

4 Some restoration data of tushare and baostock seem to be inconsistent. At the time of writing this book, the closing price of 600,000 SPD Bank on May 12, 2006 differed by more than 4 yuan. Readers have to evaluate which is correct. baostock is 16.18, tushare is 21.03, while on the snowball website it is 21.03, and in Flush software is 20.75.

5 It is best to restore data after downloading

Sweeper Backtrader awesome tutorial

Guess you like

Origin blog.csdn.net/qtbgo/article/details/108296146