Preface
Our stock quantitative analysis system QTYX is available in two forms:
EXE installation file. The advantage is that there is no need to install the Python environment. You can use the functions of QTYX by double-clicking the installed EXE file.
Python source code. The advantage is that you can learn and debug the source code, and do secondary development on this basis, add your own ideas to it, and transform it into your own quantification system.
For students who want to run the source code, as long as they install the third-party libraries used by the source code in the Python environment, they can run it! ! !
So, the first step is to set up the operating environment! ! ! It is recommended to use a combination of Anaconda+Pycharm. It is also possible if you use the vscode environment.
QTYX 2.0 version can use the Python3.7 environment. The latest version of QTYX uses the pywencai library and requires Python 3.8 or above. Therefore, our Python environment keeps pace with the times and will be upgraded simultaneously to Python 3.9! If you don't need to ask for the financial interface, the Python3.7 environment can continue to be used.
Why install Anaconda
For Python beginners, it is recommended to install Anaconda.
Python is just an interpreter, and Anaconda is a Python distribution (packaged collection) for scientific computing. It comes pre-installed with conda, python (a certain version), numerous packages, scientific computing tools, etc., and also includes third-party libraries. Management (such as installation, uninstallation, updating libraries) and environment management (facilitating coexistence and switching when multiple Python runtime environments are installed). Supports Linux, Mac, and Windows systems.
In short, using Anaconda is trouble-free, convenient and fast.
How to download Anaconda
It is not recommended to download from the official website [https://www.anaconda.com/download/] (super slow), and the Python version included with the download is not consistent with what we recommend.
It is recommended to download and install from the mirror website of Tsinghua University.
Taking window 10 as an example, choose Anaconda3-2019.10-Windows-x86_64.exe to download the Python 3.7 version, and choose Anaconda3-2023.07-Windows-x86_64.exe to download the Python 3.9 version.
Tsinghua University Open Source Software Mirror Station [https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/]
Anaconda installation process
After the download is complete, run the installation file as an administrator.
It is recommended to install on the C drive. The path should be simple, with no spaces or Chinese characters in the middle!
The first item below, Add Anaconda... will automatically add the installation path to the system environment variables. It is recommended not to select it. You can add it manually after the installation is completed. The second item refers to the version of python used by default, select it!
Configure Anaconda environment variables
Under Windows system, add the installation path of anaconda and the Scripts folder path in [Control Panel->System and Security->System->Advanced System Settings->Environment Variables->User Variables->PATH].
C:\Anaconda(Python需要)
C:\Anaconda\Scripts(conda自带脚本)
At this point you can first check whether the previous installation was successful.
Enter conda info in cmd to see if the following returns (confirm that it is consistent with the version you installed):
conda version : 4.11.0
conda-build version : 3.18.9
python version : 3.7.4.final.0
Check whether you can enter the ANACONDA NAVIGATOR interface.
Add Anaconda domestic mirror
When installing Anaconda, you are accessing a foreign network, so downloading the installation package will be particularly slow.
We need to change to the domestic mirror source address. It is recommended to change to the address of Tsinghua University in China. (It was banned by the United States before, but has been restored now)
Operate in the Anaconda prompt:
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
# 设置搜索时显示通道地址
conda config --set show_channel_urls yes
If you use the pip command when installing the library, you can change the pip mirror source address to a domestic one. Add parameter -i when using pip https://pypi.tuna.tsinghua.edu.cn/simple
pip install 【库名称】 -i https://pypi.tuna.tsinghua.edu.cn/simple
This will install the numpy library from the Tsinghua mirror.
Install third-party libraries
After installing Anaconda, you can use conda to manage installation packages (installation, uninstallation, updates).
Of course, you can also choose pip. The library management functions of conda are the same as pip.
Commonly used instructions are as follows:
安装库:conda install matplotlib
卸载库:conda remove matplotlib
更新库:conda update matplotlib
查询已经安装的库:conda list
Newbies are strongly recommended to keep the same version of Python as mine to avoid many detours! ! !
之前Python3.7的版本:
wxpython 4.0.4
mplfinance 0.12.7a10(QTYX2.0 以上版本需要安装)
mpl_finance 0.10.0(QTYX1.0/2.0/书籍配套代码需要安装)
TA-Lib 0.4.17
numpy 1.15.1
pandas 0.23.4
pandas-datareader 0.7.0
pyecharts 1.7.0
matplotlib 3.1.1
tushare 1.2.51
baostock 0.8.8
statsmodels 0.9.0
QTYX的2.3版本之后,已经增加第三方库tabulate,需要pip安装一下
现在Python3.9的版本:
baostock 0.8.8
matplotlib 3.7.2
mplfinance 0.12.10b0
numpy 1.23.4
pandas 1.5.0
pyecharts 2.0.3
pywencai 0.12.0
statsmodels 0.14.0
TA-Lib 0.4.19
tabulate 0.9.0
tqdm 4.66.1
tushare 1.2.89
urllib3 2.0.4
wxPython 4.2.1
In the QTYX2.0 version, if the combination of baostock and wxpython is not good, an "incorrect date format" error will appear. The recommended version combination is: Python3.7+wxpython4.0.4+baostock 0.8.8
If you use Python3.8, you can refer to the following configuration [simply and crudely comment out lines 175 to 187 of the baostock library's \site-packages\baostock\security\history.py file and restart Pycharm]: Python3.8+wxpython4. 1.1+baostock 0.8.8
If you encounter the following error when installing a third-party library:
An HTTP error occurred when trying to retrieve this URL……
You can check out this Tsinghua mirror usage help:
Install TaLib
***** Regarding the installation of TA_Lib under window, it is not enough to install TA_Lib (pip install). You also need to install a C++ compilation environment.
Download the TA_Lib library installation file suitable for the Python environment on your computer under the Windows system from the python extension library of the University of California (the file suffix is WHL, and it is called a wheel file in many places)
https://www.lfd.uci.edu/~gohlke/pythonlibs/
When you open this website, what you will see is dense English. Don’t be nervous. Use Ctrl+F to search for ta_lib directly on the web page.
Here you need to check whether the Windows 10 operating system version (similar to Windows 7) is a 64-bit operating system or a 32-bit operating system, and the Python version to choose to download the correct whl installation file.
For example: In the file name TA Lib‑0.4.21‑cp310‑cp310‑win amd64.whl,
TA Lib‑0.4.21: This refers to the version number of TA Lib, indicating that the version is 0.4.21
cp310: refers to the corresponding python version, 310 refers to the python version 3.10, the corresponding python 3.9 corresponds to cp39, python 3.8 corresponds to cp38, and so on. It should be noted that if your python version is 3.7.6, you should also choose cp37, other versions are similar.
win_amd64: refers to the 64-bit operating system for which the file is suitable for Windows systems
win32: refers to the 32-bit operating system for which the file is suitable for Windows systems
Depending on your windows system and python version, choose to download the whl installation file that suits you. For example, my computer is a Windows 10 64-bit operating system, and the Python version is 3.7.6. I should choose the following installation file. The following installations are all based on this environment.
Careful friends may have discovered that versions before 0.4.21 no longer provide installation files for python37 or above. If you need 0.4.17 or 0.4.19 corresponding to python3.7 or above versions of whl files, you can contact our instructor.
Save the downloaded TA Lib‑0.4.21‑cp37‑cp37m‑win amd64.whl file to a directory that is easy to find. For example, I saved it under d:\whl.
Whether it is Anaconda or the official version of python environment, you can install it as follows:
In the pop-up CMD window, enter the pip installation command pip install TA_Lib-0.4.19-cp37-cp37m-win32.whl and press Enter
After seeing that the following information is returned after the command is executed, it means that the TA_Lib library has been installed successfully.
Looking in indexes: https://pypi.douban.com/simple/
Processing d:\whl\ta_lib-0.4.17-cp37-cp37m-win_amd64.whl
Installing collected packages: TA-Lib
Successfully installed TA-Lib-0.4.17
If the downloaded whl does not match the operating system or python version, for example, the error below is because I selected the python3.7 version of the whl file for a 32-bit operating system. When executing the installation, the following error message will appear.
***** Regarding the installation of TA_Lib under MacOS, it is relatively simple. Just use the following command:
conda install -c conda-forge ta-lib
pip install TA-Lib
Requirement already satisfied: TA-Lib in ./anaconda3/envs/env39/lib/python3.9/site-packages (0.4.19)
Requirement already satisfied: numpy in ./anaconda3/envs/env39/lib/python3.9/site-packages (from TA-Lib) (1.23.4)
Install Pycharm
Pycharm can be downloaded from the official website (http://www.jetbrains.com/pycharm/),
Pycharm has two main versions: Community and Professional, of which Community is free to use. If you want to crack Professional, you can add me on WeChat and I will send you the network disk address to download.
After the download is complete, install Pycharm and click Next along the way to the end according to the screenshot below.
Configure Pycharm
We need to configure the python environment under Anaconda in Pycharm
First create a project to run a quantitative trading system. Click New Project when creating it for the first time.
When re-creating, select [File->New Project]. Select the project file storage path. Add the project's interpreter (python.exe in the anaconda file path) and click Create.
View the third-party libraries in the current Python environment by selecting [File->Settings].
Okay, so far, the configuration of anaconda in pycharm is basically completed.
Run quantitative analysis tools
After everything is ready, you can import the QTYX project file into Pycharm and run the main file StartEntry.py!
The QTYX2.0-study version is given as a gift when you purchase the book "Python Stock Quantitative Trading from Introduction to Practice". The purpose is to help readers build a "bridge" from book knowledge to practical applications. It includes three basic functions: stock selection, market trends, and backtesting.
The latest version of QTYX code and exe executable files need to be added to Knowledge Planet to obtain the functions. For QTYX usage guide, you can check the link: QTYX usage guide
illustrate
Friends who want to join Knowledge Planet's "Fun with Stock Quantitative Trading" remember to call me on WeChat to get benefits. The quota is limited and first come first served!
元宵大师的量化交易书籍开售!!
京东、当当、天猫有售!!