2
$\begingroup$

I am in the process of making a cryptocurrency trading bot. Currently, I am doing backtesting over a period of 7 months in which I provide a portion of historical data as if it were in real-life.

By modulating 3 variables: decision threshold, maximum % gain per trade, and stop loss, I want to find the best input values in order to maximize the amount of ending money I have at the end of the backtest.

What would be a good way to go about this? Currently, I'm running each backtest, and changing only 1 variable, but it seems like a slow process and I feel like there has to be a better way to do it. I've heard about neural networks, but I'm not 100% sure this would be a good scenario to apply that here.

$\endgroup$
3
$\begingroup$

This area is known as black-box optimization: you have a function $f(x,y,z)$ where you have the ability to evaluate $f$ on an input of your choice, and you want to find $x,y,z$ that maximizes $f(x,y,z)$. (Here $x$ is the decision threshold, $y$ is the maximum % gain per trade, and $z$ is the stop loss, and $f(x,y,z)$ is the amount of ending money at the end of a backtest with those parameters.)

There is a broad literature on black-box optimization, with many methods you could try. See, e.g., Google Vizier, BBComp, and derivative-free optimization; there are many other resources as well.

One last warning: your current procedure is likely to greatly overfit. If you get a rate of return of 10% on your historical data, that doesn't mean this is expected to give you a rate of return of 10% on future data; the future return rate will probably be far lower, due to overfitting. If you want to estimate the likely future rate of return, I suggest you split your historical data into a training set and a validation set (e.g., 4 months into the training set, 3 months into the validation set). Use the training set for the backtesting and to select the parameters. Then, once you have picked a value for the parameters, you can measure how well it performs on the validation set. To avoid bias, you're only allowed to use the validation set once -- if you don't like the results you get on the validation set, you're not allowed to go back to the training set and try to choose new parameters.

Personally, I suspect that 7 months won't be nearly enough. There are financial behaviors that only occur once every few years (e.g., due to financial cycles that occur on a multiple-year horizon), so it's likely that optimizing based solely on 7 months of historical data could lead you to parameters that might perform badly when the situation changes.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.