[Vnpy quantitative investment from scratch] 6. Store historical data in mysql

[Vnpy quantitative investment from scratch] 6. Store historical data in mysql

overview

In the content of the first lesson, we introduced how to use the vnpy client to download data through the meter basket rqdata, but did not delve into where the data is downloaded, and how to access and use the data through code. In this lesson, we will modify the implementation of the database and use the independently installed mysql to store data for backtesting and real trading.

Switch database implementation

Principle of vnpy database

We open the database.py file under the vnpy.trader package. The data structure and interface for futures data storage and acquisition are defined here. Let's introduce the content and usage of several main methods.
save_bar_data: Minute K-line storage method, supports list, from the specific implementation point of view, you need to pay attention to the single call when using it, you need to ensure that the list input parameter only contains the data of that variety, otherwise the data recorded for the first time in the bar_overview table will have some Statistical errors (Although it does not affect actual use, it is not recommended to store mixed data)
load_bar_data: query k-line data, there are two main purposes. One is to call the load(N) method in the on_init method to obtain the k-line data of N days during the initialization of the real market, and use this data to initialize the statistical values ​​required by the strategy, such as calculating the moving average or calculating channel information. The second is to load data for the backtest. We used this method to run the backtest after we used the rice basket to click download, and then click the backtest to run the results.

class BaseDatabase(ABC)

Guess you like

Origin blog.csdn.net/u011687355/article/details/130236062