MrMarc

3123 Reputation

16 Badges

12 years, 315 days

MaplePrimes Activity


These are replies submitted by MrMarc

Alternately derive this in Maple:

Consider the following two person game. Each person is given a random number generated from a standard uniform distribution with boundaries 0 and 1. The goal is to get a number that is as large as possible. Now each person is given the option to discard his allocated number and receive a new random number. This choice is made without knowing the other players number or whether the other player chose to replace his number. After each player has had an opportunity to replace his number the numbers are compared and the player with the higher number wins. What strategy should a player follow to ensure he will win at least 50% of the time?


A player will ensure he wins at least 50% of the time by choosing to receive a new number when his original number is less than (sqrt(5)-1)/2 = .6180+.

It should be clear that we need only consider strategies of the form, choose a new number if the original number is < x otherwise keep the original number.

Suppose player A uses threshold x and player B uses threshold y. Then it can be shown that the probability, p, that A will win is

p=.5*(1+x-y-x * y+y * y+x * y * y-x* x * y) for x <= y
p=.5*(1+x-y-x*x+x*y+x*y*y-x*x*y) for x >= y

or

p=.5+.5*(x-y)*(1-y-x*y) for x <= y
p=.5+.5*(x-y)*(1-x-x*y) for x >= y

Suppose A chooses x=(sqrt(5)-1)/2. Note x*x+x=1.

Now if y > x then x*y+y > 1 so (x-y) < 0 and (1-y-x*y) < 0 so
(x-y)*(1-y-x*y) > 0 which implies p > .5.
Also if y < x then x*y+x < 1 so (x-y) > 0 and (1-x-x*y) > 0
so (x-y)*(1-x-x*y) > 0 which implies p > .5.

So if A chooses x = (sqrt(5)-1)/2 he will win more than 50% of the time unless B chooses y = (sqrt(5)-1)/2 also in which case he will win exactly 50% of the time.


or why we put EP(x)=x?


We now assume that player-1 discard his first allocated number if it is lower than a specified threshold denoted by x. We also denote player-1's first allocated numbers with n1 and the second allocated number with n2

We can calculate the expected value for player-1 as follows:

        EP(x) = P(n1 < x) E(n2) + (1 - P(n1 < x)) E(n1)

Since:

restart:
with(Statistics):

Mean(RandomVariable(Uniform(a, b)));
Mean(RandomVariable(Uniform(x, 1)));

CDF(RandomVariable(Uniform(0, 1)), x);
CDF(RandomVariable(Uniform(0, 1)), .5);
CDF(RandomVariable(Uniform(0, 1)), .8);
CDF(RandomVariable(Uniform(0, 1)), .2);


We can write the previous equation as:

EP(x) = .5*x+(1-x)*(.5*(x+1))


Now lets say player-2 enter into the game. What is the optimal threshold for player two ?
In order for Player-2 to win against player-1 he has to make sure that his threshold is equal to the
expected value of player-1 which means that x = EP(x)

EPxx := convert(EPx, rational);
solve(x = EPxx, x)[1];
evalf(%, 10)

@Christopher2222 an honest mistake :-) plus it gave me an opportunity
to improve the formulation to include "exactly"....

@Christopher2222 thanx for looking at the problem with critical eyes.
I think you should interpret "one dollar more than the ball" as strict
ie exactly one dollar more not at least one dollar more.

At least that is my interpretation but I might be wrong. In
maple something like this:


eq1 := x+y = 1.1;
eq2 := subs(y = x+1, eq1);
eq3 := solve(eq2, x);
solve(subs(x = eq3, eq1), y);

                          x + y = 1.1
                         2 x + 1 = 1.1
                         0.05000000000
                          1.050000000


@williamov I dont know what it means but I think it is a result from the central limit theorem that

the more observations you have the closer you get to the expected value

@williamov I dont know what it means but I think it is a result from the central limit theorem that

the more observations you have the closer you get to the expected value

@williamov I noted that as well however if you increase the sample size to 500
it rejects all the time (as it should).

Also you are absolutly correct that it only applies to past events.
It only test past data ie the future is uncertain (you might have a change in expected return)
but the test does not account for that.

@williamov I noted that as well however if you increase the sample size to 500
it rejects all the time (as it should).

Also you are absolutly correct that it only applies to past events.
It only test past data ie the future is uncertain (you might have a change in expected return)
but the test does not account for that.

@williamov it just means that the two sample with a 95% probability is
not drawn from the same distribution for example if you want to compare a trading strategy
with some random data it will tell you if the difference between the
expected values is significant ot not (if it is a good strategy and not only "luck").

You can do it like this as well:

restart:
randomize():
with(Statistics):

infolevel[Statistics] := 1:
data := Sample(RandomVariable(Normal(2, 10)), 100):

OneSampleTTest(data, 0);
OneSampleZTest(data, 0, 10);

@williamov it just means that the two sample with a 95% probability is
not drawn from the same distribution for example if you want to compare a trading strategy
with some random data it will tell you if the difference between the
expected values is significant ot not (if it is a good strategy and not only "luck").

You can do it like this as well:

restart:
randomize():
with(Statistics):

