MrMarc

3123 Reputation

16 Badges

12 years, 315 days

MaplePrimes Activity


These are answers submitted by MrMarc

"For example, f(1) = p (this is just the probability that the last trial is a success), while f(2) = 2*p*(1-p)  (the probability that there is exactly one success in the last two trials, i.e. either (failure, success) or (success, failure)).  For k = 1 to be optimal you need f(1) >= f(2), which is equivalent to p >= 1/2.  Your coin-flip is p = 1/2.    And indeed for p = 1/2, (1-p)/p = 1."


I like this explanation a lot. Very powerful but still simple :-).
I think I managed to figure it out as seen below. On thing that is important to remember
though is that the first observation is actually the last one as pointed out by Robert.

You should reject every roll until only five rolls of the dice remains. Then if you get a 6 during
any of these last five attampts you should declare that this is the last six!

Again Robert I want to thank you for your help and support. I dont think I would have managed
to understand it otherwise. Feal free to point out any errors that still might be present.


restart;
with(plots):
with(plottools):
f := proc (k) options operator, arrow; eval(k*p^s*(1-p)^(k-s), {p = 1/6, s = 1}) end proc:
evalf(k = solve(diff(f(k), k) = 0, k));
A := evalf(add((1/6)/(1-1/6), x = 1 .. 5), 5);
display({plot(f(k), k = 1 .. 5, filled = true, color = green), plot(f(k), k = 1 .. 10, color = black, thickness = 2), textplot([[3, .15, A]], align = {above, right}, font = [Times, Roman, 15])});

                        k = 5.484814948
                               1.

I think I managed to crack it :-)


restart:
with(Sockets):

str := "";
sid := Open("google.com", 80);
Write(sid, cat("GET /finance/historical?cid=626307&startdate=Aug+26%2C+2009&enddate=Aug+25%2C+2010 HTTP/1.0 \n\n"));

b := Read(sid); while b <> false do str := cat(str, b); b := Read(sid) end do;
Close(sid);
str;

The question remains though if you can do the downloading simultiously (ie threads) ???

I guess I could type:

FormatTime("%Y-%m-%d", offset = -24*(60*60)*30);

                          "2010-07-26"

but then I get the date 30 days ago humm.
If the date is 2010-08-25  then I want 2010-07-25

I know that you can not change the size of a slider (embedded components)
which is a major weaknesses. I am not sure for Maplet...but I think you can..

Try to look at this yahoo finance application at the Maple Application center:

www.maplesoft.com/applications/view.aspx

look also at the post at the Mapleprimes:

www.mapleprimes.com/forum/yahoofinancedownloaddata

The yahoo finance tags are very obscured which does not seem to be the case for
the climate data website. So I think it can be done. I will try to play around and
see if I can get it to work ..
 

In the cross sectional example you have a high probability of a win when r1 and r2
have the same sign because you are betting that r3 will have the oppositie sign.
If they do not have the same sign then you check if r1 and r3 have the same sign.
If they do then you bet that r2 will have the oppositie sign. If they do not have the
same sign then you check if r2 and r3 have the same sign. If they do then you
bet that r1 will have the oppositie sign.

"Since r[i] is independent of r[i-1] and r[i-2], knowing r[i-1] and r[i-2] doesn't help you guess r[i]."

This is true. The 5 million dollar question is how can you get a round that ? There has to be
a way that you can take the dynamics from the "cross sectional" example an apply it to a
time series perspective. The weakness with the "cross sectional" example is that it does not
apply to the real world. For example if you have a 3 stock portfolio then you know the returns for
these three stocks at time t, t+1, t+2 etc. This means that it does not matter if you can correctly
guess the return of for example stock 3 at time t because you already know it.

In the cross sectional example the expected value is far from zero.

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

n := 500:
r1 := Sample(RandomVariable(Normal(0, 1)), n):
r2 := Sample(RandomVariable(Normal(0, 1)), n):
r3 := Sample(RandomVariable(Normal(0, 1)), n):

