Setting up work environment
The easiest way to get started is by installing Anaconda. Anaconda is a distribution of Python, and it offers different IDEs like Spyder, Jupyter, __, ___ etc.
Installing Quandl
Quandl will help us in retrieving the historical data of the stock. To install quandl type the below command in the terminal –
pip install quandl
Note: The Quandl Python module is free but you must have a Quandl API key in order to download data. To get your own API key, you will need to create a free Quandl account and set your API key.
Importing packages
Once Quandl is installed, the next step is to import packages. We will be using Pandas rigorously in this tutorial as backtesting requires a lot of data manipulation.
import pandas as pd import quandl as qd
After the packages have been imported, we will extract data from Quandl, using the API key.
qd.ApiConfig.api_key = "<API key>”
Automated Trading using Python
Using Python speeds up the trading process, and hence it is also called automated trading/ quantitative trading. The use of Python is credited to its highly functional libraries like TA-Lib, Zipline, Scipy, Pyplot, Matplotlib, NumPy, Pandas etc. Exploring the data at hand is called data analysis. Starting with Python. We will first learn to extract data using the Quandl API.
Using previous data is going to be our key to backtesting strategy. How a strategy works in a given circumstance can only be understood using historical data. We use historical data because in trends in the stock market tend to repeat itself over time.