Question:beat randomness

Question:beat randomness

Maple

One thing I am struggling to understand is the following:

If you have three randomvariables (similarities to the hat puzzle) then you
can get a positive expected value if you for example bet that r1 will be negative
when r2>0 and r3>0 and that r1 will be positive when r2<0 and r3<0. It follows
because the probability of getting [+,+,+] + [-.-.-] = 0.5^3+0.5^3=0.25. Which
means that the probability of success for our introduced betting strategy is 0.75.

I have now started to think about it from a time series perspective instead from
a cross sectional perspective. I mean it should work the same way here. The
probability of getting three positive returns is given by 0.5^3=0.125 so the optimal
strategy should be to bet that the return is negative after you have had two positive
returns. However, the problem is that it does not work as seen in the code below.
I am puzzled. I am clearly missing something important here. The question is:
What is it ?

restart:
with(plots):
with(Statistics):
randomize():

n := 500:
r1 := Sample(RandomVariable(Normal(0, 1)), n):
z1[1] := 0:   z1[2] := 0:

for i from 3 to n do
if `and`(r1[i-2] > 0, r1[i-1] > 0) then z1[i] := -r1[i]:
elif `and`(r1[i-2] < 0, r1[i-1] < 0) then z1[i] := r1[i]:
else z1[i] := 0 end if :
end do:

r4 := [seq(z1[i], i = 1 .. n)]:
display({plot(ExpectedValue(r4), x = 0 .. n, thickness = 3), listplot(r4, thickness = 2)});

﻿