Alexana
unread,Aug 10, 2010, 12:53:50 PM8/10/10Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to JArbitrager
I am new to this group and want to thank all of you who have created
this excellent tool. Since many of you appear to be much better
progammers than I, I doubt I can contribute much in the way of the
code. However, I hope to be able to contribute with some ideas and
insights.
First, I want to make a suggestion with respect to the EMA and SMA
indicators:
Presently, you compute the difference (DIFF) between the price of two
instruments, compute the Exponential (EMA) or Simple (SMA) moving
average of that difference and calculate the Value as the spread
between current difference and one of the moving averages. This Value
is then compared to Entry, which was predetermined through an
optimization process. If the Value exceeds the Entry, then the Buy or
Sell action is initiated.
There is a conceptual problem with using fixed value for Entry: the
Entry may be time dependent, i.e. during the periods of high
volatility the Entry may need to be set higher than during low
volatility periods. The optimization process will find some globally
optimal value of Entry, which may not work for low or high volatility
regimes.
The methodology will work much more consistently if the Value is
standardized by the Standard Deviation of the DIFF. If the DIFF is
normally distributed around EMA (or SMA), then setting the Entry = 2
(i.e. two standard deviations from the average) will guarantee with
high probability that the price spread will mean revert. In reality,
the true probability distribution may be leptokurtic (have heavier
tails than normal). Using the optimizer to select the proper multiple
of Standard Deviations will help deal with the heavy tails.
For Simple Moving Average, the standard deviation can be easily
implemented by adding lines in SmaDifferential.java class:
double stdev =
diffs.getStdev();
value = (diff - mean)/
stdev;
For Exponential Moving Average, the standard deviation should have
appropriate exponential weighting. It could be implemented in the code
of the EmaDifferential.java by adding lines:
import
static
java.lang.Math.*;
private
double emm2;
In the calculate() method the following lines would be added,
computing exponentially weighted standard deviation as the square root
of the difference of the exponentially weighted second moment and the
square of the exponentially weighted first moment:
// emm2
computes exponentially weighted second moment of diff;
emm2
+= ( pow(diff,2) - emm2) * multiplier;
//
sqrt(emm2 - pow(ema,2)) is the standard deviation of diff;
value = (diff - ema) / sqrt(emm2 - pow(ema,2));