Re:Show HN: I discovered a trading algorithm that returns ~2...
by a1369209993 on Sunday June 06, 2021 @08:46PM
(#27417799)
> Go up 50% then down 50% and you're not even, you're down 25%.
It helps if you measure in the right units[0], namely bits, orders of magnitude, or fractions thereof. Up 50% is log(1.5) = +0.58 bits, down 50% is log(0.5) = -1 bits, and indeed 0.58-1 = -0.42, or 1.5*0.5=0.75, down 25%.
0: Well, strictly speaking the problem is that up/down X% isn't even in units at all.
Re:Show HN: I discovered a trading algorithm that returns ~2...
by economusty on Sunday June 06, 2021 @09:19PM
(#27417996)
I assumed they meant dollars.
Re:Show HN: I discovered a trading algorithm that returns ~2...
by hervature on Sunday June 06, 2021 @04:21PM
(#27415978)
Don’t know why this is on HN front page given it is an error.
Re:Show HN: I discovered a trading algorithm that returns ~2...
by ryanmonroe on Sunday June 06, 2021 @05:27PM
(#27416497)
The wording in the original comment was too strong, I've edited it. It's probably not best to consider it a plain "error" since this calculation is actually a typical one provided in finance. It's just that you usually look at other stats too rather than just this one, which gives you an idea about its accuracy wrt realized return e.g. Sharpe, Max Drawdown, Skew, Kurtosis
Re:Show HN: I discovered a trading algorithm that returns ~2...
by hervature on Sunday June 06, 2021 @08:19PM
(#27417619)
No, you were correct, arithmetic mean of returns is not standard in finance. If it was, financial crashes would be much worse. They do arithmetic means of "log returns" because 1/n sum(log(r)) = log(product(r)^(1/n)). That is, in log world, the arithmetic mean is the geometric mean.
Re:Show HN: I discovered a trading algorithm that returns ~2...
by joppy on Sunday June 06, 2021 @06:18PM
(#27416879)
Is it normal to deal with returns over time as log-returns log(R) rather than simple returns (R - 1) for this reason? The average log return does the right thing.
Re:Show HN: I discovered a trading algorithm that returns ~2...
by SomewhatLikely on Tuesday June 15, 2021 @10:38AM
(#27516164)
Right, I used to use the geometric mean when dabbling in this area in my teens which is mathematically equivalent to averaging the log returns.
Re:Show HN: I discovered a trading algorithm that returns ~2...
by nwallin on Monday June 07, 2021 @12:21PM
(#27424345)
The uniform distribution is the wrong distribution for this. A normal distribution is better, but also wrong- the normal distribution significantly under-predicts extreme events relative to the stock market.
Can you try it with the Laplace distribution? It's a bell curve like the normal distribution, but has fat tails. Extreme events aren't common, but much more common than with a normal distribution.
Re:Show HN: I discovered a trading algorithm that returns ~2...
by jiofih on Sunday June 06, 2021 @04:27PM
(#27416016)
Where do you take that uniform distribution from? I don’t think any ETF would conform to that.
Re:Show HN: I discovered a trading algorithm that returns ~2...
by whoisburbansky on Sunday June 06, 2021 @06:33PM
(#27416975)
> I chose uniformly distributed returns with a wide range to make the reason against this calculation very obvious.
The uniform distribution is a pedagogical choice, to explain why OP's average return calculation is misleading.
Re:Show HN: I discovered a trading algorithm that returns ~2...
by jiofih on Monday June 07, 2021 @08:31AM
(#27421781)
That’s the point - the choice of a normal distribution is misleading. It doesn’t model market behaviour on any time scale.
Backtesting is more likely to be meaningful. Am I missing something here?
Re:Show HN: I discovered a trading algorithm that returns ~2...
by whoisburbansky on Monday June 07, 2021 @11:12AM
(#27423520)
The question isn’t backtesting vs no backtesting. The question is do you use the arithmetic mean of daily returns as your metric or use the final return over the entire period. The arithmetic mean hides the fact that large downswings hurt your net return more than they would otherwise seem to, and is therefore misleading, making the strategy looking better than it actually is.
Here's the calculation used in main.js line 77 applied to a very extreme unrealistic example. I simulated 253 days of return percentages from a uniform distribution between -5.5% and 5.6%, and then the actual total return percent, calculated in R
Edit:In reality the actual numbers are likely to be not nearly as different as this example. I chose uniformly distributed returns with a wide range to make the reason against this calculation very obvious. Here's an example return distribution where there's hardly any difference. Normal returns with average of 0.085% and standard deviation of .05 i.e. daily_gain <- rnorm(n, .085/100, .05/100) gives
For good measure here's one in the middle where your returns are normally distributed with an average of 0.35% and a sd of .2%, but then you have on average 10 bad days a year where returns are 5 percentage points lower than that distribution i.e. daily_gain <- rnorm(n, .35/100, .2/100) - rbinom(n, 1, 10/n)*.05 gives