Rounding when backtesting - how do you deal with it?
Author: antonmueller
Creation Date: 4/23/2015 3:20 PM
profile picture


Hi there,

I'm currently evaluating Wealthlab and started using Yahoo data.

When I backtest a strategy (for example the 3x2 system from the examples that come with WealthLab) on a stock or ETF, for example SPY, on the charts I never see anything beyond 2 decimals.

When I look more closely and do "edit bar data" there are much more decimals which comes from yahoo and the adjusted close I guess. But even when I use the "raw data" from yahoo, not adjusted to splits/dividends when there are no more decimals at least for recent data, WealthLab seems to not round up to two decimals when backtesting.

So looking at SPY for example in the results I see (RAW mode, always trade 1000 shares, no commissions or slippage applied):

Long Trade: 1000 Quantity, Entry: 209.84, Exit: 207.26 which would result in (209.84 - 207.26) * 1000 = $2580.

But in the results I get $2583.32. After looking into the bar data I understand why. WealthLab takes the unrounded data provided by yahoo for example and calculating limit-order entries for example it does the same.

So it's actually (209.84331178997 - 207.25999) * 1000 = 2583.32178997000 which is then rounded to $2583.32

So far so good but I wonder if this is a realistic way of backtesting? You'll hardly get filled at that price in the real world. At the same time I'm aware that due to splits etc. using the adjusted data it can be more realistic to work with the fractions...

How do you guys handle this? Do you always round everything to two decimals (in stocks)? And if so how do you translate this to the real world of trading when going live with a system? How do you round your orders then?

Looking forward to your input, maybe I'm just missing something and hope to get the puzzle more complete!

profile picture


Hi Anton,

This is the effect of the dividend adjustment applied by the Yahoo! provider. You can minimize its effect by unchecking "Perform dividend adjustment" on provider's Data Manager tab > Yahoo! Data.
profile picture


Hi Eugene,

I'm aware that this is the reason for the issue but my question is more like how to deal with it and what the most realistic approach might be.

So even if I turn off dividend adjustments for yahoo data and I have a strategy that for whatever reason would exit on 5/5/2000 at the open, the price used by WealthLab to calculate profits by default is 141.0625 - a price where in reality no fill would have happened (unless you got filled at different prices).

My question is would it be more realistic to use 141.06?

And the second question is when using divident adjusted data, is it more realistic to round everything (limit-entries etc.) to 2 decimals or is it actually more realistic to have 4 decimals since if a split happened at some place that might be closer to reality since the actual price was for example 100.50 and due to a 4:1 split in the adjusted data it's now 25.1250?

I just wonder how to deal with this...everyone using adjusted data must have run into this issue at some point I guess - so what are your thoughts?

profile picture


In backtesting, absolute precision of the trade price is not high on my list of requirements. My need is more for consistency so I can compare. I want to know, "Did this change make the strategy better or worse?", or "For this portfolio/timeframe, is strategy A better than strategy B?" The absolute numbers are less important and small errors are tolerable. Just my opinion.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).