Backtesting Onchain Metrics in 5 Minutes? Absolutely.
See How @glassnode and GPT-4 Can Help You Achieve It in 5 Steps.
👇 #btc #eth #onchain #chatgpt
Here is the chat gpt 4 prompt I used:
"I want you to be a data analyst and create a sma backtesting strategy and calculate the Sharpe ratio of BTC. BTC = m1, and each formula needs to follow the following format: f1,f2,f3... Here is the glassnode syntax:"
Since #chatgpt 4 isn't familiar with the newest glassnode syntax, you will need to copy and paste it from this google sheets file:
@glassnode Workbench Syntax
docs.google.com/spreadsheets/d…
I wasn't that happy with the initial request, so I asked chat gpt to output a crossover strategy with two simple moving averages.
Prompt: "Can you do the same but make the strategy with two sma."
Chat Gpt 4 output:
We can create a backtesting strategy using two SMAs, often called a Moving Average Crossover strategy. In this example, we will use a short-term (20-day) and a long-term (50-day) SMA.
Great!
Now let's add the formulas to @glassnode
f1 = sma(m1, 20)
f2 = sma(m1, 50)
f3 = if(f1, ">", f2, 1, -1)
f4 = backtest(m1, f3, "2020-01-01", 10000, 0.001)
f5 = sharpe_ratio(f4, 50)
Go to @glassnode workbench and click on + Add to add a formula.
If you don't have a glassnode account, you can support me by using my link:
studio.glassnode.com/partner/oe
Copy and paste the formula into the input field, then click "Evaluate and draw".
Do that with the remaining formulas.
I also recommend asking chat gpt 4 questions on the different formulas. That will improve your comprehension.
Let's say I want to understand what:
f3 = if(f1, ">", f2, 1, -1)
does
So I ask: "What does formula f3 do"
I get this answer:
`f3` generates a trading signal for the moving average crossover strategy by comparing the 20-day and 50-day SMAs.
When you have added all the formulas, it should look like this:
But is this backtesting strategy actually any good?
A trading strategy is useless if you don't know it's better than a simple "buy-and-hold" strategy.
So I asked: "how can I check if my backtest was more profitable than just holding btc"
The first chat gpt 4 output wasn't that great so I need to regenerate a few times.
I had to do a bit of troubleshooting.
The syntax that chat gpt 4 spits out isn't always correct.
Here are the formulas you need to add:
f6 = value_at(m1, "2020-01-01")
f7 = m1-1
f8 = (f7 / f6) * 10000
f9 = f4-1 - f8
Results:
The backtested strategy value: $15'642 💀
Buy-and-hold strategy value: $40'288 🔥
Profitability (f9): -24k
Conclusion: The strategy was not more profitable than a simple "buy-and-hold" strategy.
This shows us how important it is to backtest strategies to know if they're profitable.
I will backtest many onchain strategies in the next few weeks and share the profitability scores.
Let's find the most profitable and successful backtesting strategy.
Caveat: There is a risk of overfitting the strategy to the past data. I need to keep that in mind.
I hope you've found this thread helpful.
Follow me @onchain_edge for more.
Like/Retweet the first tweet below if you can:
I appreciate the support! ❤️
Share this Scrolly Tale with your friends.
A Scrolly Tale is a new way to read Twitter threads with a more visually immersive experience.
Discover more beautiful Scrolly Tales like this.