avatarEymeric plaisant

Summarize

Backtesting ChatGPT investing strategies #2 : 5.006.025 $ Profit

The Coppock curve is a popular trading strategy that is used to identify long-term bullish momentum in a stock or market index.

It was developed by Edwin Coppock, an economist, and was first published in Barron’s magazine in 1962. The Coppock curve is calculated by taking the sum of the 14-period rate of change and 11-period rate of change of a market index or stock price and then smoothing it with a 10-month weighted moving average.

This creates a curved line that can be used to determine potential buy and sell signals.

In this article, we will discuss how to create the Coppock curve trading strategy using Python code. We will also show you how to backtest the strategy to determine its historical performance.

To create the Coppock curve in Python, we will use the Pandas library for data manipulation and the Talib library for technical analysis.Next, we will calculate the 14-period rate of change and 11-period rate of change of the index data and sum them.Finally, we will smooth the sum of the two rates of change using a 10-month weighted moving average.

The smoothed sum of the two rates of change is the Coppock curve. This curve can be used to determine potential buy and sell signals. When the curve rises, it is a bullish signal, and when it falls, it is a bearish signal.

if (df.iloc[i]['COP'] > df.iloc[i-1]['COP'])  and (df.iloc[i]['COP'] < df.iloc[i+1]['COP']):
        signals.append(1)
    elif (df.iloc[i]['COP'] < df.iloc[i-1]['COP'])  and (df.iloc[i]['COP'] > df.iloc[i+1]['COP']) :
        signals.append(-1)

To backtest the Coppock curve trading strategy, we will use the smoothed Coppock curve to determine when to buy and sell the ETHUSDT.

df["signal"] = signals
print(signals)
investment = 1000
current_investment = 1000
invested_amount = 0
fees = 0
profit = 0
is_invested = False
best_trade = -99999999
worst_trade = 99999999
largest_loss = 0
largest_gain = 0
total_trades = 0
for i in range(0, len(df)):
    signal = df.iloc[i]['signal'] 
    close = df.iloc[i]['close']

    if signal == 1 and not is_invested:
        Entrypoint = close
        print(signal)
        print(close)
        quantity = (current_investment / close)
        print(current_investment)       
        print(quantity)
        invested_amount = quantity * close
        is_invested = True
    elif signal == -1 and is_invested:
        print(signal)
        print(close)
        profit = quantity * (close - Entrypoint) - 2
        print(profit)
        current_investment += profit
        invested_amount = 0
        total_trades += 1
        is_invested = False
        if profit > largest_gain:
            largest_gain = profit
        if profit < largest_loss:
            largest_loss = profit
        if profit > best_trade:
            best_trade = profit
        if profit < worst_trade:
            worst_trade = profit
    else: 
        pass
        
final_profit = current_investment - investment
print("Final Profit: ", final_profit)
print("Best Trade: ", best_trade)
print("Worst Trade: ", worst_trade)
print("Largest Loss: ", largest_loss)
print("Largest Gain: ", largest_gain)
print("Total Trades: ", total_trades)

When the curve rises above its previous low, we will buy the index, and when it falls below its previous high, we will sell the index.

In conclusion, the Coppock Curve is a popular trading strategy that can be implemented in Python.

However, it is important to note that any form of trading carries a certain level of risk and should not be undertaken lightly. It is crucial to have a solid understanding of the markets, your own risk tolerance, and to properly assess and manage the risks associated with each trade.

Before starting any trading activity, it is recommended to seek advice from a financial advisor and to thoroughly educate yourself on the risks involved. Remember, past performance is not indicative of future results, and the markets can be unpredictable. Trading should only be done with risk capital that you can afford to lose.

Programming
Python
Investing
Trading
Cryptocurrency
Recommended from ReadMedium