Successful trading requires a great sense of analysis, high-quality financial data, and a programming language that makes the data work for you. In the universe of finance, the two most popular programming languages are Python and R. Today, we’ll be focusing on Python. My name is Victor Montanez, and if you’re a Python beginner, I’ll be leading you through the process of getting started with trading in Python.
The very first thing we need is a data set, in this case stock price data. We can save and call from a .csv format, or call by a programming code, then organize what we need from it and apply it to a programming algorithm.
That will result in a specific data frame, such as in Python and one of its libraries, Pandas. Once we have gathered the data, we can then proceed to analyze its trending sense or direction to plot a chart that will show technical indicators within a price chart.
For our data calls, we will be using the Intrinio US Core Market Data package. You can find documentation for the Intrinio Python software development kit (SDK) here, which, along with my tutorial, will help you get set up so you can start making data calls.
First, you need to install the Intrinio Python SDK API v2 as follows:
Type in your jupyter notebook or Python IDE (Integrated Development Environment) such as VS Code, Anaconda, or Python terminal as shown below
"pip install intrinio-sdk" in Windows or
"pip3 install intrinio-sdk" in a Linux operating system such as Unbutu
This next step will import the library to your notebook or IDE, which will allow you to call the collection of classes, methods, and response objects as outlined in the Intrinio Python SDK documentation.
Importing needed libraries
Notice, if such packages or libraries are needed but not installed, your Python environment will ask for them.
In order to use the Python API SDK, you need an API key as a token to allow you to use the data. You can get your Intrinio API key by creating a free account. Once you have created an account, visit this page to retrieve your API keys (this article explains the difference between the sandbox and production environments, and which key to use).
The following format will call for data - in this example, I'm retrieving data for AMD (American Micro Devices).
Now, a great feature of the Intrinio Python SDK is the following lines where you can state a specific start and end date for the data you want as per the company symbol, in this case AMD.
The code above means you are stating the specific year, month, and day of the month as a start or end date.
Other features include the capability to specify the data frequency (such as daily), page size, and what to do next.
Error exception catch can be also possible, as shown in the lines of code below.
Within the data results, you can receive and view the printed format as shown. Frequency of data, high, low, open, close, and volume, to mention a few, that you can use to print the candles on a chart.
We can use the adj_close for example, which is the price of the stock after the market had closed and settled for the day, and may include any dividends adjustments on the price. That data makes this Intrinio Python SDK an amazing tool to get more accurate data for your charts and trading algorithms.
Please take a look at the Python SDK documentation, so you can see how all of this code is put together, with helpful notes.
There are other external libraries we can use to plot charts and trading signals according to the data we pulled. The Pandas library can help in converting, reading, and saving as .csv. The Backtrader library is useful for a simulated portfolio with technical indicators and trading signals included.
For examples of charts that may include technical indicators and related signals, feel free to visit my blog.
Intrinio's data is available via Web API (what we used for the code above), Excel, .csv, and widgets. Having this advanced set of tools make our programming life and data manipulation very easy.
With an Excel or .csv sheet, we can call the data from a local folder in our computer, then arrange it with Python or R. We use the Pandas library with Python so we can remove or add rows or columns in a very professional way and with just few lines of code.
Some of the most valuable players in Intrinio financial data are the financial statements, covered exchanges, accessibility, and fast server response, as we have tested. It took one second or less to get a response from the data servers to see the AMD adjusted closing price and volume at the moment of the call.
Intrinio US Core Market Data includes features for real-time and historical pricing, and data components such as the "adjusted_close" so we can plot a more accurate chart or test. We can also build stock trading algorithms and manipulate the data with Python libraries such as Pandas and Backtrader. If you haven't already, start by signing up for a free Intrinio account.
Enjoy and thanks for reading.