{"id":1772,"date":"2023-08-29T08:08:07","date_gmt":"2023-08-29T08:08:07","guid":{"rendered":"https:\/\/eodhd.com\/financial-academy\/?p=1772"},"modified":"2024-03-14T07:30:47","modified_gmt":"2024-03-14T07:30:47","slug":"algorithmic-trading-with-the-disparity-index-in-python","status":"publish","type":"post","link":"https:\/\/eodhd.com\/financial-academy\/fundamental-analysis-examples\/algorithmic-trading-with-the-disparity-index-in-python","title":{"rendered":"Algorithmic Trading with the Disparity Index in Python"},"content":{"rendered":"\n<p><\/p>\n\n\n\n<p>There is an extensive amount of technical indicators out there for trading purposes, but traders being so picky will end up choosing only a handful of them, and the indicator we are going to discuss today definitely adds to this list. Behold the&nbsp;Disparity Index.&nbsp;In this article, we will first discuss what the Disparity Index is all about, the math behind the indicator, and then we will move on to the coding part where we will use Python to first build the indicator from scratch, construct a simple trading strategy based on it, backtest the strategy on the Apple stock and compare the returns to those of the SPY ETF (an ETF designed to track the movements of the S&amp;P 500 market index).<\/p>\n\n\n\n\n\n\n<h1 class=\"wp-block-heading\" id=\"15bc\">Disparity Index<\/h1>\n\n\n\n<p id=\"881b\">The Disparity Index is a momentum indicator that measures the distance between the current closing price of a stock and its moving average for a specified number of periods and interprets the readings in the form of percentages. Unlike other momentum oscillators, the Disparity Index is not bound between certain levels and hence is an unbounded oscillator.<\/p>\n\n\n\n<p id=\"3eb4\">Traders often use the Disparity Index to determine the current momentum of a market. Upward momentum in the market can be observed if the readings of the Disparity Index are above zero, and similarly, the market is considered to be in a downward momentum if the readings of the indicator are below zero.<\/p>\n\n\n\n<p id=\"d5a9\">The calculation of the Disparity Index is pretty much straightforward. First, we have to find the difference between the closing of the price of a stock and the moving average for a specified number of periods and divide the difference by the moving average, then multiply it by 100. The calculation of the Disparity Index with a typical setting of 14 as the lookback period can be represented as follows:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-background\" style=\"background-color:#abb7c217\"><strong>DI 14<\/strong> = [ <strong>C.PRICE<\/strong> - <strong>MOVING  AVG 14<\/strong> ] \/ [ <strong>MOVING AVG 14<\/strong> ] * <strong>100<\/strong>\n\nwhere,\nDI 14 = 14-day Disparity Index\nMOVING AVG 14 = 14-day Moving Average\nC.PRICE = Closing price of the stock<\/pre>\n\n\n\n<p id=\"05f8\">That\u2019s the whole process of calculating the readings of the Disparity Index. Now, let\u2019s analyze a chart where Apple&#8217;s closing price data is plotted along with its 14-day Disparity Index.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1805\" height=\"884\" src=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/08\/image-29.png\" alt=\"\" class=\"wp-image-1774\"\/><\/figure>\n\n\n\n<p id=\"8fc8\">The above chart is separated into two panels: the upper panel with the closing prices of Apple and the lower panel with the readings of the 14-day Disparity Index. From the above chart, we can see that whenever the readings of the Disparity Index are above the zero-line, a green-colored histogram is plotted representing a positive or an upward momentum in the market, and similarly, whenever the Disparity Index goes below the zero-line, a red-colored histogram is plotted representing a negative or downward momentum. This is one way of using the Disparity Index. The other way traders use this indicator is to detect ranging markets (markets where the prices oscillate back and forth between certain limits showing neither positive nor negative price movements). Sometimes, it can be seen that the bars of the Disparity Index go back and forth on either side of the zero line indicating the market is ranging or consolidating. This feature of the indicator comes in handy to traders while making trades (for me personally).<\/p>\n\n\n\n<p id=\"fc89\">To my knowledge, there are two trading strategies based on the Disparity Index. The first one is the Breakout strategy where traders assume two extreme levels plotted on either side of the plot, and this strategy reveals a buy signal whenever the Disparity Index goes below the lower level, similarly, a sell signal is generated whenever the Disparity Index touches above the upper level. These thresholds vary from one asset to another since the Disparity Index is an unbounded oscillator. The second one is the Zero-line cross strategy which reveals a buy signal whenever the Disparity Index goes from below to above the zero-line, and a sell signal is generated whenever the Disparity Index goes from above to below the zero-line.<\/p>\n\n\n\n<p id=\"1ef0\">In this article, we are going to implement the second strategy which is the Zero-line cross strategy but since the Disparity Index is prone to revealing a lot of false signals, we are going to tune the traditional crossover strategy. Our tuned strategy reveals a buy signal only if the past four readings are below the zero-line and the current reading is above the zero-line. Similarly, a sell signal is generated only if the past four readings are above the zero-line and the current reading is below the zero-line. Doing this would drastically reduce the number of false signals generated by the strategy and thus boost its performance. Our tuned Zero-line crossover trading strategy can be represented as follows:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-background\" style=\"background-color:#abb7c217\">IF <strong>PREV.4 DIs<\/strong> &lt; <strong>ZERO-LINE <\/strong>AND <strong>CURR.DI<\/strong> &gt; <strong>ZERO-LINE<\/strong> ==&gt; <strong>BUY SIGNAL<\/strong><br>IF <strong>PREV.4 DIs<\/strong> &gt; <strong>ZERO-LINE<\/strong> AND <strong>CURR.DI<\/strong> &lt; <strong>ZERO-LINE<\/strong> ==&gt; <strong>SELL SIGNAL<\/strong><\/pre>\n\n\n\n<p id=\"f4f1\">This concludes our theory part on the Disparity Index. Now, let\u2019s move on to the programming part where we are first going to build the indicator from scratch, build the tuned Zero-line crossover strategy which we just discussed, then, compare our strategy\u2019s performance with that of SPY ETF in Python. Let\u2019s do some coding!&nbsp;<strong>Before moving on, a note on disclaimer: This article\u2019s sole purpose is to educate people and must be considered as an information piece but not as investment advice.<\/strong><\/p>\n\n\n\n<p class=\"has-text-align-center\"><a class=\"maxbutton-1 maxbutton maxbutton-subscribe-to-api external-css btn\" href=\"https:\/\/eodhd.com\/register\"><span class='mb-text'>Register &amp; Get Data<\/span><\/a><\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"6c3d\">Implementation in Python<\/h1>\n\n\n\n<p id=\"f130\">The coding part is classified into various steps as follows:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-background\" style=\"background-color:#abb7c217\"><strong>1. Importing Packages\n2. Extracting Stock Data from EODHD\n3. Disparity Index Calculation\n4. Creating the Tuned Zero-line Crossover Trading Strategy\n5. Plotting the Trading Lists\n6. Creating our Position\n7. Backtesting\n8. SPY ETF Comparison<\/strong><\/pre>\n\n\n\n<p id=\"efd7\">We will be following the order mentioned in the above list, so buckle up your seatbelts to follow every upcoming coding part.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"2faa\">Step-1: Importing Packages<\/h2>\n\n\n\n<p id=\"946d\">Importing the required packages into the Python environment is a non-skippable step. The primary packages are going to be Pandas to work with data, NumPy to work with arrays and for complex functions, Matplotlib for plotting purposes, and Requests to make API calls. The secondary packages are going to be Math for mathematical functions and Termcolor for font customization (optional).<\/p>\n\n\n\n<p id=\"2f4e\"><strong>Python Implementation:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-white-color has-black-background-color has-text-color has-background\"><strong># IMPORTING PACKAGES<br><\/strong><br>import numpy as np<br>import requests<br>import pandas as pd<br>import matplotlib.pyplot as plt<br>from math import floor<br>from termcolor import colored as cl<br><br>plt.style.use('fivethirtyeight')<br>plt.rcParams['figure.figsize'] = (20,10)<\/pre>\n\n\n\n<p id=\"a48e\">With the required packages imported into Python, we can proceed to fetch historical data for Apple using EODHD&#8217;s OHLC split-adjusted data API endpoint.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"c6f6\">Step-2: Extracting data from Twelve Data<\/h2>\n\n\n\n<p id=\"cdbc\">In this phase, we&#8217;re set to retrieve the historical stock data for Apple using the <a href=\"https:\/\/eodhd.com\/financial-apis\/technical-indicators-api\/#Split_Adjusted_Data\" target=\"_blank\" rel=\"noreferrer noopener\">OHLC split-adjusted API endpoint<\/a> provided by&nbsp;<a href=\"https:\/\/eodhd.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">EODHD<\/a>. It&#8217;s important to note that&nbsp;<a href=\"https:\/\/eodhd.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">EOD Historical Data<\/a> (EODHD) is a reliable provider of financial APIs, encompassing an extensive array of market data, including historical data and economic news. Be sure to possess an <a href=\"https:\/\/eodhd.com\/register\">EODHD account<\/a> and access your secret API key, a crucial element for data extraction via the API.<\/p>\n\n\n\n<p id=\"b990\"><strong>Python Implementation:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-white-color has-black-background-color has-text-color has-background\"># EXTRACTING STOCK DATA\n\ndef get_historical_data(symbol, start_date):\n    api_key = 'YOUR API KEY'\n    api_url = f'https:\/\/eodhistoricaldata.com\/api\/technical\/{symbol}?order=a&amp;fmt=json&amp;from={start_date}&amp;function=splitadjusted&amp;api_token={api_key}'\n    raw_df = requests.get(api_url).json()\n    df = pd.DataFrame(raw_df)\n    df.date = pd.to_datetime(df.date)\n    df = df.set_index('date')\n    return df\n\naapl = get_historical_data('AAPL', '2020-01-01')\naapl.tail()<\/pre>\n\n\n\n<p id=\"62f4\"><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"917\" height=\"457\" src=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/08\/image-30.png\" alt=\"\" class=\"wp-image-1775\"\/><\/figure>\n\n\n\n<p id=\"1ba9\"><strong>Code Explanation:<\/strong>&nbsp;We begin by defining a function named &#8216;get_historical_data,&#8217; which takes the stock symbol (&#8216;symbol&#8217;) and the start date for historical data (&#8216;start_date&#8217;) as parameters. Inside the function, we define the API key and URL, then retrieve the historical data in JSON format using the &#8216;get&#8217; function and store it in the &#8216;raw_df&#8217; variable. After cleaning and formatting the raw JSON data, we return it as a Pandas dataframe. Finally, we call this function to fetch Apple&#8217;s historical data from the start of 2020 and store it in the &#8216;aapl&#8217; variable.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"b8c7\">Step-3: Disparity Index Calculation<\/h2>\n\n\n\n<p id=\"d5b2\">In this step, we are going to calculate the readings of the Disparity Index by following the formula we discussed before.<\/p>\n\n\n\n<p id=\"3821\"><strong>Python Implementation:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-white-color has-black-background-color has-text-color has-background\"># DISPARITY INDEX CALCULATION\n\ndef get_di(data, lookback):\n    ma = data.rolling(lookback).mean()\n    di = ((data - ma) \/ ma) * 100\n    return di\n\naapl['di_14'] = get_di(aapl['close'], 14)\naapl = aapl.dropna()\naapl.tail()<\/pre>\n\n\n\n<p id=\"2643\"><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1089\" height=\"456\" src=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/08\/image-31.png\" alt=\"\" class=\"wp-image-1776\"\/><\/figure>\n\n\n\n<p id=\"3813\"><strong>Code Explanation:<\/strong>&nbsp;First, we are defining a function named \u2018get_di\u2019 that takes a stock\u2019s closing price (\u2018data\u2019) and the lookback period as parameters. Inside the function, we are first calculating the Moving Average of the closing price data for a specified number of lookback periods. Then, we substituted the determined values into the Disparity Index formula to calculate the readings. Finally, we are returning and calling the created function to store the 14-day Disparity Index readings of Apple.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"6f17\">Step-4: Creating the trading strategy<\/h2>\n\n\n\n<p id=\"5255\">In this step, we are going to implement the discussed Disparity Index tuned Zero-line crossover trading strategy in Python.<\/p>\n\n\n\n<p id=\"f3e1\"><strong>Python Implementation:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-white-color has-black-background-color has-text-color has-background\"># DISPARITY INDEX STRATEGY\n\ndef implement_di_strategy(prices, di):\n    buy_price = []\n    sell_price = []\n    di_signal = []\n    signal = 0\n    \n    for i in range(len(prices)):\n        if di[i-4] &lt; 0 and di[i-3] &lt; 0 and di[i-2] &lt; 0 and di[i-1] &lt; 0 and di[i] &gt; 0:\n            if signal != 1:\n                buy_price.append(prices[i])\n                sell_price.append(np.nan)\n                signal = 1\n                di_signal.append(signal)\n            else:\n                buy_price.append(np.nan)\n                sell_price.append(np.nan)\n                di_signal.append(0)\n        elif di[i-4] &gt; 0 and di[i-3] &gt; 0 and di[i-2] &gt; 0 and di[i-1] &gt; 0 and di[i] &lt; 0:\n            if signal != -1:\n                buy_price.append(np.nan)\n                sell_price.append(prices[i])\n                signal = -1\n                di_signal.append(signal)\n            else:\n                buy_price.append(np.nan)\n                sell_price.append(np.nan)\n                di_signal.append(0)\n        else:\n            buy_price.append(np.nan)\n            sell_price.append(np.nan)\n            di_signal.append(0)\n            \n    return buy_price, sell_price, di_signal\n\nbuy_price, sell_price, di_signal = implement_di_strategy(aapl['close'], aapl['di_14'])<\/pre>\n\n\n\n<p id=\"ac56\"><strong>Code Explanation:<\/strong>&nbsp;First, we are defining a function named \u2018implement_di_strategy\u2019 which takes the stock prices (\u2018prices\u2019), and the readings of the Disparity Index (\u2018di\u2019) as parameters.<\/p>\n\n\n\n<p id=\"9210\">Inside the function, we are creating three empty lists (buy_price, sell_price, and di_signal) in which the values will be appended while creating the trading strategy.<\/p>\n\n\n\n<p id=\"4910\">After that, we are implementing the trading strategy through a for-loop. Inside the for-loop, we are passing certain conditions, and if the conditions are satisfied, the respective values will be appended to the empty lists. If the condition to buy the stock is satisfied, the buying price will be appended to the \u2018buy_price\u2019 list, and the signal value will be appended as 1 representing to buy the stock. Similarly, if the condition to sell the stock is satisfied, the selling price will be appended to the \u2018sell_price\u2019 list, and the signal value will be appended as -1 representing to sell the stock.<\/p>\n\n\n\n<p id=\"98a5\">Finally, we are returning the lists appended with values. Then, we call the created function and store the values in their respective variables. The list doesn\u2019t make any sense unless we plot the values. So, let\u2019s plot the values of the created trading lists.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"f20c\">Step-5: Plotting the trading signals<\/h2>\n\n\n\n<p id=\"f57d\">In this step, we are going to plot the created trading lists to make sense of them.<\/p>\n\n\n\n<p id=\"978d\"><strong>Python Implementation:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-white-color has-black-background-color has-text-color has-background\"># DISPARITY INDEX TRADING SIGNALS PLOT\n\nax1 = plt.subplot2grid((11,1), (0,0), rowspan = 5, colspan = 1)\nax2 = plt.subplot2grid((11,1), (6,0), rowspan = 5, colspan = 1)\nax1.plot(aapl['close'], linewidth = 2, color = '#1976d2')\nax1.plot(aapl.index, buy_price, marker = '^', markersize = 12, linewidth = 0, label = 'BUY SIGNAL', color = 'green')\nax1.plot(aapl.index, sell_price, marker = 'v', markersize = 12, linewidth = 0, label = 'SELL SIGNAL', color = 'r')\nax1.legend()\nax1.set_title('AAPL CLOSING PRICES')\nfor i in range(len(aapl)):\n    if aapl.iloc[i, 5] &gt;= 0:\n        ax2.bar(aapl.iloc[i].name, aapl.iloc[i, 5], color = '#26a69a')\n    else:    \n        ax2.bar(aapl.iloc[i].name, aapl.iloc[i, 5], color = '#ef5350')\nax2.set_title('AAPL DISPARITY INDEX 14')\nplt.show()<\/pre>\n\n\n\n<p id=\"c860\"><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1805\" height=\"884\" src=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/08\/image-32.png\" alt=\"\" class=\"wp-image-1777\"\/><\/figure>\n\n\n\n<p id=\"b698\"><strong>Code Explanation:<\/strong>&nbsp;We are plotting the readings of the Disparity Index along with the buy and sell signals generated by the tuned Zer-line crossover trading strategy. We can observe that whenever the previous four readings of the Disparity Index are below the zero-line and the current reading is above the zero-line, a green-colored buy signal is plotted in the chart. Similarly, whenever the previous four readings of the Disparity Index are above the zero-line and the current reading is below the zero-line, a red-colored sell signal is plotted in the chart.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"15b1\">Step-6: Creating our Position<\/h2>\n\n\n\n<p id=\"733c\">In this step, we are going to create a list that indicates 1 if we hold the stock or 0 if we don\u2019t own or hold the stock.<\/p>\n\n\n\n<p id=\"f381\"><strong>Python Implementation:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-white-color has-black-background-color has-text-color has-background\"># STOCK POSITION\n\nposition = []\nfor i in range(len(di_signal)):\n    if di_signal[i] &gt; 1:\n        position.append(0)\n    else:\n        position.append(1)\n        \nfor i in range(len(aapl['close'])):\n    if di_signal[i] == 1:\n        position[i] = 1\n    elif di_signal[i] == -1:\n        position[i] = 0\n    else:\n        position[i] = position[i-1]\n        \nclose_price = aapl['close']\ndi = aapl['di_14']\ndi_signal = pd.DataFrame(di_signal).rename(columns = {0:'di_signal'}).set_index(aapl.index)\nposition = pd.DataFrame(position).rename(columns = {0:'di_position'}).set_index(aapl.index)\n\nframes = [close_price, di, di_signal, position]\nstrategy = pd.concat(frames, join = 'inner', axis = 1)\n\nstrategy.head()<\/pre>\n\n\n\n<p id=\"e051\"><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"860\" height=\"465\" src=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/08\/image-33.png\" alt=\"\" class=\"wp-image-1778\"\/><\/figure>\n\n\n\n<p id=\"68c4\"><strong>Code Explanation:<\/strong>&nbsp;First, we are creating an empty list named \u2018position\u2019. We are passing two for-loops, one is to generate values for the \u2018position\u2019 list to just match the length of the \u2018signal\u2019 list. The other for-loop is the one we are using to generate actual position values. Inside the second for-loop, we are iterating over the values of the \u2018signal\u2019 list, and the values of the \u2018position\u2019 list get appended concerning which condition gets satisfied. The value of the position remains 1 if we hold the stock or remains 0 if we sold or don\u2019t own the stock. Finally, we are doing some data manipulations to combine all the created lists into one dataframe.<\/p>\n\n\n\n<p id=\"fe2d\">From the output being shown, we can see that in the first three rows, our position in the stock has remained 1 (since there isn\u2019t any change in the Disparity Index signal) but our position suddenly turned to -1 as we sold the stock when the Disparity Index trading signal represents a sell signal (-1). Our position will remain 0 until some changes in the trading signal occur. Now it\u2019s time to implement some backtesting process!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"0a56\">Step-7: Backtesting<\/h2>\n\n\n\n<p id=\"4215\">Before moving on, it is essential to know what backtesting is. Backtesting is the process of seeing how well our trading strategy has performed on the given stock data. In our case, we are going to implement a backtesting process for our Disparity Index trading strategy over the Apple stock data.<\/p>\n\n\n\n<p id=\"e44c\"><strong>Python Implementation:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-white-color has-black-background-color has-text-color has-background\"># BACKTESTING\n\naapl_ret = pd.DataFrame(np.diff(aapl['close'])).rename(columns = {0:'returns'})\ndi_strategy_ret = []\n\nfor i in range(len(aapl_ret)):\n    returns = aapl_ret['returns'][i]*strategy['di_position'][i]\n    di_strategy_ret.append(returns)\n    \ndi_strategy_ret_df = pd.DataFrame(di_strategy_ret).rename(columns = {0:'di_returns'})\ninvestment_value = 100000\ndi_investment_ret = []\n\nfor i in range(len(di_strategy_ret_df['di_returns'])):\n    number_of_stocks = floor(investment_value\/aapl['close'][i])\n    returns = number_of_stocks*di_strategy_ret_df['di_returns'][i]\n    di_investment_ret.append(returns)\n\ndi_investment_ret_df = pd.DataFrame(di_investment_ret).rename(columns = {0:'investment_returns'})\ntotal_investment_ret = round(sum(di_investment_ret_df['investment_returns']), 2)\nprofit_percentage = floor((total_investment_ret\/investment_value)*100)\nprint(cl('Profit gained from the DI strategy by investing $100k in aapl : {}'.format(total_investment_ret), attrs = ['bold']))\nprint(cl('Profit percentage of the DI strategy : {}%'.format(profit_percentage), attrs = ['bold']))<\/pre>\n\n\n\n<p id=\"d968\"><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-background\" style=\"background-color:#abb7c217\"><strong>Profit gained from the DI strategy by investing $100k in AAPL : 105467.66\nProfit percentage of the DI strategy : 105%<\/strong><\/pre>\n\n\n\n<p id=\"dc5d\"><strong>Code Explanation:<\/strong>&nbsp;First, we are calculating the returns of the Apple stock using the \u2018diff\u2019 function provided by the NumPy package and we have stored it as a dataframe in the \u2018aapl_ret\u2019 variable. Next, we are passing a for-loop to iterate over the values of the \u2018aapl_ret\u2019 variable to calculate the returns we gained from our Disparity Index trading strategy, and these returns values are appended to the \u2018di_strategy_ret\u2019 list. Next, we are converting the \u2018di_strategy_ret\u2019 list into a dataframe and storing it into the \u2018di_strategy_ret_df\u2019 variable.<\/p>\n\n\n\n<p id=\"6a41\">Next comes the backtesting process. We are going to backtest our strategy by investing a hundred thousand USD into our trading strategy. So first, we are storing the amount of investment into the \u2018investment_value\u2019 variable. After that, we are calculating the number of Apple stocks we can buy using the investment amount. You can notice that I\u2019ve used the \u2018floor\u2019 function provided by the Math package because, while dividing the investment amount by the closing price of Apple stock, it spits out an output with decimal numbers. The number of stocks should be an integer but not a decimal number. Using the \u2018floor\u2019 function, we can cut out the decimals. Remember that the \u2018floor\u2019 function is way more complex than the \u2018round\u2019 function. Then, we are passing a for-loop to find the investment returns followed by some data manipulation tasks.<\/p>\n\n\n\n<p id=\"1ca5\">Finally, we are printing the total return we got by investing a hundred thousand into our trading strategy and it is revealed that we have made an approximate profit of one hundred and five thousand USD in one year. That\u2019s not bad at all! Now, let\u2019s compare our returns with SPY ETF (an ETF designed to track the S&amp;P 500 stock market index) returns.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"d7b3\">Step-8: SPY ETF Comparison<\/h2>\n\n\n\n<p>While this step is optional, it is highly recommended as it enables us to assess the performance of our trading strategy against a benchmark (SPY ETF). Here, we&#8217;ll extract SPY ETF data using the &#8216;get_historical_data&#8217; function and compare the returns from the SPY ETF with the returns generated by our trading strategy applied to Apple stock.<\/p>\n\n\n\n<p id=\"cd91\"><strong>Python Implementation:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-white-color has-black-background-color has-text-color has-background\"># SPY ETF COMPARISON\n\ndef get_benchmark(start_date, investment_value):\n    spy = get_historical_data('SPY', start_date)['close']\n    benchmark = pd.DataFrame(np.diff(spy)).rename(columns = {0:'benchmark_returns'})\n    \n    investment_value = investment_value\n    benchmark_investment_ret = []\n    \n    for i in range(len(benchmark['benchmark_returns'])):\n        number_of_stocks = floor(investment_value\/spy[i])   \n        returns = number_of_stocks*benchmark['benchmark_returns'][i]\n        benchmark_investment_ret.append(returns)\n\n    benchmark_investment_ret_df = pd.DataFrame(benchmark_investment_ret).rename(columns = {0:'investment_returns'})\n    return benchmark_investment_ret_df\n\nbenchmark = get_benchmark('2020-01-01', 100000)\ninvestment_value = 100000\ntotal_benchmark_investment_ret = round(sum(benchmark['investment_returns']), 2)\nbenchmark_profit_percentage = floor((total_benchmark_investment_ret\/investment_value)*100)\nprint(cl('Benchmark profit by investing $100k : {}'.format(total_benchmark_investment_ret), attrs = ['bold']))\nprint(cl('Benchmark Profit percentage : {}%'.format(benchmark_profit_percentage), attrs = ['bold']))\nprint(cl('DI Strategy profit is {}% higher than the Benchmark Profit'.format(profit_percentage - benchmark_profit_percentage), attrs = ['bold']))<\/pre>\n\n\n\n<p id=\"864d\"><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-background\" style=\"background-color:#abb7c217\"><strong>Benchmark profit by investing $100k : 40344.61\nBenchmark Profit percentage : 40%\nDI Strategy profit is 65% higher than the Benchmark Profit<\/strong><\/pre>\n\n\n\n<p id=\"3594\"><strong>Code Explanation:<\/strong>&nbsp;The code used in this step is almost similar to the one used in the previous backtesting step but, instead of investing in Apple, we are investing in SPY ETF by not implementing any trading strategies. From the output, we can see that our Disparity Index tuned zero-line crossover trading strategy has outperformed the SPY ETF by 65%. That\u2019s great!<\/p>\n\n\n\n<p class=\"has-text-align-center\"><a class=\"maxbutton-1 maxbutton maxbutton-subscribe-to-api external-css btn\" href=\"https:\/\/eodhd.com\/register\"><span class='mb-text'>Register &amp; Get Data<\/span><\/a><\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"bb44\">Final Thoughts!<\/h1>\n\n\n\n<p id=\"08ee\">After an exhaustive process of crushing both theory and programming parts, we have successfully learned what the Disparity Index is all about, the mathematics behind it, and finally, how to build the indicator from scratch and construct a tuned zero-line crossover trading strategy based on it with Python. Even though we managed to build a strategy that makes a profit, there are still a lot of spaces where this article can be improved and one such important space is constructing a more realistic strategy.<\/p>\n\n\n\n<p id=\"b20b\">The procedures, steps, and code we implemented in this article can be suitable for virtual trading but the real-world market doesn&#8217;t behave the same way and to thrive in such conditions, it is essential to build our strategy by considering more external factors like risks involved in each trade, commission or fees charged for each transaction, and most importantly market sentiment.<\/p>\n\n\n\n<p id=\"7559\">The process isn&#8217;t finished even after building a realistic strategy, but it is necessary to know whether the strategy is even a profitable one or just a waste of time. In order to determine the profitability and the performance of the strategy, one has to backtest and evaluate it with various metrics. And this would be the next space where the article can be improved.<\/p>\n\n\n\n<p id=\"3104\">If you\u2019re done with these improvisations, you\u2019re set to apply them in the real-world market and the certainty of you being profitable is high. With that being said, you\u2019ve reached the end of the article. Hope you learned something new and useful from this article.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There is an extensive amount of technical indicators out there for trading purposes, but traders being so picky will end up choosing only a handful of them, and the indicator we are going to discuss today definitely adds to this list. Behold the&nbsp;Disparity Index.&nbsp;In this article, we will first discuss what the Disparity Index is [&hellip;]<\/p>\n","protected":false},"author":18,"featured_media":1773,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[],"coding-language":[30],"ready-to-go-solution":[],"qualification":[31,32],"financial-apis-category":[36],"financial-apis-manuals":[39,40],"class_list":["post-1772","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-fundamental-analysis-examples","coding-language-python","qualification-experienced","qualification-guru","financial-apis-category-stock-market-prices","financial-apis-manuals-end-of-day","financial-apis-manuals-technical-indicators","has_thumb"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.9 (Yoast SEO v26.7) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Algorithmic Trading Disparity Index Python| EODHD APIs Academy<\/title>\n<meta name=\"description\" content=\"Discover the Disparity Index and its role in algorithmic trading. Code it in Python to analyze the Apple stock and compare returns to the SPY ETF\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/eodhd.com\/financial-academy\/fundamental-analysis-examples\/algorithmic-trading-with-the-disparity-index-in-python\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Algorithmic Trading with the Disparity Index in Python\" \/>\n<meta property=\"og:description\" content=\"Discover the Disparity Index and its role in algorithmic trading. Code it in Python to analyze the Apple stock and compare returns to the SPY ETF\" \/>\n<meta property=\"og:url\" content=\"https:\/\/eodhd.com\/financial-academy\/fundamental-analysis-examples\/algorithmic-trading-with-the-disparity-index-in-python\" \/>\n<meta property=\"og:site_name\" content=\"Financial Academy\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/eodhistoricaldata\" \/>\n<meta property=\"article:published_time\" content=\"2023-08-29T08:08:07+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-03-14T07:30:47+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/08\/image-28.png\" \/>\n\t<meta property=\"og:image:width\" content=\"828\" \/>\n\t<meta property=\"og:image:height\" content=\"552\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Nikhil Adithyan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@EOD_data\" \/>\n<meta name=\"twitter:site\" content=\"@EOD_data\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Nikhil Adithyan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"13 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/fundamental-analysis-examples\/algorithmic-trading-with-the-disparity-index-in-python#article\",\"isPartOf\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/fundamental-analysis-examples\/algorithmic-trading-with-the-disparity-index-in-python\"},\"author\":{\"name\":\"Nikhil Adithyan\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#\/schema\/person\/67681e71050cf7d8d0efb91fee5f0402\"},\"headline\":\"Algorithmic Trading with the Disparity Index in Python\",\"datePublished\":\"2023-08-29T08:08:07+00:00\",\"dateModified\":\"2024-03-14T07:30:47+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/fundamental-analysis-examples\/algorithmic-trading-with-the-disparity-index-in-python\"},\"wordCount\":2592,\"publisher\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#organization\"},\"image\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/fundamental-analysis-examples\/algorithmic-trading-with-the-disparity-index-in-python#primaryimage\"},\"thumbnailUrl\":\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/08\/image-28.png\",\"articleSection\":[\"Fundamental Analysis Examples\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/fundamental-analysis-examples\/algorithmic-trading-with-the-disparity-index-in-python\",\"url\":\"https:\/\/eodhd.com\/financial-academy\/fundamental-analysis-examples\/algorithmic-trading-with-the-disparity-index-in-python\",\"name\":\"Algorithmic Trading Disparity Index Python| EODHD APIs Academy\",\"isPartOf\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/fundamental-analysis-examples\/algorithmic-trading-with-the-disparity-index-in-python#primaryimage\"},\"image\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/fundamental-analysis-examples\/algorithmic-trading-with-the-disparity-index-in-python#primaryimage\"},\"thumbnailUrl\":\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/08\/image-28.png\",\"datePublished\":\"2023-08-29T08:08:07+00:00\",\"dateModified\":\"2024-03-14T07:30:47+00:00\",\"description\":\"Discover the Disparity Index and its role in algorithmic trading. Code it in Python to analyze the Apple stock and compare returns to the SPY ETF\",\"breadcrumb\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/fundamental-analysis-examples\/algorithmic-trading-with-the-disparity-index-in-python#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/eodhd.com\/financial-academy\/fundamental-analysis-examples\/algorithmic-trading-with-the-disparity-index-in-python\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/fundamental-analysis-examples\/algorithmic-trading-with-the-disparity-index-in-python#primaryimage\",\"url\":\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/08\/image-28.png\",\"contentUrl\":\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/08\/image-28.png\",\"width\":828,\"height\":552,\"caption\":\"Algorithmic Trading with the Disparity Index in Python\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/fundamental-analysis-examples\/algorithmic-trading-with-the-disparity-index-in-python#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/eodhd.com\/financial-academy\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Algorithmic Trading with the Disparity Index in Python\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#website\",\"url\":\"https:\/\/eodhd.com\/financial-academy\/\",\"name\":\"Financial APIs Academy | EODHD\",\"description\":\"Financial Stock Market Academy\",\"publisher\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/eodhd.com\/financial-academy\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#organization\",\"name\":\"EODHD (EOD Historical Data)\",\"url\":\"https:\/\/eodhd.com\/financial-academy\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/12\/EODHD-Logo.png\",\"contentUrl\":\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/12\/EODHD-Logo.png\",\"width\":159,\"height\":82,\"caption\":\"EODHD (EOD Historical Data)\"},\"image\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/eodhistoricaldata\",\"https:\/\/x.com\/EOD_data\",\"https:\/\/www.reddit.com\/r\/EODHistoricalData\/\",\"https:\/\/eod-historical-data.medium.com\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#\/schema\/person\/67681e71050cf7d8d0efb91fee5f0402\",\"name\":\"Nikhil Adithyan\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/eb53ce41bde412555cee22b8b4c09c2ff51625fff05ba3696b20cac7a7c0d938?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/eb53ce41bde412555cee22b8b4c09c2ff51625fff05ba3696b20cac7a7c0d938?s=96&d=mm&r=g\",\"caption\":\"Nikhil Adithyan\"},\"description\":\"Founder at BacktestZone | Streamlit Student Ambassador | FinTech &amp; Quantitative Finance enthusiast\",\"url\":\"https:\/\/eodhd.com\/financial-academy\/author\/nikhiladithyan\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Algorithmic Trading Disparity Index Python| EODHD APIs Academy","description":"Discover the Disparity Index and its role in algorithmic trading. Code it in Python to analyze the Apple stock and compare returns to the SPY ETF","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/eodhd.com\/financial-academy\/fundamental-analysis-examples\/algorithmic-trading-with-the-disparity-index-in-python","og_locale":"en_US","og_type":"article","og_title":"Algorithmic Trading with the Disparity Index in Python","og_description":"Discover the Disparity Index and its role in algorithmic trading. Code it in Python to analyze the Apple stock and compare returns to the SPY ETF","og_url":"https:\/\/eodhd.com\/financial-academy\/fundamental-analysis-examples\/algorithmic-trading-with-the-disparity-index-in-python","og_site_name":"Financial Academy","article_publisher":"https:\/\/www.facebook.com\/eodhistoricaldata","article_published_time":"2023-08-29T08:08:07+00:00","article_modified_time":"2024-03-14T07:30:47+00:00","og_image":[{"width":828,"height":552,"url":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/08\/image-28.png","type":"image\/png"}],"author":"Nikhil Adithyan","twitter_card":"summary_large_image","twitter_creator":"@EOD_data","twitter_site":"@EOD_data","twitter_misc":{"Written by":"Nikhil Adithyan","Est. reading time":"13 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/eodhd.com\/financial-academy\/fundamental-analysis-examples\/algorithmic-trading-with-the-disparity-index-in-python#article","isPartOf":{"@id":"https:\/\/eodhd.com\/financial-academy\/fundamental-analysis-examples\/algorithmic-trading-with-the-disparity-index-in-python"},"author":{"name":"Nikhil Adithyan","@id":"https:\/\/eodhd.com\/financial-academy\/#\/schema\/person\/67681e71050cf7d8d0efb91fee5f0402"},"headline":"Algorithmic Trading with the Disparity Index in Python","datePublished":"2023-08-29T08:08:07+00:00","dateModified":"2024-03-14T07:30:47+00:00","mainEntityOfPage":{"@id":"https:\/\/eodhd.com\/financial-academy\/fundamental-analysis-examples\/algorithmic-trading-with-the-disparity-index-in-python"},"wordCount":2592,"publisher":{"@id":"https:\/\/eodhd.com\/financial-academy\/#organization"},"image":{"@id":"https:\/\/eodhd.com\/financial-academy\/fundamental-analysis-examples\/algorithmic-trading-with-the-disparity-index-in-python#primaryimage"},"thumbnailUrl":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/08\/image-28.png","articleSection":["Fundamental Analysis Examples"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/eodhd.com\/financial-academy\/fundamental-analysis-examples\/algorithmic-trading-with-the-disparity-index-in-python","url":"https:\/\/eodhd.com\/financial-academy\/fundamental-analysis-examples\/algorithmic-trading-with-the-disparity-index-in-python","name":"Algorithmic Trading Disparity Index Python| EODHD APIs Academy","isPartOf":{"@id":"https:\/\/eodhd.com\/financial-academy\/#website"},"primaryImageOfPage":{"@id":"https:\/\/eodhd.com\/financial-academy\/fundamental-analysis-examples\/algorithmic-trading-with-the-disparity-index-in-python#primaryimage"},"image":{"@id":"https:\/\/eodhd.com\/financial-academy\/fundamental-analysis-examples\/algorithmic-trading-with-the-disparity-index-in-python#primaryimage"},"thumbnailUrl":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/08\/image-28.png","datePublished":"2023-08-29T08:08:07+00:00","dateModified":"2024-03-14T07:30:47+00:00","description":"Discover the Disparity Index and its role in algorithmic trading. Code it in Python to analyze the Apple stock and compare returns to the SPY ETF","breadcrumb":{"@id":"https:\/\/eodhd.com\/financial-academy\/fundamental-analysis-examples\/algorithmic-trading-with-the-disparity-index-in-python#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/eodhd.com\/financial-academy\/fundamental-analysis-examples\/algorithmic-trading-with-the-disparity-index-in-python"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/eodhd.com\/financial-academy\/fundamental-analysis-examples\/algorithmic-trading-with-the-disparity-index-in-python#primaryimage","url":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/08\/image-28.png","contentUrl":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/08\/image-28.png","width":828,"height":552,"caption":"Algorithmic Trading with the Disparity Index in Python"},{"@type":"BreadcrumbList","@id":"https:\/\/eodhd.com\/financial-academy\/fundamental-analysis-examples\/algorithmic-trading-with-the-disparity-index-in-python#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/eodhd.com\/financial-academy\/"},{"@type":"ListItem","position":2,"name":"Algorithmic Trading with the Disparity Index in Python"}]},{"@type":"WebSite","@id":"https:\/\/eodhd.com\/financial-academy\/#website","url":"https:\/\/eodhd.com\/financial-academy\/","name":"Financial APIs Academy | EODHD","description":"Financial Stock Market Academy","publisher":{"@id":"https:\/\/eodhd.com\/financial-academy\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/eodhd.com\/financial-academy\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/eodhd.com\/financial-academy\/#organization","name":"EODHD (EOD Historical Data)","url":"https:\/\/eodhd.com\/financial-academy\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/eodhd.com\/financial-academy\/#\/schema\/logo\/image\/","url":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/12\/EODHD-Logo.png","contentUrl":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/12\/EODHD-Logo.png","width":159,"height":82,"caption":"EODHD (EOD Historical Data)"},"image":{"@id":"https:\/\/eodhd.com\/financial-academy\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/eodhistoricaldata","https:\/\/x.com\/EOD_data","https:\/\/www.reddit.com\/r\/EODHistoricalData\/","https:\/\/eod-historical-data.medium.com\/"]},{"@type":"Person","@id":"https:\/\/eodhd.com\/financial-academy\/#\/schema\/person\/67681e71050cf7d8d0efb91fee5f0402","name":"Nikhil Adithyan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/eodhd.com\/financial-academy\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/eb53ce41bde412555cee22b8b4c09c2ff51625fff05ba3696b20cac7a7c0d938?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/eb53ce41bde412555cee22b8b4c09c2ff51625fff05ba3696b20cac7a7c0d938?s=96&d=mm&r=g","caption":"Nikhil Adithyan"},"description":"Founder at BacktestZone | Streamlit Student Ambassador | FinTech &amp; Quantitative Finance enthusiast","url":"https:\/\/eodhd.com\/financial-academy\/author\/nikhiladithyan"}]}},"jetpack_featured_media_url":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/08\/image-28.png","jetpack_shortlink":"https:\/\/wp.me\/pdOdVT-sA","jetpack_sharing_enabled":true,"acf":[],"_links":{"self":[{"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/posts\/1772","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/users\/18"}],"replies":[{"embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/comments?post=1772"}],"version-history":[{"count":15,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/posts\/1772\/revisions"}],"predecessor-version":[{"id":3079,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/posts\/1772\/revisions\/3079"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/media\/1773"}],"wp:attachment":[{"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/media?parent=1772"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/categories?post=1772"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/tags?post=1772"},{"taxonomy":"coding-language","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/coding-language?post=1772"},{"taxonomy":"ready-to-go-solution","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/ready-to-go-solution?post=1772"},{"taxonomy":"qualification","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/qualification?post=1772"},{"taxonomy":"financial-apis-category","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/financial-apis-category?post=1772"},{"taxonomy":"financial-apis-manuals","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/financial-apis-manuals?post=1772"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}