for i to n do
if `and`(r1[i] > 0, r2[i] > 0) then zz[i] := -r3[i]
elif `and`(r1[i] < 0, r2[i] < 0) then zz[i] := r3[i]

elif `and`(r2[i] > 0, r3[i] > 0) then zz[i] := -r1[i]
elif `and`(r2[i] < 0, r3[i] < 0) then zz[i] := r1[i]

elif `and`(r1[i] > 0, r3[i] > 0) then zz[i] := -r2[i]
elif `and`(r1[i] < 0, r3[i] < 0) then zz[i] := r2[i]
else zz[i] := 0 end if

end do:

r5 := [seq(zz[i], i = 1 .. n)]:

display({plot(ExpectedValue(r5), x = 0 .. n, thickness = 3), listplot(r5, thickness = 2)});
 




Why does not the same dynamics apply in the time series example ?

"What do you mean by "bet that r1 will be negative when r2>0 and r3>0 and that r1 will be positive when r2<0 and r3<0" ?"

That is the way the cross sectional example works. You have three random variables r1, r2, r3.
At time i  then you check

if  r1[i]>0  and r2[i]>0   then you bet that r3[i]<0 ie you multiply r3[i] return with -1 hence a
positive return if r3[i] is negative and a negative return if r3[i] is positive.

if  r1[i]<0  and r2[i]<0   then you bet that r3[i]>0 ie you get r3[i] return. If r3[i] is positive then
you get a positive return and if r3[i] is negative then you get a negative return.

you do the same reasoning for the other combinations r2[i] and r3[i]   &  r1[i] and r3[i].
You will only be holding one bet per time period.

Your second question:  If r2 and r3 have different signs then there is no bet. You simply pass ie return=0 .
I am very intrigued by the second piece of code above (cross sectional)
because the expected value is positive. The thing is that the more variables
you add ie r1,r2,r3,r4,r5...n etc then your probability of winning goes to 1
The expected value is however decreasing given a bet size of 1 but it is still positive.

I want to find a way to get the time series example to work as well because the reasoning
is more or less the same as in the cross sectional example. Both examples deal with independent random
variables so the cross sectional example should not work either but id does....magic :-)

The code for the cross sectional example (where the betting strategy is working) is provided below.
Again I am puzzled as to why the same argument does not work for the time series example ...humm


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

n := 500:
r1 := Sample(RandomVariable(Normal(0, 1)), n):
r2 := Sample(RandomVariable(Normal(0, 1)), n):
r3 := Sample(RandomVariable(Normal(0, 1)), n):

for i to n do
if `and`(r1[i] > 0, r2[i] > 0) then zz[i] := -r3[i]
elif `and`(r1[i] < 0, r2[i] < 0) then zz[i] := r3[i]

elif `and`(r2[i] > 0, r3[i] > 0) then zz[i] := -r1[i]
elif `and`(r2[i] < 0, r3[i] < 0) then zz[i] := r1[i]

elif `and`(r1[i] > 0, r3[i] > 0) then zz[i] := -r2[i]
elif `and`(r1[i] < 0, r3[i] < 0) then zz[i] := r2[i]
else zz[i] := 0 end if

end do:

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

You can start by assigning number the TicTacToe board game as follows:

1   2    3
4   5    6
7   8    9

Then the 252 different permutations ie [1,2,3,4,5,6,7,8,9] where each location number can take a
value of 0 or 1 are given by the code below. I have removed all the permutations which have more than
5 1's or 5 0's since these are impossible to get due to that the two players take turnes.

restart:
with(ListTools):
intp := `@`(indices, Array):
A := [intp(`$`(0 .. 1, 9))]:
AA := map(proc (x) options operator, arrow; `if`(5 < Occurrences(0, x) or 5 < Occurrences(1, x), NULL, x) end proc, A);
nops(AA);
 

In order to get it to work I think the plot component should be named Plot0 and you
also need a Do call in the end ie after end proc:

