%run scripts/daily_change.py
[ 0%% ][*********************100%%**********************] 2 of 2 completed
Navigating today’s financial markets to find an investment strategy is overwhelming. The abundance of data, ideas & stories available is more than ever before.
This scientific journal targets hobbyists who use regular apps for trading, with a focus on a simple strategy known as pairs trading.
Pairs trading involves choosing two financial instruments, typically stocks, that historically show a strong correlation in their price movements. The core idea is that these instruments’ prices tend to move together, and deviations from this correlation can create profitable trading opportunities.
Here’s how the strategy works:
Identify a Pair: Select two securities that have historically moved together in price. Monitor the Spread: Watch the price difference between the two securities. When this difference deviates significantly from its usual range, it suggests a trading opportunity.
Enter the Trade:
Convergence: The trade becomes profitable when the price difference returns to its normal range, as the prices of the two securities move back in sync.
This scientific journal is a straightforward study on flipping pairs, helping hobbyists better understand why and how they do it this way.
Using modern tools for scientific-grade research like NumPy, Pandas, Matplotlib, LLMs & prompt engineering & Jupyter. We concluded that using the most volatile pairs in the market tend to yield the best rewards for this particular average joe strategy.
The study concludes that for achieving the highest profits, trading low-market-cap cryptocurrencies aka shitcoins proves to be the most effective strategy.
The methodology of this study is best described by splitting it into 2 subsections, tooling & process.
The author of this study is not an experienced statician, actuarial scientist nor a data engineer.
I am a software engineer that’s worked with Ruby/Rails & Node.js. I wanted to use Python & it’s data science ecosystem for the study without having to invest a large amount of time picking up a new syntax and set of libraries.
With new AI on the table, I decided to preload an LLM with the relevant context & guide as if I was a technical lead guiding a developer through a tech stack I’m not savvy in. With that in mind, here’s the full list of tools & techniques I used as-is to set this up:
The code for this study can be found on the @shellandbull/higher-risk-higher-rewards
Using personal, hobbyist-level, financial investment knowledge a pairs trading strategy was devised. The strategy is fairly simple
2 Financial instruments are selected, let us call them A & B. This flavour of pairs trading relies on actively tracking price changes between the 2 instruments to maximise gains by buying/selling them against each other. Let us go over an iteration of the strategy
We start with 1 Bitcoin and 220 Tesla stocks
BTC/USD - Price | BTC/USD - Amount | TSLA/USD - Price | TSLA/USD - Amount | Portfolio Value |
---|---|---|---|---|
60,000 |
1.00 |
220 |
200 |
$104,000 |
Time goes by, and the prices change slightly. Bitcoin became more expensive, Tesla became cheaper.
BTC/USD - Price | BTC/USD - Amount | TSLA/USD - Price | TSLA/USD - Amount | Portfolio Value |
---|---|---|---|---|
63,000 |
1.00 |
190 |
200 |
$101,000 |
An opportunity pops out the water to say “What’s upppppp dawg”.
We allocate .3 BTC
so $18,900
into Tesla. This means we bought 99.47
Tesla stocks
BTC/USD - Price | BTC/USD - Amount | TSLA/USD - Price | TSLA/USD - Amount | Portfolio Value |
---|---|---|---|---|
63,000 |
0.7 |
190 |
200 + 99.47 = 299.47 |
$100,999 |
P.D: I dropped some decimal points without rounding which is why the value of the portfolio fluctuated down. We can theorise these are trading fees to make the study seem more realistic
The market moves again. Bitcoin maintains it’s price while Tesla recovers
BTC/USD - Price | BTC/USD - Amount | TSLA/USD - Price | TSLA/USD - Amount | Portfolio Value |
---|---|---|---|---|
63,000 |
0.7 |
220 |
299.47 |
$109,983.4 |
A profit of $5,983.4
is retained. Voila!
This of course, is a far cry from a perfect strategy. A few challenges come to mind:
This study doesn’t aim to give the reader a Moneyball on investing. If that was the case the author would be writing this study from some highly valued real state investment whereas I am now sitting in my humble home with a cat sitting on my lap.
This strategy is far from perfect, there isn’t a guarantee on price fluctuations sailing your way. What can be done, is to measure the number of “opportunities” that existed in the past across any tuple of financial instruments to best determine what instrument set to use.
With the strategy and tools set into place it becomes a matter of guiding an LLM across the study. The modus operandi for guiding the LLM across building the study is as follows:
WARNING This scientific journal styled blog post is a live piece of knowledge that’s actively under development. It aims to study the progress of LLMs in the context of financial investigation & research on top of it’s actual objective
hic sunt dracones, there can be bugs. If you find one please submit a PR on the repo @shellandbull/higher-risk-higher-rewards
The potential gains of a speculative trading strategy are analyzed by examining two pairs:
BTC/USD
CRO/USD
This strategy utilizes a straightforward “buy low, sell high” approach exclusively with these two instruments. To visualize potential margins, the percentage price changes of the two pairs are plotted on the same time series, with areas where one offsets the other highlighted. In layman’s terms, the colored areas indicate moments where profit opportunities arise. The gains of a potential speculative strategy are studied by plotting 2 pairs
%run scripts/daily_change.py
[ 0%% ][*********************100%%**********************] 2 of 2 completed
The visualization indicates that there is potential for margins. However, how will this strategy perform in real market conditions?
A simple strategy with specific rules is devised:
%run scripts/basic_speculation.py
[ 0%% ][*********************100%%**********************] 2 of 2 completed
With the foundation established, I can design multiple strategies to evaluate how different approaches affect portfolio value. A proposed problem for machine learning to solve would be to:
🌟 The objective is to achieve the highest portfolio value, making the goal straightforward.
%run scripts/multi_strategy_speculation.py
[ 0%% ][*********************100%%**********************] 2 of 2 completed
BTC
and CRO
are not the only instruments available in the market. What if we consider another pair? For this example, I chose TSLA
and PYPL
.
We can also experiment by mixing and matching different pairs to explore various combinations and their impact on portfolio value.
%run scripts/multi_instrument_multi_strategy.py
[ 0%% ][*********************100%%**********************] 2 of 2 completed
[ 0%% ][*********************100%%**********************] 2 of 2 completed
[ 0%% ][*********************100%%**********************] 2 of 2 completed
A successful gain occurs when we “flip” twice, and the price variation is always in our favor.
By using historical data, we can examine every possible combination of financial instruments over the past year to identify those yielding the maximum gains.
We can then rank these pairs and derive a top 3 or 5. The algorithm to identify these pairs is straightforward:
I will determine the top pairs of instruments to trade. The script can be found here and should be run in the background due to its large data size.
scripts/top_pairs_to_trade.py
import pandas as pd
# Load CSV file into DataFrame
= pd.read_csv('data/selected_pairs.csv')
df
df
pair | score | |
---|---|---|
0 | AISP / AULT | 2047.352423 |
1 | AULT / AISP | 2047.352423 |
2 | WTO / SBFM | 1995.649214 |
3 | FET-USD / AXL17799-USD | 1323.654462 |
4 | AXL17799-USD / FET-USD | 1323.654462 |
... | ... | ... |
439 | JTAIZ / GCTS | 4489.530701 |
440 | JAGX / JTAIZ | 4426.418104 |
441 | CFG-USD / FTT-USD | 1721.783582 |
442 | FTT-USD / CFG-USD | 1721.783582 |
443 | GRI / FTT-USD | 1609.159168 |
444 rows × 2 columns
We now have a list of approximately 450 entries of stock pairs.
The score is calculated as the absolute value of the aggregated percentage price change difference between the two stocks each day. This method allows us to identify the pairs with the highest potential gains. Let’s test one of these pairs using our previous simulation framework.
In this example, we trade CXAI
and ZETA-USD
.
%run scripts/daily_change_top.py
[ 0%% ][*********************100%%**********************] 2 of 2 completed
/Users/xyzxyz/dev/higher-risk-higher-rewards/docs/scripts/daily_change_top.py:12: FutureWarning:
The default fill_method='pad' in DataFrame.pct_change is deprecated and will be removed in a future version. Either fill in any non-leading NA values prior to calling pct_change or specify 'fill_method=None' to not fill NA values.
It appears that trading low-market-cap cryptocurrencies, colloquially known as “shitcoins,” presents a significant speculative opportunity for substantial financial gain.
Given that this is an early-stage study, further refinements and adaptations are necessary.
Preliminary results indicate a potential doubling of capital when trading these assets over the past two months.
%run scripts/top_multi_strategy_speculation.py
[ 0%% ][*********************100%%**********************] 2 of 2 completed
If you have any feedback, recommendations or ammendments to make to this study I’d like to speak to you! You can find me on:
mariojgintili at gmail dot com