[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Pattern matching



PureBytes Links

Trading Reference Links


Here is a technique that might be used for pattern matching. I am just 
throwing this idea out and haven't thought it out in detail.

Suppose for n set of market conditions a set of symbols s1...sn which 
provide a snapshot of a market for a trading period (day, 15 minute bar, 
week, etc.). Then for each time series there is a correlated string of 
symbols. For any set of such symbols it is possible to find a string 
constituing a subset of the symbols in the time series using a regular 
expression match.

Example:

Suppose the following symbol set:

h: today's high is higher than yesterday's high, but by less that 5%
H: today's high is higher than yesterday's high, but >= 5%
s: today's high is lower than yesterday's high, but by less than 5%
S: today's high is lower than yesterday's high, but by >= 5%

A representative string then might read:

shSShhhshSSShhsshhhhhHSSsHhhhhs

Using a regular expression we might substitute some other string for 
certain patterns and then test for trading opportunities.

test1: hhhHS
test2: SSsH

Let test1 be the test for a short rule and test2 be the test for a buy rule.
Since the first 4 symbols in the short rule could be construed to be the 
setup for the sell at position 5, we could substitute a short symbol at 
that position. Likewise a sell symbol could be substited for position 4 
in test2.

Using U as the buy signal and D as the sell signal, here is how it might 
work using Perl:

$data = 'shSShhhshSSShhsshhhhhHSShHhhhhs';
$sell_opportunities = $data;
$sell_opportunities =~ s/hhhHS/hhhHD/g;
$buy_opportunities = $data;
$buy_opportunities =~ s/SSsH/SSsU/g;

Now test by checking the profit, drawdown, etc. associated with going 
short or long at the corresponding times in the series where there is a U 
or D. Comments?

Cheers,

Jim

--
http://www.ilinks.net/~airesearch/marketalert/