Rank: Advanced Member
Groups: Registered, Registered Users, Subscribers, Unverified Users Joined: 10/28/2004(UTC) Posts: 3,111 Location: Perth, Western Australia
Was thanked: 16 time(s) in 16 post(s)
|
At another online forum, one of our members asked a question: "Has anyone tried the volatility formulas below and does it make
mathematical sense?" and posted the code:
Code:
HiV:=(CLOSE>20 AND (HHV((Std(Log(C/Ref(C,-1)),23) * Sqr(365)),5))
<
(HHV((Std(Log(C/Ref(C,-1)),23) * Sqr(365)),253)) AND
Ref((HHV((Std(Log(C/Ref(C,-1)),23) * Sqr(365)),5))
,-1)=Ref((HHV((Std(Log(C/Ref(C,-1)),23) * Sqr(365)),253)) ,-1) AND
(Std(Log(C/Ref(C,-1)),23) * Sqr(365))< Ref((Std(Log(C/Ref(C,-1)),23) *
Sqr(365)),-1));
LowV:=CLOSE>20 AND (Std(Log(C/Ref(C,-1)),6) * Sqr(365))
<0.5*(Std(Log(C/Ref(C,-1)),100) * Sqr(365)) AND
(Std(Log(C/Ref(C,-1)),10) *
Sqr(365))<0.5*(Std(Log(C/Ref(C,-1)),100) * Sqr(365));
NeuV:=((Std(Log(C/Ref(C,-1)),6) *
Sqr(365))>0.5*(Std(Log(C/Ref(C,-1)),100) *
Sqr(365)) OR (Std(Log(C/Ref(C,-1)),10) *
Sqr(365))>0.5*(Std(Log(C/Ref(C,-1)),100) * Sqr(365))) AND
(Ref((HHV((Std(Log(C/Ref(C,-1)),23) *
Sqr(365)),5)),-1)<Ref((HHV((Std(Log(C/Ref(C,-1)),23) *
Sqr(365)),253)),-1) AND
CLOSE>20);
HiV;
LowV;
NeuV;
The post and the question gives us a great learning opportunity, so I post my response here for our members, knowing the OP will also visit here at some point and get his answer. The code itself looks quite scary at first, so you have to ask yourself, "What is really going on in the code and why are they trying to hide it?" The easiest way to figure this out is to replace all the same expressions with variables, which also happens to speed up processing and makes later editing of the code easier. With all the repetition of the expressions and unnecessary multipliers removed we see more clearly: Code:
minPrice:=C>20;
logc:=Log(C/Ref(C,-1));
x6:=Std(logc,6);
x10:=Std(logc,10);
x23:=Std(logc,23);
x100:=0.5*Std(logc,100);
x23H5:= HHV(x23,5);
x23H253:=HHV(x23,253);
HiV:= x23H5<x23H253 AND Ref(x23H5,-1)=Ref(x23H253,-1) AND x23<Ref(x23,-1);
LowV:=x6<x100 AND x10<x100;
NeuV:=(x6>x100 OR x10>x100) AND Ref(x23H5,-1)<Ref(x23H253,-1);
minPrice*HiV;
minPrice*LowV;
minPrice*NeuV;
IMHO, the code is "junk" and makes little sense. It is a [censored]isation of statistical volatility concepts; the original code kept multiplying by values which are not required which gives a strong clue as to the validity of the process. If we consider some simple logic: the code writer wants to classify volatility as high, low or neutral, but unfortunately for them, they have coded situations where the volatility is neither high, low nor neutral. What is this fourth condition? Personally, I would use a catch-all to define the remaining condition given other criteria e.g. if I am defining high and low volatility in my code, then neutral volatility would be the condition when neither high or low were true; if I was defining high and neutral volatility, then low volatility would be the condition which exists when the volatility is neither high nor neutral etc. We can see why this happens when we look at the LowV and NeuV variables. If you use other people's works without fully analysing the code and how it works -- that's up to you. Even if you have the code but don't put in the effort to discover how and why it works, then you might as well buy some black-box trading system, cross your fingers and hope the coder has done everything right. Analysing codes also applies for the "basic" set of technical indicators; I love attending conferences etc and listening to people spruik about RSI and Stochastics, so I then ask them how they are computed and they have no idea! Personally, I don't trade anything I haven't fully analysed and strongly urge all traders to spend the time and effort to understand what is actually driving the things which are driving your trading decisions. wabbit [:D]
|