# How to “uncluster” a set of financial data?

I am attempting to evaluate and compare the profit factor of different "test runs" of a FOREX trading strategy.

My problem is that, despite an average time between orders of 2hr+, some of these runs can have 20+ orders in a row, every 5 minutes, in the same direction. I need some way to normalize these clusters that occur without just throwing the data out.

I want to treat the cluster as 1 data point by averaging the gain/loss of each trade within the cluster.

I was thinking of doing it with a moving time window in the following manner:

````For each order:
Weight = 1/(N+1) 
N =  count of consecutive orders within 30 minutes of the current order.
````

But I am not sure if that is correct.

-

## 2 Answers

That is definitely not correct. Your test results will suffer from look-ahead bias. At the point in time that you will be entering your order, you will not know yet how many orders will come in the next 30 minutes, thus a proper backtest should not use that information to size the trade.

There are many factors to consider when running a proper backtest (see wikipedia), but the key factor behind all of them is to replicate as closely as possible what is realizable in live trading. In your case, that means that you will have to predict how many trades your strategy is about to enter and size all subsequent trades appropriately. Once you reach your "limit," at which point in real trading you would have run out of capital, your backtest is effectively prevented from entering new trades.

If your strategy isn't able to predict whether trades are about to cluster, you could try an incremental system, whereby the first trade is assigned a proportion $\delta$ of total capital, the second gets $\delta(1-\delta)$, etc.

-

This is not true. There is no look-ahead bias. You are right that at the point in the when I enter the order I do not know how many orders will come in the next 30 minutes - BUT - I do know how many orders came in the next 30 minutes of SIMILAR orders to the current order - in the past. THAT is what I am evaluating and what I am basing my entry size on - it is a meta test. – Mike Sep 19 '11 at 0:29
Mike, it sounds like you are trying to get around the fact that you are allowing look-ahead bias by calling it a "meta" test.  I would just be very careful with that.  The way your original question is phrased, it is clear that you cannot use the weight scheme you proposed.  You cannot even replace N with E[N], because there will be some occasions that N>E[N], and your test will implicitly be allowing you to use more capital than you actually have available.  These sort of "meta" tests are nearly worthless for anything but a quick and very rough first pass at the data. – Tal Fishman Sep 19 '11 at 2:08
How could there be look-ahead bias when everything in the meta test has already occurred? – Mike Sep 19 '11 at 2:23
– Tal Fishman Sep 19 '11 at 2:31
That's the thing - it HAS occurred at that point in time. Thats why I call it a meta test. – Mike Sep 19 '11 at 2:42
show 2 more comments

you could perhaps cluster the information in a candle stick manner and bin the price data into high, low and closing, instead of throwing some data out and keeping only its closing price.

Using the high, low and closing prices you are able to make 3 separate estimates with regards to Profit and lost. Obviously with a long position, profit calculated by entering at a high price while using a low price for its exit would be the pessimistic estimate of profit.

-
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 2, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "github"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "english_confidence": 0.9571588635444641, "perplexity_flag": "middle"}