DocumentTools:-Do(%Plot0 = f());
 
Then it works for me in Maple 13 :-)

Beautiful stuff. Thanx for explaining that to me :-)

Ok, thanx. Two more questions:

1) How do you know that Covariance(X[1], X[2]) = (a+b-(a+2*b+c)^2)  and
StandardDeviation(X[1])*StandardDeviation(X[2]) = (a+2*b+c-(a+2*b+c)^2)  ??


2) I have experimented with the trivariate normal distribution a bit. I have found the
below code to be accurate in a three variable case. It would be nice to be able to
show graphically in a 3D plot that the probability of getting three heads ie 0.5*0.5*0.5=0.125
increases when the the cross correlation increases. Any ideas ?!


restart:
with(Statistics):
with(LinearAlgebra):
with(plots):

N := 3:
h := proc (i) options operator, arrow; x[i] end proc:               X := Vector(N, h):
g := proc (i) options operator, arrow; mu[i] end proc:           M := Vector(N, g):
w := proc (i) options operator, arrow; sigma[i] end proc:     S := Vector(N, w):

CorrMat := Matrix([seq([seq(`if`(i = j, 1, p[i, j]), j = 1 .. N)], i = 1 .. N)], shape = symmetric):
Covar := Zip(`*`, simplify(S.Transpose(S)), CorrMat):

pdf1 := simplify(exp(-(1/2)*(Transpose(X-M).(1/Covar).(X-M)))/((2*Pi)^((1/2)*N)*sqrt(Determinant(Covar))), symbolic):
pdf2 := eval(pdf1, {mu[1] = 0, mu[2] = 0, mu[3] = 0, sigma[1] = 1, sigma[2] = 1, sigma[3] = 1, p[2, 1] = 0, p[3, 1] = 0, p[3, 2] = 0}):
cdf := evalf(int(pdf2, x[1] = -infinity .. 0, x[2] = -infinity .. 0, x[3] = -infinity .. 0), 5);

                               cdf := 0.12500


Ok, thanx Robert. I got a couple of questions:

1) Could you please explain why the correlation coefficient is given by:
(a+b-(a+2*b+c)^2/(a+2*b+c-(a+2*b+c)^2)
I need to understand this equation if I am going to use it.


2)  Why is the Expected Value equal to  a + 2*b + c = m  ?


3) "The probability of three heads or three tails is then a + d"
Where do you get the expession from d from ?  You only solve for a,b and c (not d)  in
solve(eqs,{a,b,c});


4)  When I evalute your final expression for probability of three heads or three tails with expected
value (m) =0  ie   eval(3*m^2+3*p*m-3*p*m^2-3*m+1, m = 0)  then I get  1. I dont understand this.
If you toss three random coins with expected value=0 is then the probability of three heads
or three tails =1 ?  It does not make any sense. Also the correlation coefficient seems to be
canceled out. I would assume that if the coins have a high + cross correlation then the probability
of three heads or three tails would be greater and if the coins have a high - cross correlation then
the probability of three heads or three tails would be smaller......hummm


5) Is it posible to do this with a trivariate normal distribution ie a multivariate normal distribution.
and then simple integrate the pdf from -infinity to 0 for all three variables to get p (H, H, H)  ie cdf.
I have tried to get the pdf for a multivariate normal distribution but it involves matrix algebra ie

(1/ (2*phi))^(p/2) * ¦COV¦^(-1/2) * exp{ -0.5 *(X-m)' COV^(-1) * (X-m) }

I find this very complicated and difficult to get a valid pdf.
I would appreciate if anyone could show me how this would be done :-)

With second thought it kind of make sense to have  add(0.5, x = 0 .. 7) = 4.0 
Since a 0.5 line has a value of 0.5 at 0  ie  add(0.5, x = 0 .. 7) = add(0.5, x = 1 .. 8) = 4.0
I am not completely comfortable with that    int<> add   but I might get over it :-)

1 2 3 4 5 6 7 Last Page 3 of 25