How to start the stock quantification system QTYX-Python3.7/3.9 environment and install Anaconda+Pycharm and TaLib

1948711f57c2206869cae3c7226b6efb.png

Preface

4a2cd86b77cacd7749f4d6e400cf100e.png

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.

[Important Notice] The Flush Wealth Management interface has expired! QTYX’s rescue team has arrived at the scene and repaired it successfully!

d5ff32d93e26145810c1d16b69906fb9.png

Why install Anaconda

170a46dce2a6894c362680026e9fc86c.png

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.

63ea62cc2b4b469fbc6039168eb519e3.png

How to download Anaconda

3fb7c012c0add91277e20770250f2012.png

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/]

73dc153742f36fd586e277c8c52014af.png

Anaconda installation process

2687f8085e0f56ce8cd4e6cb5f0ed0db.png

After the download is complete, run the installation file as an administrator.

49cc91c3198d9c4b0867031b9a53cf81.png

e3c075bc6f6e77b989e08d7f6a400523.png

c84a75e5deffc09cc400dcc8bbe57d2b.png

It is recommended to install on the C drive. The path should be simple, with no spaces or Chinese characters in the middle! 

54cb0c797bd52fae77f306a555058535.png

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!e38c61ae2bbfcacb783638ff965041e0.png

219371bb40668e0fbfe63811fbf3aef0.png

386ef39911d15e4696032983b9fdc2f6.png

d5479754913546c805a2e7d6fcfa6429.png

2026dbdfb6771fe1b70ea38adc9d4b71.png

Configure Anaconda environment variables

89804b17d1a160837e8e98255273fb10.png

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自带脚本)

1fac14ca3984f00b17c0bc6d3934c142.png

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.2251030296630e911b6497c5ba64eb05.png

45362f30a21e2c90b136d24415125924.png

Add Anaconda domestic mirror

f3af5a57d81bfa87994cf2ee43754f1d.png

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.

0d5a519471dcb4070b6882e6e6ba80de.png

Install third-party libraries

d99da77ff12e0c42bbcf093b9357f946.png

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:1bb111861d02fc9da050087f1452b1df.png

8ba27ddd7927d355f812daf054aa0e93.png

Install TaLib

f6c14aff3cb7e163ad5c2dc7f40920d4.png

***** 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.

98bb906cfc8d9365e1b81a7830d776e2.png

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:

e5795ed10fd5a8f1638618725087ea6e.png

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

5679ce31ccac4f43d9e670a3c9cc6f36.png

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.

e028657bfd4784d7ea107190dea7a7de.png

***** 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)

bdd4e180adacb6f743deb4d1580ff4ee.png

Install Pycharm

8516a086f03d16e7aad2acf067bbc81f.png

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.

7f4205cc20ca51956393dc3f9d898682.png

After the download is complete, install Pycharm and click Next along the way to the end according to the screenshot below.

f6d530284ae5209e73f7405b4d3a4322.png

3547f915745f38984e66f9a38dc9d8f3.png

a99c0a1b54c5b05f168aa279965ae854.png

231dd64e1031e6bc48f8a2cc9da529f2.png

f8034862899b1da7a73fd4d64ba5c286.png

2a3775404ed7fd124ef175e81235be2d.png

Configure Pycharm

eaa5dbe3a720bafcef63dd3de4b0aadc.png

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.abeda05afbd724a49e5d61c07d3465a9.png

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.8687530b852b551dccb8697858d76aab.png

View the third-party libraries in the current Python environment by selecting [File->Settings].43ac96fcdfb2adc11646b588c21de3c7.png

Okay, so far, the configuration of anaconda in pycharm is basically completed.

3257fca6a9b6c74d0c49976417524f4f.png

Run quantitative analysis tools

7d1b08e416e21e137b5714659fc542cf.png

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.

fe88f9d85fa1255aa6c33aa786ab4a9e.png

f3707f650ec9a0fc80d9d567618f5d7c.png

9ce8241e3a3dc4438ceaa1e1993a5bb7.png

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!

c0c5b81569d1f56db9686c4867081046.jpeg

元宵大师的量化交易书籍开售!!
京东、当当、天猫有售!!

5058966e61039443d1cc0cc0c29ef576.jpeg

Guess you like

Origin blog.csdn.net/hangzhouyx/article/details/132727553