Z-Score For MA Differences

Optuma Forums Optuma Scripting Z-Score For MA Differences

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #57387
    AvatarDan
    • Topics: 1
    • Replies: 0
    • Posts: 1

    Hi Everyone:

     

    I am trying to find the z-score for the difference between 2 MAs. Can you help?

    #57391
    MathewMathew
    • Topics: 28
    • Replies: 1,290
    • Posts: 1,318

    Hi Dan,

    Easiest way is to use the Z-Score 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:

    If that is not doing what you need, let us know.

    All the best

    Mathew

    #57403
    AvatarThomas
    • Topics: 53
    • Replies: 71
    • Posts: 124

    Hi Mathew,

    I allow me to link into this discussion about the z-score test.

    I have seen and read something about the z-score test to verify the significance of a test. SentimenTrader (https://www.sentimentrader.com) works a lot with z-score testing.

    Can you give me some more information about z-score testing e.g. internet links etc.?

    The z-score tells us how many standard deviations a value is from its mean. A z-score 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 z-score mean in relation to the two moving averages? Lets say e.g. the z-score 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

    #57405
    MathewMathew
    • 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

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.

Pin It on Pinterest

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close