Typefully

M-FARM: trading algorithm for psychic traders

Avatar

Share

 • 

3 years ago

 • 

View on X

Have you wondered how much money you can make from crypto trading if you're psychic? I developed an algorithm called M-FARM that finds the max profit when you can predict prices with 100% accuracy. A thread:
First off, how much money can you make from crypto trading if you're psychic? The answer: M-FARM achieved ~5.5% return in a 3-hr sample period using historical data. That would translates into a 50% return EVERY DAY.
Why is this useful? 1. We can learn trading from the algorithm by examining the trading behavior of M-FARM on historical data. Combining this with technical and fundamental analysis can reveal patterns for good trading signals and even strategies.
2. Use as a reference metric for backtesting/evaluating trading performance. The M-FARM return can be interpreted as "the best possible return" for a long-only crypto portfolio. (whereas market portfolio return/risk-free return are baselines)
A semi-technical summary: M-FARM stands for minutely fee-adjusted return maximization. Since I traded readability for a cool acronym, let me explain the detail with 50% technical details + 50% intuition/examples.
Assumptions/restrictions: - Long-only: only buy/sell, no shorting/borrowing (otherwise meaningless bc return is infinite) - Trading on CEX: instant transactions and percentage fees. I'm using FTX US data: only ~17 tokens - Price taker: our trades do not affect market prices
We are given the following: initial portfolio value (V_0) e.g. $10k; transaction fee rate (τ) e.g. 0.2%; and the price (P) of every asset (a) at every minute (t). Index trades from 1 to n, then the final portfolio value (V^n) can be condensed into the following expression:
The intuition: With each trade we have to pay some fees, but profit from price increases. The trade-off: if we trade very frequently in order to capture every upward price tick, the fees will eat a lot of the profit. Hence an optimization problem.
Although we have a closed-form expression, this optimization problem is difficult to solve with conventional methods b/c: 1. # of trades (n) is undetermined. 2. The number of variables is too large for most non-linear optimizers. (also technically an integer programming prob)
M-FARM solves this optimization problem by identifying the best trade in terms of minutely return adjusted by fees. The exact definition is as follows:
Notice the exponent term which is adopted from the classic yield-to-maturity formula used for bonds etc. Intuitively, 10% return in 30 minutes is better than 15% in one hour. (time is money!)
If you specify a time period (T), M-FARM first finds one (asset, buy_time, sell_time) combination within T with highest M-FAR. Then it recursively finds the highest M-FAR for the rest of the time period, until every minute within T is occupied with a good trade.
A brief illustration with a 3-hr period: -> start with search period T=0~180min: best trade is (XXX, 80min, 100min) -> now search on T=0~80min and T=100~180min; -> best trade in 0~80min is (YYY, 10min, 15min); best trade in 100-180min is (ZZZ, 115min, 170min) -> keep going...
Thanks to @ProfPieters for an interesting homework prompt that led to this, and giving insights on how to potentially improve the computational efficiency.
Next steps: All my code is currently in a messy python notebook screaming for some clean-up. The recursion part currently runs inefficiently at O(n^3) per branch.
I might write M-FARM as a program w/ UI (anyone knows how?), or open source it on a github repo, but at least after the code clean-up
Like/follow/RT if you like the content! I'll be posting more web3 research stuff since I'm a graduate student looking for web3 internship/fulltime positions and could benefit from some twitter exposure.
Avatar

mingxuanh.eth

@MingXDynasty

blockchain ℝesearch & data | meme AGI dev | incoming @Gauntlet_xyz | escaping @UChicago | Gamer. d/acc