Have you tried using EMA-like processing to weight the most recent events
higher?

so
            n++;
            sumX += balance;
            sumXX += (balance * balance);
            sumY += price;
            sumYY += (price * price);
            sumXY += (price * balance);

becomes:
            n++;
            sumX += alpha * (balance - sumX);
            sumXX += alpha * (balance * balance - sumXX);
            sumY += alpha * (price - sumY);
            sumYY += alpha * (price * price - sumYY);
            sumXY += alpha * (price * balance - sumXY);

It seems like this should do the trick...

On Tue, Aug 4, 2009 at 4:22 PM, nonlinear5 <[email protected]> wrote:

>
> I have a new indicator, called DepthPriceCorrelation. It's not in the
> release yet, but it's in SVN
>
> http://code.google.com/p/jbooktrader/source/browse/trunk/source/com/jbooktrader/indicator/depth/DepthPriceCorrelation.java
>
> The indicator is based on the idea that current price can be
> considered "fair" when the correlation between market depth balances
> and market prices is positive. This positive correlation occurs when:
>
> -- high depth balances are accompanied by higher prices
> or
> -- low depth balances are accompanied by lower prices
>
> When the correlation is negative, the prices are moving in the
> direction opposite from the direction of depth balances, and I call it
> a "high tension" condition. This is when my strategy gets into a
> position on the bet that the tension will ease and the correlation
> will return to its "normal" positive value. Here is an example of such
> a strategy:
>
> http://code.google.com/p/jbooktrader/source/browse/trunk/source/com/jbooktrader/strategy/TensionSeeker.java
>
> Now, to calculate the correlation, the indicator simply updates the
> running sums for prices and balances, and then uses a standard
> correlation coefficient formula to come up with the result. This is
> very efficient, and it works well. The problem is, sometime in the
> second half of the trading session, the indicator becomes too "stale",
> because it uses all the data accumulated so far during the trading
> session. So, at say, 2pm, the indicator would represent the
> correlation between balances and prices based on all the data from
> 9:30am to 2pm, while my strategy is looking for a shorter term
> correlation, such as the last 2 hours. It's certainly possible to
> recalculate the indicator based on this 2-hour moving window, but it
> would be very computationally expensive, since every time, I would
> need to loop through the last two hours of values, instead of simply
> updating the running sums.
>
> So, here is the question for the algorithmically inclined. How do I
> *efficiently* calculate the correlation between X and Y in a moving
> time window?
>
>
>
>
> >
>


-- 
Martin Koistinen
Sisu Consulting
www.sisuconsulting.com

+44 7703 046 154 (mobile)
+44 (0) 20 3286 3710 (London)
+1 (678) 389-6676 (Atlanta)
+1 (832) 426-3791 (Houston)

100% carbon-neutral as of 1-Jan-2008.
"Act without Activism"

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"JBookTrader" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/jbooktrader?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to