Optuma Forums › Optuma Scripting › ZScore For MA Differences
 This topic has 3 replies, 3 voices, and was last updated 1 week, 6 days ago by Mathew.

AuthorPosts

March 17, 2020 at 12:02 pm #57387Dan
 Topics: 1
 Replies: 0
 Posts: 1
Hi Everyone:
I am trying to find the zscore for the difference between 2 MAs. Can you help?
March 17, 2020 at 12:12 pm #57391Mathew Topics: 28
 Replies: 1,290
 Posts: 1,318
Hi Dan,
Easiest way is to use the ZScore function in scripting on an Oscillator. The simple oscillator tool is the difference between two MAs.
One thing to note, the ZScore works by calculating the average and standard deviation over a look back period and then for each point measuring the number of standard deviations away from the average.
Script would be:
1234o1=OSC(BARS1=50, BARS2=200);ZSCORE(o1)If that is not doing what you need, let us know.
All the best
Mathew
March 17, 2020 at 7:29 pm #57403Thomas Topics: 53
 Replies: 71
 Posts: 124
Hi Mathew,
I allow me to link into this discussion about the zscore test.
I have seen and read something about the zscore test to verify the significance of a test. SentimenTrader (https://www.sentimentrader.com) works a lot with zscore testing.
Can you give me some more information about zscore testing e.g. internet links etc.?
The zscore tells us how many standard deviations a value is from its mean. A zscore of 1.95 and 1.95 means that there is a statistical significance since it corresponds with a standard deviation of 2 to 2. A standard deviation between 2 and 2 means that 95% of the values are in this area.
In your script above what does the value of the zscore mean in relation to the two moving averages? Lets say e.g. the zscore is 1.37 in the above script using the S&P 500 data. What does that mean in plain English explained?
Thanks a lot.
Thomas
March 17, 2020 at 8:58 pm #57405Mathew Topics: 28
 Replies: 1,290
 Posts: 1,318
Hi Thomas,
ZScores are simply multiples of standard deviations.
 We calculate an average over a lookback period (say 20 bars)
 We look at all the points that led to that average and from them we calculate the variance σ² (squared average distance from the average value) and then the standard deviation is σ.
 The ZScore value is distance from the final bar’s close to the average value divided by σ. It is the distance measured in units of standard deviations.
 Then we move to the next bar and repeat the process.
Doing so tells us how “significant” (or insignificant) the close was compared to our average. In this type of use, I would argue that a lone observation a long way from the average (high number of σ) is not significant but rather an aberration.
Where this get confusing is that in Hypothesis Testing (which we use in the MonteCarlo section of the Back Tester in Optuma) we use “significance” to compare our test result against thousands of random variations of our test. This all comes down to the primary premise of TA – that our analysis is giving us results which are better than random. If my test is more than 1.95σ away from the average, then I can argue that it is statistically significant and not the result of luck.
Look at Lecture 1 on this page (you do not need to buy the course to see the preview) I explain this more in that video.
https://learn.optuma.com/course/quant/ Note that I am waiting to finish that course for when I have our new generation of testers in place.It is the mixing up of these ideas which led to the problems with VaR (value at risk). Analysts were calculating the average moves in a security and from that, the standard deviation. The issue came that they believed that a price move of more than 2σ was so rare that they built in risk models which did not allow for bigger moves (ie. their capital reserves did not need to be bigger). In their models they completely understated the probability and magnitude of “black swan” events and some argue that it is what made 2008 so bad. Essentially they took the theory of hypothesis testing significance and applied it to daily moves in the market.
There are other complications such as 2 tailed v’s single tailed tests.
Hope that helps
Mathew

AuthorPosts
 You must be logged in to reply to this topic.