infolevel[Statistics] := 1:
data := Sample(RandomVariable(Normal(2, 10)), 100):

OneSampleTTest(data, 0);
OneSampleZTest(data, 0, 10);

@williamov what about this?


restart:
with(Statistics):

p := .3: q := .2: r := 1: n := 2:

pdf := (p/((p+2*q*T)/(1+p*T+q*T^2)-(p*T+q*T^2)*(p+2*q*T)/(1+p*T+q*T^2)^2))^r*r^2*T^n/factorial(n):

plot(pdf, T = 0 .. 9);

`assuming`([plot(Int(pdf, T = 0 .. xx), xx = 0 .. 5)], [xx > 0]);


Also I am intrigued where do you get the pdf from and what is the application?

@williamov what about this?


restart:
with(Statistics):

p := .3: q := .2: r := 1: n := 2:

pdf := (p/((p+2*q*T)/(1+p*T+q*T^2)-(p*T+q*T^2)*(p+2*q*T)/(1+p*T+q*T^2)^2))^r*r^2*T^n/factorial(n):

plot(pdf, T = 0 .. 9);

`assuming`([plot(Int(pdf, T = 0 .. xx), xx = 0 .. 5)], [xx > 0]);


Also I am intrigued where do you get the pdf from and what is the application?

or like this with cdf's:

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

p := Array(1 .. 1, 1 .. 2):

# Random Data
qq := Quantile(RandomVariable(Normal(0, 1)), .95):
p[1, 1] := display({plot(CDF(RandomVariable(Normal(0, 1)), x), x = -4 .. 4, legend = "CDF Random Data", color = red), plot([qq, y, y = 0 .. 1], thickness = 3, legend = "Quantile 0.95 Random Data", color = black)}):

# Empirical Data
A := Sample(RandomVariable(Normal(2, 1)), 100):
ex := ExpectedValue(A):

p[1, 2] := display({plot(CDF(RandomVariable(EmpiricalDistribution(A)), x), x = -4 .. 4, legend = "CDF Empirical Data", color = blue), plot([ex, y, y = 0 .. 1], thickness = 3, legend = "Expected Value Empirical Data", color = black)}, title = "Since the expected value for the empirical data is larger than the 0.95 Quantile for the random data  -> the expected value of the empirical data is significant", titlefont = [times, roman, 14]):
display(p);

or like this with cdf's:

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

p := Array(1 .. 1, 1 .. 2):

# Random Data
qq := Quantile(RandomVariable(Normal(0, 1)), .95):
p[1, 1] := display({plot(CDF(RandomVariable(Normal(0, 1)), x), x = -4 .. 4, legend = "CDF Random Data", color = red), plot([qq, y, y = 0 .. 1], thickness = 3, legend = "Quantile 0.95 Random Data", color = black)}):

# Empirical Data
A := Sample(RandomVariable(Normal(2, 1)), 100):
ex := ExpectedValue(A):

p[1, 2] := display({plot(CDF(RandomVariable(EmpiricalDistribution(A)), x), x = -4 .. 4, legend = "CDF Empirical Data", color = blue), plot([ex, y, y = 0 .. 1], thickness = 3, legend = "Expected Value Empirical Data", color = black)}, title = "Since the expected value for the empirical data is larger than the 0.95 Quantile for the random data  -> the expected value of the empirical data is significant", titlefont = [times, roman, 14]):
display(p);

@williamov put raw data in Array A directly!
i) You dont have a value for r hence you cant plot it.
ii) Maybe something like this in regards to plot?!

restart:
with(Statistics):

# Simulated random data with mean =0
R := Sample(RandomVariable(Normal(0, 1)), 100):

# 95% of the area under a normal curve lies within roughly 1.96 standard deviations of the mean
threshold := ExpectedValue(R)+1.96*StandardDeviation(R);

# put your empirical data here
Empiricaldata := Sample(RandomVariable(Normal(2, 1)), 100):
ex := ExpectedValue(Empiricaldata);

# Significant testing
Significant = is(ex > threshold);

plots:-display({plot([ex, y, y = 0 .. .7], color = green, thickness = 3), plot([threshold, y, y = 0 .. .7], color = red, thickness = 3), Histogram(R, color = red), Histogram(Empiricaldata, color = green, bincount = 65)})

@williamov put raw data in Array A directly!
i) You dont have a value for r hence you cant plot it.
ii) Maybe something like this in regards to plot?!

restart:
with(Statistics):

# Simulated random data with mean =0
R := Sample(RandomVariable(Normal(0, 1)), 100):

# 95% of the area under a normal curve lies within roughly 1.96 standard deviations of the mean
threshold := ExpectedValue(R)+1.96*StandardDeviation(R);

# put your empirical data here
Empiricaldata := Sample(RandomVariable(Normal(2, 1)), 100):
ex := ExpectedValue(Empiricaldata);

# Significant testing
Significant = is(ex > threshold);

plots:-display({plot([ex, y, y = 0 .. .7], color = green, thickness = 3), plot([threshold, y, y = 0 .. .7], color = red, thickness = 3), Histogram(R, color = red), Histogram(Empiricaldata, color = green, bincount = 65)})

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