{"id":1726,"date":"2023-08-29T14:53:18","date_gmt":"2023-08-29T14:53:18","guid":{"rendered":"https:\/\/eodhd.com\/financial-academy\/?p=1726"},"modified":"2024-03-12T12:20:19","modified_gmt":"2024-03-12T12:20:19","slug":"the-coppock-curve-coding-and-backtesting-a-trading-strategy-in-python","status":"publish","type":"post","link":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/the-coppock-curve-coding-and-backtesting-a-trading-strategy-in-python","title":{"rendered":"The Coppock Curve \u2014 Coding and Backtesting a Trading Strategy in Python"},"content":{"rendered":"\n<p>In today\u2019s article, we are going to discuss an indicator that is specifically dedicated to long-term trading purposes \u2014 the Coppock Curve. We will first discuss the concepts that are prerequisites for the Coppock Curve. Then, we will move on to exploring the main concept of the Coppock Curve, and the math behind the indicator. After that, we will proceed to the coding part where we will use Python to build the indicator from scratch, construct a trading strategy based on it, backtest the strategy, and compare the results with those of the SPY ETF (an ETF specifically designed to track the movement of the S&amp;P 500 market index). With that being said, let\u2019s dive into the article.<\/p>\n\n\n\n\n\n\n<h1 class=\"wp-block-heading\" id=\"e075\">ROC and WMA<\/h1>\n\n\n\n<p id=\"da15\">The prerequisites for&nbsp;the Coppock Curve&nbsp;are&nbsp;the Rate Of Change (ROC) and the Weighted Moving Average (WMA). Without having some knowledge of these concepts, it will be tough to learn the Coppock Curve.<\/p>\n\n\n\n<p id=\"a4cb\">First is the ROC indicator. The Rate Of Change indicator is a momentum indicator that is used by traders as an instrument to determine the percentage change in price from the current closing price and the price of a specified number of periods ago.&nbsp;Unlike other momentum indicators such as the RSI and CCI, the Rate Of Change indicator is an unbounded oscillator whose values are not bound to certain limits.<\/p>\n\n\n\n<p id=\"c46a\">To calculate the readings of ROC, we have to&nbsp;first determine the \u2019n\u2019 value which is how many periods ago the current closing price is compared to. The determination of \u2019n\u2019 varies from one trader to another but the traditional setting is 9 (widely used for short-term trading). With 9 as the \u2019n\u2019 value, the readings of the ROC indicator are calculated as follows:<\/p>\n\n\n\n<p id=\"a263\">First, the closing price of 9 periods ago is subtracted from the current closing price. This difference is then divided by the closing price of 9 periods ago and multiplied by 100. The calculation can be mathematically represented as follows:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-background\" style=\"background-color:#abb7c217\"><strong>ROC 9<\/strong> = [ ( <strong>C.CLOSE <\/strong>- <strong>PREV9.CLOSE<\/strong> ) \/ <strong>PREV9.CLOSE<\/strong> ] * <strong>100<\/strong>\n\nwhere,\nC.CLOSE = Current Closing Price\nPREV9.CLOSE = Closing Price of 9 Periods ago<\/pre>\n\n\n\n<p id=\"545a\">Next is the WMA.&nbsp;One thing that bothered traders while using Simple Moving Average is that the indicator assigned equal weights to all data points present in a series. Here is where the Weighted Moving Average comes into play. To solve this problem, the&nbsp;WMA assigns greater weight (or greater importance) to the latest or the most recent data point and lesser weight to the data points in the past.&nbsp;To determine the WMA for a given series, each value is multiplied by certain weights that are predetermined, and the results are summed up.<\/p>\n\n\n\n<p id=\"8946\">Now, let\u2019s assume a series that has the past three days\u2019 closing price data whose values are 12, 13, 15 respectively. Now to calculate the WMA of these three closing prices, we need to first determine the weights which will be 1, 2, 3 and the sum of the weights is 6. Using these predetermined weights and their sum, the WMA calculation goes as follows:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-background\" style=\"background-color:#abb7c217\">[ <strong>( 15 * 3 )<\/strong> + <strong>( 13 * 2 )<\/strong> + <strong>( 12 * 1 )<\/strong> ] \/ <strong>6  <\/strong>= <strong>21.333333<\/strong><\/pre>\n\n\n\n<p id=\"33b1\">From the above calculation, you could see that we have assigned greater weights to the latest data point which is 15, and lesser weights to the past data point which is 12. Note that this is a very basic example of how weights are assigned to calculate the WMA, in the real world it\u2019s way more complex. Sometimes, the weights can also be a decimal number. <\/p>\n\n\n\n<p id=\"33b1\">That\u2019s all about ROC and WMA. Now, let\u2019s dive into the main concept of this article which is the Coppock Curve.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"0c18\">Coppock Curve<\/h1>\n\n\n\n<h2 class=\"wp-block-heading\">The Curve Basics<\/h2>\n\n\n\n<p id=\"9a42\">Founded by Edwin Coppock, the Coppock Curve is a long-term momentum indicator that is often used by traders or investors to identify uptrends and downtrends in a market. This indicator is majorly applied on market indices like the S&amp;P 500 to determine buy and sell signals but in this article, we are going to apply it to stocks and there is no restriction in doing too. Also, this indicator is designed in such a way that it is implemented on a monthly timeframe, but today we are going to try to use it on a daily timeframe.<\/p>\n\n\n\n<p id=\"0a55\">The readings of the Coppock Curve are calculated by taking the WMA of the total of two ROCs, one with a lesser and the other with a greater \u2019n\u2019 value. The typical setting to determine the Coppock Curve is 10 as the lookback period for WMA, 14 and 11 as the \u2019n\u2019 value for long and short ROC respectively. The formula to calculate the Coppock Curve with the typical setting can be represented as follows:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-background\" style=\"background-color:#abb7c217\"><strong>COPPOCK CURVE<\/strong> =<strong> WMA 10 <\/strong>[ <strong>LONG ROC <\/strong>+<strong> SHORT ROC<\/strong> ]\n\nwhere,\nWMA 10 = 10-day Weighted Moving Average\nLONG ROC = 14-period Rate Of Change\nSHORT ROC = 11-period Rate Of Change<\/pre>\n\n\n\n<p id=\"8f3f\">That\u2019s the whole process of calculating the readings of the Coppock Curve. Now, let\u2019s analyze a chart where Apple\u2019s closing price data is plotted along with its Coppock Curve.<\/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-23.png\" alt=\"\" class=\"wp-image-1729\"\/><\/figure>\n\n\n\n<p id=\"d23d\">The above chart is divided into two panels: the upper panel with the closing price data of Apple, and the lower panel with the readings of the Coppock Curve. From the above chart, it can be observed that whenever the readings of the Coppock Curve are above zero, the histogram is plotted in green color, and similarly, whenever the readings are below zero or negative, the histogram turns to red color. Now, using the histogram, we could easily spot the current trend of the market. If the histogram is plotted in green color, it represents that the market is in an uptrend, and if the histogram is plotted in red color, the market is observed to be in a downtrend. The Coppock Curve can also be used to detect ranging and trending markets but it\u2019s not its main forte.<\/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<h2 class=\"wp-block-heading\">Coppock Curve Trading Strategy<\/h2>\n\n\n\n<p id=\"178a\">Now let\u2019s discuss the trading strategy that can be built using the Coppock Curve. The foremost strategy implemented based on this indicator is the zero-line cross which reveals a buy signal whenever the Coppock Curve rises from below to above the zero-line, likewise, a sell signal is revealed whenever the Coppock Curve goes from above to below the zero-line. If zero-line sounds like a buzzword, it is just zero (0). This strategy can be represented as follows:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-background\" style=\"background-color:#abb7c217\">IF <strong>P.COPPC<\/strong> &lt; <strong>ZERO-LINE<\/strong> AND <strong>C.COPPC<\/strong> &gt; <strong>ZERO-LINE<\/strong> ==&gt; <strong>BUY SIGNAL<\/strong><br>IF <strong>P.COPPC<\/strong> &gt; <strong>ZERO-LINE <\/strong>AND <strong>C.COPPC<\/strong> &lt; <strong>ZERO-LINE<\/strong> ==&gt; <strong>SELL SIGNAL<\/strong><\/pre>\n\n\n\n<p id=\"99b6\">Directly applying this strategy might lead to catastrophic results since the Coppock Curve has two drawbacks. The first drawback of the Coppock Curve is that it is very lagging in nature. One has to be more cautious than ever while using the indicator for trading purposes. Another drawback is that the Coppock Curve is prone to revealing a lot of false signals leading us to make bad trades. In order to achieve good results, it is necessary to tune the typical zero-line cross 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. The tuned strategy can be represented as follows:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-background\" style=\"background-color:#abb7c217\">IF <strong>P.4 COPPCs<\/strong> &lt; <strong>ZERO-LINE <\/strong>AND <strong>C.COPPC <\/strong>&gt; <strong>ZERO-LINE<\/strong> ==&gt; <strong>BUY SIGNAL<\/strong><br>IF <strong>P.4 COPPCs<\/strong> &gt; <strong>ZERO-LINE<\/strong> AND <strong>C.COPPC <\/strong>&lt; <strong>ZERO-LINE<\/strong> ==&gt; <strong>SELL SIGNAL<\/strong><\/pre>\n\n\n\n<p id=\"b0e1\">This concludes our theory part on Coppock Curve. 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 or so.<\/strong><\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"9815\">Implementation in Python<\/h1>\n\n\n\n<p id=\"8f19\">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. Coppock Curve 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=\"10ce\">We will be following the order mentioned in the above list and buckle up your seat belts to follow every upcoming coding part.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"9c60\">Step-1: Importing Packages<\/h2>\n\n\n\n<p id=\"4817\">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=\"f420\"><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 requests<br>import numpy as np<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=\"f139\">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=\"f66d\">Step-2: Extracting data from EODHD<\/h2>\n\n\n\n<p id=\"89a5\">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=\"1f3d\"><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=\"2b5a\"><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"864\" height=\"461\" src=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/08\/image-24.png\" alt=\"\" class=\"wp-image-1730\"\/><\/figure>\n\n\n\n<p id=\"f157\"><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=\"2ffe\">Step-3: Coppock Curve Calculation<\/h2>\n\n\n\n<p id=\"016a\">In this step, we are going to&nbsp;calculate the readings of the Coppock Curve&nbsp;by following the formula we discussed before.<\/p>\n\n\n\n<p id=\"5cb0\"><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># COPPOCK CURVE CALCULATION<br><\/strong><br>def wma(data, lookback):<br>    weights = np.arange(1, lookback + 1)<br>    val = data.rolling(lookback)<br>    wma = val.apply(lambda prices: np.dot(prices, weights) \/ weights.sum(), raw = True)<br>    return wma<br><br>def get_roc(close, n):<br>    difference = close.diff(n)<br>    nprev_values = close.shift(n)<br>    roc = (difference \/ nprev_values) * 100<br>    return roc<br><br>def get_cc(data, roc1_n, roc2_n, wma_lookback):<br>    longROC = get_roc(data, roc1_n)<br>    shortROC = get_roc(data, roc2_n)<br>    ROC = longROC + shortROC<br>    cc = wma(ROC, wma_lookback)<br>    return cc<br><br>aapl['cc'] = get_cc(aapl['close'], 14, 11, 10)<br>aapl = aapl.dropna()<br>aapl.tail()<\/pre>\n\n\n\n<p id=\"2dca\"><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1046\" height=\"458\" src=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/08\/image-25.png\" alt=\"\" class=\"wp-image-1731\"\/><\/figure>\n\n\n\n<p id=\"8a93\"><strong>Code Explanation:<\/strong>&nbsp;The above code can be classified into&nbsp;three categories:&nbsp;Weighted Moving Average&nbsp;calculation,&nbsp;Rate Of Change&nbsp;calculation, and the&nbsp;Coppock Curve&nbsp;calculation.<\/p>\n\n\n\n<p id=\"9eae\">WMA calculation: In this part, we are first&nbsp;defining a function named \u2018wma\u2019&nbsp;that takes the&nbsp;closing prices&nbsp;(\u2018data\u2019), and the&nbsp;lookback period&nbsp;(\u2018lookback\u2019) as parameters. Inside the function, we are&nbsp;first determining the weights&nbsp;that are to be assigned to each data point and stored them into the \u2018weights\u2019 variable. Next, we are creating a variable named \u2018val\u2019 to store the rolling data series for a specified number of periods with the help of the \u2018rolling\u2019 function provided by the Pandas package. Now, using the predetermined weights and the rolling values, we are calculating and storing the WMA values into the \u2018wma\u2019 variable.<\/p>\n\n\n\n<p id=\"1901\">ROC calculation: Firstly, we are defining a function named \u2018get_roc\u2019 that takes the&nbsp;stock\u2019s closing price&nbsp;(\u2018close\u2019) and the&nbsp;\u2019n\u2019 value&nbsp;(\u2019n\u2019) as parameters. Inside the function, we are first taking the&nbsp;difference between the current closing price and the closing price for a specified number of periods ago&nbsp;using the \u2018diff\u2019 function provided by the Pandas package. With the help of the \u2018shift\u2019 function, we are&nbsp;taking into account the closing price for a specified number of periods ago&nbsp;and&nbsp;stored it in the \u2018nprev_values\u2019&nbsp;variable. Then, we are&nbsp;substituting the determined values into the ROC indicator formula&nbsp;we discussed before to&nbsp;calculate the values&nbsp;and finally returned the data.<\/p>\n\n\n\n<p id=\"c35c\">Coppock Curve calculation: just as we did in the other two functions, here as well we first define a function named&nbsp;\u2018get_cc\u2019 that takes a stock\u2019s closing price data (\u2018data\u2019), the \u2019n\u2019 value for the longer ROC (\u2018roc_1\u2019)&nbsp;and the&nbsp;shorter ROC (\u2018roc_2\u2019), and the Weighted Moving Average lookback period (\u2018wma_lookback\u2019) as parameters. Inside the function,&nbsp;we are first determining the two ROCs, one with the greater \u2019n\u2019 value and the other with the shorter \u2019n\u2019 value using the \u2018get_roc\u2019 function we created earlier. Then we are adding both the ROCs and stored the results into the \u2018ROC\u2019 variable. With the help of the \u2018wma\u2019 function we created before, we are taking the&nbsp;Weighted Moving Average of the sum of the two ROCs to get the readings of the Coppock Curve.<\/p>\n\n\n\n<p id=\"4abc\">Finally, we are calling the created \u2018get_cc\u2019 function to store the readings of Apple\u2019s Coppock Curve. Now, let\u2019s proceed to create the discussed tuned zero-line crossover trading strategy.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"8cea\">Step-4: Creating the trading strategy<\/h2>\n\n\n\n<p id=\"6c36\">In this step, we are going to implement the discussed Coppock Curve tuned Zero-line crossover trading strategy in Python.<\/p>\n\n\n\n<p id=\"5469\"><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># COPPOCK CURVE STRATEGY<br><\/strong><br>def implement_cc_strategy(prices, cc):<br>    buy_price = []<br>    sell_price = []<br>    cc_signal = []<br>    signal = 0<br>    <br>    for i in range(len(prices)):<br>        if cc[i-4] &lt; 0 and cc[i-3] &lt; 0 and cc[i-2] &lt; 0 and cc[i-1] &lt; 0 and cc[i] &gt; 0:<br>            if signal != 1:<br>                buy_price.append(prices[i])<br>                sell_price.append(np.nan)<br>                signal = 1<br>                cc_signal.append(signal)<br>            else:<br>                buy_price.append(np.nan)<br>                sell_price.append(np.nan)<br>                cc_signal.append(0)<br>        elif cc[i-4] &gt; 0 and cc[i-3] &gt; 0 and cc[i-2] &gt; 0 and cc[i-1] &gt; 0 and cc[i] &lt; 0:<br>            if signal != -1:<br>                buy_price.append(np.nan)<br>                sell_price.append(prices[i])<br>                signal = -1<br>                cc_signal.append(signal)<br>            else:<br>                buy_price.append(np.nan)<br>                sell_price.append(np.nan)<br>                cc_signal.append(0)<br>        else:<br>            buy_price.append(np.nan)<br>            sell_price.append(np.nan)<br>            cc_signal.append(0)<br>            <br>    return buy_price, sell_price, cc_signal<br><br>buy_price, sell_price, cc_signal = implement_cc_strategy(aapl['close'], aapl['cc'])<\/pre>\n\n\n\n<p id=\"8ef0\"><strong>Code Explanation:<\/strong>&nbsp;First, we are defining a function named \u2018implement_cc_strategy\u2019 which takes the stock prices (\u2018prices\u2019), and the readings of the Coppock Curve (\u2018cc\u2019) as parameters.<\/p>\n\n\n\n<p id=\"f10d\">Inside the function, we are creating three empty lists (buy_price, sell_price, and cc_signal) in which the values will be appended while creating the trading strategy.<\/p>\n\n\n\n<p id=\"35e8\">After that, we are implementing the trading strategy through a&nbsp;for-loop. Inside the for-loop,&nbsp;we are passing certain conditions, and if the conditions are satisfied, the respective values will be appended to the empty lists. If the&nbsp;condition to buy the stock gets satisfied, the&nbsp;buying price will be appended to the \u2018buy_price\u2019 list, and the&nbsp;signal value will be appended as 1&nbsp;representing buying the stock. Similarly, if the condition to sell the stock gets 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=\"553e\">Finally, we are returning the lists appended with values. Then, we are calling the created function and stored 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=\"fc70\">Step-5: Plotting the trading signals<\/h2>\n\n\n\n<p id=\"011a\">In this step, we are going to plot the created trading lists to make sense of them.<\/p>\n\n\n\n<p id=\"2be6\"><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># COPPOCK CURVE TRADING SIGNAL PLOT<br><\/strong><br>ax1 = plt.subplot2grid((11,1), (0,0), rowspan = 5, colspan = 1)<br>ax2 = plt.subplot2grid((11,1), (6,0), rowspan = 6, colspan = 1)<br>ax1.plot(aapl['close'], linewidth = 2, label = 'aapl')<br>ax1.plot(aapl.index, buy_price, marker = '^', color = 'green', markersize = 12, linewidth = 0, label = 'BUY SIGNAL')<br>ax1.plot(aapl.index, sell_price, marker = 'v', color = 'r', markersize = 12, linewidth = 0, label = 'SELL SIGNAL')<br>ax1.legend()<br>ax1.set_title('AAPL CC TRADING SIGNALS')<br>for i in range(len(aapl)):<br>    if aapl.iloc[i, 5] &gt;= 0:<br>        ax2.bar(aapl.iloc[i].name, aapl.iloc[i, 5], color = '#009688')<br>    else:    <br>        ax2.bar(aapl.iloc[i].name, aapl.iloc[i, 5], color = '#f44336')<br>ax2.set_title('AAPL COPPOCK CURVE')<br>plt.show()<\/pre>\n\n\n\n<p id=\"1205\"><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-26.png\" alt=\"\" class=\"wp-image-1732\"\/><\/figure>\n\n\n\n<p id=\"b31b\"><strong>Code Explanation:<\/strong>&nbsp;We are plotting the readings of the Coppock Curve along with the buy and sell signals generated by the tuned Zero-line crossover trading strategy. We can observe that&nbsp;whenever the previous four readings of the Coppock Curve are below the zero line&nbsp;and the&nbsp;current reading is above the zero-line, a green-colored buy signal is plotted&nbsp;in the chart. Similarly, whenever the previous four readings of the Coppock Curve 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=\"2f18\">Step-6: Creating our Position<\/h2>\n\n\n\n<p id=\"ed07\">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=\"2a78\"><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># STOCK POSITION<br><\/strong><br>position = []<br>for i in range(len(cc_signal)):<br>    if cc_signal[i] &gt; 1:<br>        position.append(0)<br>    else:<br>        position.append(1)<br>        <br>for i in range(len(aapl['close'])):<br>    if cc_signal[i] == 1:<br>        position[i] = 1<br>    elif cc_signal[i] == -1:<br>        position[i] = 0<br>    else:<br>        position[i] = position[i-1]<br>        <br>close_price = aapl['close']<br>cc = aapl['cc']<br>cc_signal = pd.DataFrame(cc_signal).rename(columns = {0:'cc_signal'}).set_index(aapl.index)<br>position = pd.DataFrame(position).rename(columns = {0:'cc_position'}).set_index(aapl.index)<br><br>frames = [close_price, cc, cc_signal, position]<br>strategy = pd.concat(frames, join = 'inner', axis = 1)<br><br>strategy<\/pre>\n\n\n\n<p id=\"6161\"><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"865\" height=\"472\" src=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/08\/image-27.png\" alt=\"\" class=\"wp-image-1733\"\/><\/figure>\n\n\n\n<p id=\"24ed\"><strong>Code Explanation:<\/strong>&nbsp;First, we are creating an empty list named \u2018position\u2019. We are&nbsp;passing two for-loops, one is to&nbsp;generate values for the \u2018position\u2019 list&nbsp;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&nbsp;the second for-loop, we are&nbsp;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=\"5bbd\">From the output being shown, we can see that in the first two rows, our position in the stock has remained 1 (since there isn\u2019t any change in the Coppock Curve signal) but our position suddenly turned to -1 as we sold the stock when the Coppock Curve 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 processes!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"12be\">Step-7: Backtesting<\/h2>\n\n\n\n<p id=\"4244\">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 Coppock Curve trading strategy over the Apple stock data.<\/p>\n\n\n\n<p id=\"ad7d\"><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># BACKTESTING\n<\/strong>\naapl_ret = pd.DataFrame(np.diff(aapl['close'])).rename(columns = {0:'returns'})\ncc_strategy_ret = []\n\nfor i in range(len(aapl_ret)):\n    returns = aapl_ret['returns'][i]*strategy['cc_position'][i]\n    cc_strategy_ret.append(returns)\n    \ncc_strategy_ret_df = pd.DataFrame(cc_strategy_ret).rename(columns = {0:'cc_returns'})\ninvestment_value = 100000\ncc_investment_ret = []\n\nfor i in range(len(cc_strategy_ret_df['cc_returns'])):\n    number_of_stocks = floor(investment_value\/aapl['close'][i])\n    returns = number_of_stocks*cc_strategy_ret_df['cc_returns'][i]\n    cc_investment_ret.append(returns)\n\ncc_investment_ret_df = pd.DataFrame(cc_investment_ret).rename(columns = {0:'investment_returns'})\ntotal_investment_ret = round(sum(cc_investment_ret_df['investment_returns']), 2)\nprofit_percentage = floor((total_investment_ret\/investment_value)*100)\nprint(cl('Profit gained from the CC strategy by investing $100k in AAPL : {}'.format(total_investment_ret), attrs = ['bold']))\nprint(cl('Profit percentage of the CC strategy : {}%'.format(profit_percentage), attrs = ['bold']))<\/pre>\n\n\n\n<p id=\"4f90\"><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-background\" style=\"background-color:#abb7c217\"><strong>Profit gained from the CC strategy by investing $100k in AAPL : 91164.07\nProfit percentage of the CC strategy : 91%<\/strong><\/pre>\n\n\n\n<p id=\"cf8a\"><strong>Code Explanation:<\/strong>&nbsp;First, we are calculating the returns of the Apple stock using the \u2018diff\u2019 function&nbsp;provided by the NumPy package and we have stored it as a dataframe in the \u2018aapl_ret\u2019 variable. Next, we are passing a&nbsp;for-loop to iterate over the values of the \u2018aapl_ret\u2019 variable&nbsp;to calculate the returns we gained from our Coppock Curve trading strategy,&nbsp;and these returns values are&nbsp;appended to the \u2018cc_strategy_ret\u2019 list.&nbsp;Next, we are converting the \u2018cc_strategy_ret\u2019 list into a dataframe and storing it in the \u2018cc_strategy_ret_df\u2019 variable.<\/p>\n\n\n\n<p id=\"0c87\">Next comes the backtesting process.&nbsp;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&nbsp;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.&nbsp;The&nbsp;number of stocks should be an integer but not a decimal number.&nbsp;Using the&nbsp;\u2018floor\u2019 function, we can cut out the decimals.&nbsp;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=\"422b\">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 ninety thousand USD in three and a half years. That\u2019s not bad! 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=\"da55\">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=\"8ea0\"><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># SPY ETF COMPARISON\n<\/strong>\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    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('CC Strategy profit is {}% higher than the Benchmark Profit'.format(profit_percentage - benchmark_profit_percentage), attrs = ['bold']))<\/pre>\n\n\n\n<p id=\"8c9c\"><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 : 40181.36\nBenchmark Profit percentage : 40%\nCC Strategy profit is 51% higher than the Benchmark Profit<\/strong><\/pre>\n\n\n\n<p id=\"95af\"><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 Coppock Curve tuned zero-line crossover trading strategy has outperformed the SPY ETF by 51%. 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=\"11a3\">Final Thoughts!<\/h1>\n\n\n\n<p id=\"c28b\">After an immense process of crushing both the theory and coding parts, we have successfully learned what the Coppock Curve is all about, and how a trading strategy based on it can be implemented with the help of Python.<\/p>\n\n\n\n<p id=\"e8a7\">Now, talking about improvisation of which I speak a lot in all of my articles, one important aspect that can be improved is the way to choose the best stocks. In this article, we chose the Apple stock for the implementation of the indicator but it might end up resulting in bad trades while applied in the real-world market. So, it is essential to pick the right stocks, but how? Approaching this situation with a quantitative strategy would be more optimal and if this sounds too technical, read my article about it&nbsp;<a href=\"https:\/\/medium.com\/codex\/picking-stocks-with-a-quantitative-momentum-strategy-in-python-b15ac8925ec6\">here<\/a>.<\/p>\n\n\n\n<p id=\"2cf3\">That\u2019s it! Hope you learned something new and useful from this article.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A complete guide to using the Coppock Curve indicator for making better algorithmic trades<\/p>\n","protected":false},"author":18,"featured_media":1728,"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":[65,61],"tags":[],"coding-language":[30],"ready-to-go-solution":[],"qualification":[31,32],"financial-apis-category":[36],"financial-apis-manuals":[39,40],"class_list":["post-1726","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-backtesting-strategies-examples","category-trading-indicators-implimentations","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>Coppock Curve Backtesting Trading Strategy in Python: A Step-by-Step Guide | EODHD APIs Academy<\/title>\n<meta name=\"description\" content=\"Master the Coppock Curve indicator for long-term trading. Create a Python trading strategy using the indicator, backtest it, and analyze the results\" \/>\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\/backtesting-strategies-examples\/the-coppock-curve-coding-and-backtesting-a-trading-strategy-in-python\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"The Coppock Curve \u2014 Coding and Backtesting a Trading Strategy in Python\" \/>\n<meta property=\"og:description\" content=\"Master the Coppock Curve indicator for long-term trading. Create a Python trading strategy using the indicator, backtest it, and analyze the results\" \/>\n<meta property=\"og:url\" content=\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/the-coppock-curve-coding-and-backtesting-a-trading-strategy-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-29T14:53:18+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-03-12T12:20:19+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/08\/image-22.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=\"15 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/the-coppock-curve-coding-and-backtesting-a-trading-strategy-in-python#article\",\"isPartOf\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/the-coppock-curve-coding-and-backtesting-a-trading-strategy-in-python\"},\"author\":{\"name\":\"Nikhil Adithyan\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#\/schema\/person\/67681e71050cf7d8d0efb91fee5f0402\"},\"headline\":\"The Coppock Curve \u2014 Coding and Backtesting a Trading Strategy in Python\",\"datePublished\":\"2023-08-29T14:53:18+00:00\",\"dateModified\":\"2024-03-12T12:20:19+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/the-coppock-curve-coding-and-backtesting-a-trading-strategy-in-python\"},\"wordCount\":3273,\"publisher\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#organization\"},\"image\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/the-coppock-curve-coding-and-backtesting-a-trading-strategy-in-python#primaryimage\"},\"thumbnailUrl\":\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/08\/image-22.png\",\"articleSection\":[\"Backtesting Strategies Examples\",\"Trading Indicators Implimentations\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/the-coppock-curve-coding-and-backtesting-a-trading-strategy-in-python\",\"url\":\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/the-coppock-curve-coding-and-backtesting-a-trading-strategy-in-python\",\"name\":\"Coppock Curve Backtesting Trading Strategy in Python: A Step-by-Step Guide | EODHD APIs Academy\",\"isPartOf\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/the-coppock-curve-coding-and-backtesting-a-trading-strategy-in-python#primaryimage\"},\"image\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/the-coppock-curve-coding-and-backtesting-a-trading-strategy-in-python#primaryimage\"},\"thumbnailUrl\":\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/08\/image-22.png\",\"datePublished\":\"2023-08-29T14:53:18+00:00\",\"dateModified\":\"2024-03-12T12:20:19+00:00\",\"description\":\"Master the Coppock Curve indicator for long-term trading. Create a Python trading strategy using the indicator, backtest it, and analyze the results\",\"breadcrumb\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/the-coppock-curve-coding-and-backtesting-a-trading-strategy-in-python#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/the-coppock-curve-coding-and-backtesting-a-trading-strategy-in-python\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/the-coppock-curve-coding-and-backtesting-a-trading-strategy-in-python#primaryimage\",\"url\":\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/08\/image-22.png\",\"contentUrl\":\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/08\/image-22.png\",\"width\":828,\"height\":552,\"caption\":\"The Coppock Curve \u2014 Coding and Backtesting a Trading Strategy in Python\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/the-coppock-curve-coding-and-backtesting-a-trading-strategy-in-python#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/eodhd.com\/financial-academy\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"The Coppock Curve \u2014 Coding and Backtesting a Trading Strategy 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":"Coppock Curve Backtesting Trading Strategy in Python: A Step-by-Step Guide | EODHD APIs Academy","description":"Master the Coppock Curve indicator for long-term trading. Create a Python trading strategy using the indicator, backtest it, and analyze the results","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\/backtesting-strategies-examples\/the-coppock-curve-coding-and-backtesting-a-trading-strategy-in-python","og_locale":"en_US","og_type":"article","og_title":"The Coppock Curve \u2014 Coding and Backtesting a Trading Strategy in Python","og_description":"Master the Coppock Curve indicator for long-term trading. Create a Python trading strategy using the indicator, backtest it, and analyze the results","og_url":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/the-coppock-curve-coding-and-backtesting-a-trading-strategy-in-python","og_site_name":"Financial Academy","article_publisher":"https:\/\/www.facebook.com\/eodhistoricaldata","article_published_time":"2023-08-29T14:53:18+00:00","article_modified_time":"2024-03-12T12:20:19+00:00","og_image":[{"width":828,"height":552,"url":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/08\/image-22.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":"15 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/the-coppock-curve-coding-and-backtesting-a-trading-strategy-in-python#article","isPartOf":{"@id":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/the-coppock-curve-coding-and-backtesting-a-trading-strategy-in-python"},"author":{"name":"Nikhil Adithyan","@id":"https:\/\/eodhd.com\/financial-academy\/#\/schema\/person\/67681e71050cf7d8d0efb91fee5f0402"},"headline":"The Coppock Curve \u2014 Coding and Backtesting a Trading Strategy in Python","datePublished":"2023-08-29T14:53:18+00:00","dateModified":"2024-03-12T12:20:19+00:00","mainEntityOfPage":{"@id":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/the-coppock-curve-coding-and-backtesting-a-trading-strategy-in-python"},"wordCount":3273,"publisher":{"@id":"https:\/\/eodhd.com\/financial-academy\/#organization"},"image":{"@id":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/the-coppock-curve-coding-and-backtesting-a-trading-strategy-in-python#primaryimage"},"thumbnailUrl":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/08\/image-22.png","articleSection":["Backtesting Strategies Examples","Trading Indicators Implimentations"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/the-coppock-curve-coding-and-backtesting-a-trading-strategy-in-python","url":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/the-coppock-curve-coding-and-backtesting-a-trading-strategy-in-python","name":"Coppock Curve Backtesting Trading Strategy in Python: A Step-by-Step Guide | EODHD APIs Academy","isPartOf":{"@id":"https:\/\/eodhd.com\/financial-academy\/#website"},"primaryImageOfPage":{"@id":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/the-coppock-curve-coding-and-backtesting-a-trading-strategy-in-python#primaryimage"},"image":{"@id":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/the-coppock-curve-coding-and-backtesting-a-trading-strategy-in-python#primaryimage"},"thumbnailUrl":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/08\/image-22.png","datePublished":"2023-08-29T14:53:18+00:00","dateModified":"2024-03-12T12:20:19+00:00","description":"Master the Coppock Curve indicator for long-term trading. Create a Python trading strategy using the indicator, backtest it, and analyze the results","breadcrumb":{"@id":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/the-coppock-curve-coding-and-backtesting-a-trading-strategy-in-python#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/the-coppock-curve-coding-and-backtesting-a-trading-strategy-in-python"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/the-coppock-curve-coding-and-backtesting-a-trading-strategy-in-python#primaryimage","url":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/08\/image-22.png","contentUrl":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/08\/image-22.png","width":828,"height":552,"caption":"The Coppock Curve \u2014 Coding and Backtesting a Trading Strategy in Python"},{"@type":"BreadcrumbList","@id":"https:\/\/eodhd.com\/financial-academy\/backtesting-strategies-examples\/the-coppock-curve-coding-and-backtesting-a-trading-strategy-in-python#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/eodhd.com\/financial-academy\/"},{"@type":"ListItem","position":2,"name":"The Coppock Curve \u2014 Coding and Backtesting a Trading Strategy 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-22.png","jetpack_shortlink":"https:\/\/wp.me\/pdOdVT-rQ","jetpack_sharing_enabled":true,"acf":[],"_links":{"self":[{"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/posts\/1726","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=1726"}],"version-history":[{"count":24,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/posts\/1726\/revisions"}],"predecessor-version":[{"id":3058,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/posts\/1726\/revisions\/3058"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/media\/1728"}],"wp:attachment":[{"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/media?parent=1726"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/categories?post=1726"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/tags?post=1726"},{"taxonomy":"coding-language","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/coding-language?post=1726"},{"taxonomy":"ready-to-go-solution","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/ready-to-go-solution?post=1726"},{"taxonomy":"qualification","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/qualification?post=1726"},{"taxonomy":"financial-apis-category","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/financial-apis-category?post=1726"},{"taxonomy":"financial-apis-manuals","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/financial-apis-manuals?post=1726"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}