I asked OpenAI's ChatGPT to write me a trading algorithm. It blew my mind.

I asked OpenAI's ChatGPT to write me a trading algorithm. It blew my mind.

It's time to rethink the way you code

#OpenAI's #ChatGPT. It's all the rage these days.

If you haven't been living under a rock, you would have heard of the buzz surrounding ChatGPT, a chatbot launched by OpenAI in November 2022. It was built on top of OpenAI's #gpt3 family of large language models and was fine-tuned with both supervised and reinforcement learning techniques.

By now, you would have seen hundreds of posts raving about the numerous use cases for copywriting, resume-writing, solving math problems, and even for writing passive-aggressive texts to your spouse.

Among the large number of use cases that ChatGPT could be applied to, I wanted to explore an underutilized use case - writing code.


"ChatGPT, write me a trading algorithm."

Building a fully-functional trading algorithm from scratch is an extremely challenging task, and I wanted to test the limits of ChatGPT's ability to assist in strategy development.

In order to optimize the capabilities of ChatGPT, I had to make appropriate prompts and questions throughout the conversation. This meant that I had to zoom into the scope and provide sufficient context, including details such as:

  1. Choice of platform & programming language: MetaTrader 4 / MQL4
  2. Currency pair: EUR/USD
  3. Timeframe: Any
  4. Type of trading strategy: Mean reversion


With the above in mind, these are the prompts that I gave ChatGPT in order to put the building blocks together:

  1. "Help me with building a mean reversion algorithm using MQL4"
  2. "Use the EUR/USD currency pair with any time frame"

Believe it or not, these were the only prompts that I gave ChatGPT and it was sufficient enough to create a simple mean reversion #algorithm.


To err is.. AI?

Don't be mistaken - ChatGPT is not perfect. The code generated was filled with bugs and I found myself having to edit up to 50% of the code that ChatGPT provided me with. I also had to tinker with other aspects such as trailing stops, take-profit and stop-loss parameters. The good news is that ChatGPT could assist you in the debugging process to make your life easier. Half an hour or so later, the code was complete.


I back-tested the algorithm for 11.5 years to call its bluff. Why not?

Using tick data, I took the freshly-minted algorithm for a rigorous 11.5-year back-test to see if it is worth its salt. I'll be honest that I had low expectations, and the results surprised me.

With a starting capital of $1,000 USD and a starting lot size of 0.01, the back-test ran from 1 January 2011 to September 2022, yielding the following results:

No alt text provided for this image
Tick-by-tick back-test for EURUSD, from 1 Jan 2011 to Sep 2022

  • Win rate: 71.17%
  • ROMAD: 10.1
  • Total return: $433.31
  • Maximum drawdown: $-42.56 (3.24%)


ChatGPT - A worthy coding assistant

I'll be honest. I was excited by the results. As you can tell, it was a fantastic start. This opens up a plethora of possibilities not just in the field of algorithmic trading, but for software engineering as a whole. If you are a software engineer and is not using ChatGPT to help with you with the development process, give it a shot! You would be pleasantly surprised.


P.S. I've excluded detailed specifics of the development process in order to keep the article succinct. If you're interested to find out more, feel free to drop me a comment or a message!


#trading #tradingstrategy #metatrader

Sheryl Claire Chen, CLMP?

Health & Wellness, Loyalty & Integrated Marketing, Digital Banking, Media, Luxury, Healthcare, Finance

1 年

Congratulations on creating a trading algorithm with ChatGPT! I liked your post on LinkedIn and I'm excited to see how it performs in the market.

Hui Teng Ng

Product | Loyalty | Strategy | Innovation

1 年

How much time did it save you (or not)?

When, not if, they start charging for the platform, I assume you'd be more than happy to pay for it?

要查看或添加评论,请登录

社区洞察

其他会员也浏览了