Sunteți pe pagina 1din 22

Students Name

Ang Xue Yin (5214178)


Shifaly M Saju (5281416)
Sowmiya Mahalakshmi (4872460)
V Prathyaksha (5283048)

Course

School of Computer Science & Software Engineering

Study Mode

Full Time

School of Computer Science & Software


Engineering
Group Assignment
STAT131 Understanding Variation and Uncertainty
JANUARY 2016 - MARCH 2016

_____________________________________________________________________
UOW Moderator

: Prof. David Steel (6dsteel@uow.edu.au)

Lecturer

: Mr Aaron Yeo

Weightage

: 30% of Subject

_____________________________________________________________________

Table of Contents
1 Introduction........................................................................................................ 3
2 Variation Over Time............................................................................................ 4
2.1 Introduction.................................................................................................. 4
2.2 OCBC Stock Price.......................................................................................... 4
2.2.1 Running mean smoothing on price.........................................................4
2.2.2 Running median smoothing on price......................................................5
2.3 OCBC Trading Volume...................................................................................8
2.4 Stock Price of OCBC versus DBS...................................................................9
2.5 Trading Volume of OCBC versus DBS..........................................................10
3 Dice Game Strategy Simulation........................................................................11
3.1 1st Strategy (Original)................................................................................. 11
3.2 2st Strategy................................................................................................. 11
3.3 3rd Strategy................................................................................................. 12
3.4 Conclusion.................................................................................................. 13
4 Monty Hall simulation....................................................................................... 14
4.1 Monty Hall simulation.................................................................................14
4.1.1 Introduction.......................................................................................... 14
4.1.2 Winning probability..............................................................................14
4.1.3 VBA program........................................................................................ 14
4.1.4 Results.................................................................................................. 15
4.2 Monty Hall simulation: Modification to 4 doors...........................................15
4.2.1 Introduction.......................................................................................... 15
4.2.2 Winning probability..............................................................................15
4.2.3 VBA program: 4 doors simulation.........................................................16
4.2.4 Results.................................................................................................. 16
4.3 Monty Hall simulation: Modification to 5 doors...........................................16
4.3.1 Introduction.......................................................................................... 16
4.3.2 Probability of winning...........................................................................16
4.3.3 VBA program: 5 doors simulation.........................................................17
4.3.4 Results.................................................................................................. 17
5 Appendix........................................................................................................... 18
Appendix A: VBA Program for Monty Hall simulation of 3 Doors.......................18
Appendix B: VBA Program for Monty Hall simulation of 4 Doors.......................19
Appendix C: VBA Program for Monty Hall simulation of 5 Doors.......................20

1 Introduction
This report consists of main 3 parts, analysing the trend and pattern of a stock
counter, simulation of dice game strategy, and simulation of the probability of
the Monty Hall problem.
In the first part, a simple statistical software tools was developed to analyse
stock prices and volume for Oversea-Chinese Banking Corporation over the
period of 5 years STI (Strait Times Index). We counter analysed the stocks with
The Development Bank of Singapore (DBS) to identify the trend and pattern of
the stocks and performed various smoothing techniques to achieve this result.
In the second part, a Visual Basic for Applications (VBA) program is done to find
the probability of the player winning/losing the game of dice. Every time he
guesses correctly, he wins, else he loses. There is the original version with an
unbiased outcome and 2 alternate versions with biased outcomes.
In the last part, a VBA program was used to simulate the Monty Hall problem.
The probability of the original Monty Hall problem was discussed and simulated,
and also further modified to 4 doors and 5 doors. The probability of the player
winning if the player chooses to change the door was worked out and discussed.

2 Variation Over Time


2.1 Introduction
Oversea-Chinese Banking Corporation Limited (OCBC) stock counter was chosen
from the Singapore Stock Exchange (SGX). 5 years of historical daily stock price
(Adjusted Closing Price) and trading volume from OCBC, from 1 st January 2010 to
31st December 2015, were used to analyse for trends and patterns. Trends and
patterns in the data was analysed after different types of smoothing techniques
were used on the data. The stocks with Development Bank of Singapore (DBS)
was counter analysed with the stocks from OCBC to identify the trends and
patterns and various smoothing techniques was used on the data to achieve this
result. The two smoothing techniques used on the graphs are running mean, and
running median. Visual Basic for Applications (VBA) tools were used in processing
the data for running mean and running median.

2.2 OCBC Stock Price

OCBC Stock Price

Price

4000
3000
2000
1000
0

Time

Figure 1: Graph of OCBC stock price over time

2.2.1 Running mean smoothing on price


Using k-value running mean smoothing technique on the graph for the stock
price, different k-values was used to see what differences it has on the graph.
The values used are 3 point running mean, 31 point running mean, 41 point
running mean, and 81 point running mean.

81 point running mean on OCBC Price

Price

4000
3500
3000
2500
2000
1500
1000
500
0

Time

Figure 2: Graph of 81 point running mean smoothing on OCBC price over time

41 point running mean on OCBC Price

Price

4000
3500
3000
2500
2000
1500
1000
500
0

Time

Figure 3: Graph of 41 point running mean smoothing on OCBC price over time

31 point Running Mean on OCBC Price


4000
3500
3000
2500
2000

Price

1500
1000
500
0

Time

Figure 4: Graph of 31 point running mean smoothing on OCBC price over time
Different k values were used to see what differences it has on the graph. The k
values were used are 3, 31, 41 and 71. After compiling all the plotted graphs for
the different k values, the graph with 41 point running mean gave the smoothest
and accurate pattern. For the graph of 81 point, the graph was very smooth and
all the minor changes were also smoothened out along with the outliers. The
graph for the k value 31 and 3, a general pattern is hard to infer from the graph,
hence these two graphs were not used.

2.2.2 Running median smoothing on price


Using k-value running median smoothing technique, different k-values was used
to see what differences it has on the graph. The k values that were used are 3,
31, 41 and 81.

81 point Running Median on OCBC Price

Price

4000
3500
3000
2500
2000
1500
1000
500
0

Time

Figure 5: Graph of 81 point running median smoothing on OCBC price over time

41 point Running Median on OCBC Price

Price

4000
3500
3000
2500
2000
1500
1000
500
0

Time

Figure 6: Graph of 41 point running median smoothing on OCBC price over time

31 point Running Median on OCBC Price

Price

4000
3500
3000
2500
2000
1500
1000
500
0

Time

Figure 7: Graph of 31 point running median smoothing on price


As seen in Figure 5, it is similar to Figure 2, 81 point running median graph was
very smooth and all the minor changes were also smoothened out along with the
outliers. Figure 6 gave the smoothest and most accurate graph in comparison to
other graph.
2.2.4 Conclusion on Price
The 41 point running median graph, in Figure 6, is used to represent adjusted
closing price for OCBC. Running median graphs are less sensitive to outliers as
compared to running mean thus making it more suitable tool for comparison.

41 point Running Median on OCBC Price

Price

4000
3500
3000
2500
2000
1500
1000
500
0

Time

Figure 8: Overall trend for OCBC price over time


From the year 2010 to the year 2011 there is a positive relationship between the
time and the adj close price, since the increase in the x-axis is accompanied by
the increase in the y-axis. For the year 2011 to 2012, we can notice the steepest
decrease for the given period. There is an increase from the year 2012 to 2013
which continues till the mid of 2013. From this point on the graph is relatively
constant with a few minor increases and decreases. In a nut shell we can notice
that there is no overall increase in the price from the year 2010 to 2015.

2.3 OCBC Trading Volume

OCBC Trading Volume


1000000000
800000000
600000000

Volume

400000000
200000000
0

Time

Figure 9: Graph of OCBC Trading Volume over Time


Two different smoothing techniques were used on the graph of volume over time,
in figure 8. Using k-value running mean smoothing technique, different k-values
was used to see what differences it has on the graph. The k values that were
used are 3, 31, 41 and 81. Using k-value running median smoothing technique,

different k-values was used to see what differences it has on the graph. The k
values that were used are 3, 31, 41 and 81.
The 81 point running mean had the smoother graph.

81 point Running Mean on OCBC Volume


350000000
300000000
250000000
200000000

Volume

150000000
100000000
50000000
0

Time

Figure 10: Graph of 81 point running mean smoothing on OCBC volume over
time
As seen from Figure 7 above, from the end of the year 2012 to first quarter of
2013 there is a drastic increase in the volume which results in the peak point for
the whole period. From there the end of 2013 there is a sharp decrease. After this
point, increase in volume to the first quarter of 2014, which is accompanied by a
decrease till the mid of 2014. After the mid of 2014, there seems to be a general
increase in trend with a lots of fluctuations until the third quarter of 2014.

2.4 Stock Price of OCBC versus DBS


Two different smoothing techniques were used on the data of OCBC and DBS
over time. For running mean smoothing technique, the different values of k used
were 3, 31, 41 and 81. For running median smoothing technique, the different
values of k used were 3, 31, 41 and 81.
The last result of using these smoothing techniques will give about the same
pattern of the graph.

41 point Running Median on Price of OCBC VS DBS

Price

DBS
OCBC
DBS

4000
3500
3000
2500
2000
1500
1000
500
0

Time

Figure 11: Graph of 41 point running median smoothing on price of OCBC vs DBS
The 41-point running median graphs regarding prices for both OCBC and DBS
from the year 2010 to the year 2015 were combined and analysed. There is an
overall increase in prices for both the banks from the 2010 till the end of 2014. In
2015, OCBC has a decrease in prices while for DBS the price remains constant.
There is a period in the graph where the prices for OCBC and DBS is more or less
the same from mid of 2013 to the first half of 2015.
DBS shows a more steady increase in the prices from 2010 to 2015, while OCBS
has many fluctuations. There is an overall increase in DBS while in OCBC the
value remains almost the same over the period of 5 years.

10

2.5 Trading Volume of OCBC versus DBS

Volume of OCBC VS DBS


25000
20000
15000

Volume

10000
5000
0

Time
DBS
OCBC

Figure 12: Graph of Trading Volume of OCBC versus DBS


As seen from Figure 9, from September of 2013 to February of 2013 and October
to December of 2013 the trading volume for both OCBC and DBS shows a
positive relationship. While from December of 2013 to March of 2014 both shows
a negative relationship.
From March of 2013 to March of 2015, OCBC shows a general increase with a lot
of fluctuations while DBS remains almost constant.

11

3 Dice Game Strategy Simulation


3.1 1st Strategy (Original)
In this task, we have simulated dice game strategy to calculate the chances of
winning by the end of the game. The first simulation will show the game with a
starting chips of 10 000. The player plays 10 000 rounds. The strategy adopted
in the simulation is that the bet will start with 1 chip and will double in the next
round if the player loses. However, if the case that the player wins, the bet starts
again with 1 chip. Assuming that the dice are unbiased and the bet (odd or even)
is random, the simulation will stop when the player has 0 chips left or if the
simulation has run for 10,000 times.
When we calculate the changes of winning, the average is about 0.5. Then, to
check to see if adjusting the number of chips or adjusting the number of rounds
will affect this probability, we did the 2 nd simulation with 10 000 rounds and 5000
starting chips. We also did a 3 rd simulation with 5000 rounds and 10 000 starting
chips. Both proved that the probability will always remain the same no matter
the changes in starting chips and number of rounds.

1st simulation (10 000 chips, 10 000


rounds)

2nd simulation (5000 chips, 10 000 rounds)

3rd simulation (10 000 chips, 5000 rounds)

3.2 2st Strategy


With this in mind, we came up with a 2 nd strategy. A strategy where the player
guesses the number on one dice. Notice that the probability of guessing the right
number is 1/6 and probability of guessing the wrong number is 5/6. So the player
would end up guessing the number wrong more often that guessing it correctly. If
he wins, he gains one chip. If he loses, he loses one chip. This is a strategy based
on a starting number of chips as 100 and the total rounds to be 5000. The player
automatically loses if he ends up with 0 chips in any time of the game. In the
picture shown below, the player loses in 232 out of 5000 rounds. This strategy is
biased as the chances of winning for the player is only around 0.2 while the
chances of the casino winning is 0.8.

12

2nd strategy (100 chips, 5000 rounds)

3.3 3rd Strategy


We also came up with a 3rd strategy. The game rules are that the player guesses
the product of 2 numbers, when 2 dice are rolled, is odd or even. When we look
at the multiplication table below,

We notice that the probability of an even outcome is 27/36 while the probability
of an odd outcome is 9/36. Furthermore, guessing even or odd correctly is
considered a winning one round. If he wins one round, he will get back double
the chips. But if he guesses wrongly, he will not get the chips back.
If we simulate it, with a starting chips of 100 and it goes for 10 rounds, it will be
like this,
Round 1:
Players guess: odd
Players bet: 10 chips
Dice product: 6 x 2 = 12
(even)
Result: player lost
Remaining chips: 90
Round 4:
Players guess: even
Players bet: 12 chips
Dice product: 2 x 1 = 2
(even)
Result: player wins
Remaining chips: 136
Round 7:
Players guess: odd
Players bet: 18 chips
Dice product: 5 x 6 = 30
(even)
Result: player lost
Remaining chips: 150
Round 10 (final):
Players guess: odd
Players bet: 9 chips

Round 2:
Players guess: even
Players bet: 15 chips
Dice product: 5 x 4 = 20
(even)
Result: player wins
Remaining chips: 120
Round 5:
Players guess: even
Players bet: 6 chips
Dice product: 4 x 6 = 24
(even)
Result: player wins
Remaining chips: 148
Round 8:
Players guess: even
Players bet: 7 chips
Dice product: 4 x 5 = 20
(even)
Result: player wins
Remaining chips: 164

Round 3:
Players guess: even
Players bet: 8 chips
Dice product: 3 x 3 = 9
(even)
Result: player lost
Remaining chips: 112
Round 6:
Players guess: even
Players bet: 10 chips
Dice product: 6 x 6 = 36
(even)
Result: player wins
Remaining chips: 168
Round 9:
Players guess: even
Players bet: 10 chips
Dice product: 3 x 6 = 18
(even)
Result: player wins
Remaining chips: 184

13

Dice product: 2 x 5 = 10
(even)
Result: player loses
Remaining chips: 174
In this result, we notice that he wins 6/10 times and loses 4/10 times. With just
10 rounds, he was able to go from the initial 100 rounds to a final 174 chips. And
this is assuming the player never bets more than 20 chips. Therefore, it increases
the chances of winning for the player and a huge loss for the casino is every
gambler chooses to play this game.

3.4 Conclusion
The 2nd strategy will result in the probability of the player losing more and the 3 rd
strategy will result in the probability of the player winning more.

14

4 Monty Hall simulation


4.1 Monty Hall simulation
4.1.1 Introduction
The Monty Hall problem originates from a game show. There are three doors,
behind which are two goats and a car. The player is given the choice of choosing
one of three doors, and the goal is to choose the door with a car. After the player
chooses a door, the game host, who knows what is behind the doors, examines,
and opens one of the door with a goat, and then ask if the player wishes to
change to last remaining door.

4.1.2 Winning probability


As there are three doors, two goats, and one car, the probability of choosing a
car in one of the three doors is 1 in 3, or about 33.33%, and the probability of
choosing a goat in one of the three doors is 2 in 3, or about 66.66%. If the player
does not change the door, it does not matter which other doors the host opens,
as the players will not change his choice. Hence, by deciding to not change
doors, the probability of the player picking a car is 33%, and the probability of
the player picking a goat is 67%.
If the player decides to change the door, the outcome of the door chosen will
change. If the player chooses a car on the first try, and then change, the player
will pick a goat. If the player chooses a goat on the first try, and then change, the
player will pick a car. Hence the 33% probability of the player choosing a car
initially, will change to the 33% probability of the player will choosing a goat.
Vice versa, the 67% probability of the player choosing a goat initially, will
become the 67% probability of the player choosing a car. Hence the probability
of picking a goat is 33% and the probability of picking a car is 67% if the player
decides to change doors.
Table 1: Calculated probability of Monty Hall 3 doors
Did not change
Changed

Car
33%
67%

Goat
67%
33%

Therefore, by swapping, the probability of picking a goat is 33% by picking the


car the first time, and the probability of picking a car is 66%, by picking the goat
the first time.
Hence, the probability worked out shows that it is always to the players
advantage to swap, as the chance of picking a car is 67% if the player changes
door, as compared to the chance of picking a car with 33% if the player does not
change door.

4.1.3 VBA program


A VBA program, in Appendix A, to simulate the Monty Hall problem will be run for
10000 times with 3 doors, and assuming that the player always changes doors.
The location of the goats and cars will be random, and the door chosen by the
player will be random. In each simulation, the total number of wins out of the
10000 rounds will be computed and displayed. The purpose of this simulation is

15

to find out if it is always to the players advantage to change the door, and if it
agrees with the calculated probability of choosing a car by changing doors.

4.1.4 Results

The results of the several VBA simulation shows about 6606 wins in 10000
rounds to 6739 wins in 10000 rounds for each simulation, rounded up to around
66-67% chance of winning.
The calculated probability of 67% is within the range of the simulation results,
and as both simulation results and calculated probability shows that if the player
changes door, the probability of the player winning is high, about 66% to 67%.
Therefore, it is always to the players advantage to change the door.

4.2 Monty Hall simulation: Modification to 4 doors


4.2.1 Introduction
As a modification to the simulation, the Monty Hall problem was extended to four
doors. There are four doors, behind which are three goats and one car. Like with
three doors, the player is given the choice of choosing one of the doors, and the
game host, instead of one door, opens two door with goats, and then ask if the
player wishes to change to last remaining door.

4.2.2 Winning probability


As there are four doors, three goats, and one car, the probability of choosing a
car in one of the four doors is 1 in 4, or 25%, and the probability of choosing a
goat in one of the four doors is 3 in 4, or 75%. If the player does not change the
door, the probability of the player picking a car is 25%, and the probability of the
player picking a goat is 75%.
If the player decides to change the door, the outcome of the door chosen will
change. If the player chooses a car on the first try, and then change, the player
will pick a goat, and vice versa. Hence the 25% probability of the player choosing
a car initially, will change to the 25% probability of the player will choosing a
goat. The 70% probability of the player choosing a goat initially, will become the
70% probability of the player choosing a car. Hence the probability of picking a
goat is 25% and the probability of picking a car is 70% if the player decides to
change doors.
Table 2: Calculated probability of Monty Hall 4 doors
Did not change
Changed

Car
25%
75%

Goat
75%
25%
16

Assuming the players always change the door, the probability of picking a goat is
25% by picking the car the first time, and the probability of picking a car is 75%,
by picking the goat the first time. Therefore, the player will win as long as the
player initially chose a door with the goat.
Hence, the probability worked out shows that it is to the players advantage to
swap as the chance of picking a car is 75% if the player changes door, as
compared to the chance of picking a car with 25% if the player does not change
door.

4.2.3 VBA program: 4 doors simulation


In this Monty Hall simulation, the number of doors have been extended to 4
doors and run for 10,000 times, as seen in Appendix B. The location of the goat
and car, and the door chosen by the payer will be random. In each simulation,
the total number of wins out of the 10000 rounds will be computed and
displayed. The purpose of this simulation is to work out the probability of the
player winning if the player chooses to change the door, analyse the percentage
difference between original and modified, and if it agrees with the calculated
probability of choosing a car by changing doors

4.2.4 Results

The results of the several VBA simulation shows about 7450 wins in 10000
rounds to 7599 wins in 10000 rounds for each simulation, rounded up to around
74-76% chance of winning.
The calculated probability of 75% is within the range of the simulation results,
and as both simulation results and calculated probability shows that if the player
changes door, the probability of the player winning is high, about 74% to 76%.
Therefore, it is always to the players advantage to change the door.

4.3 Monty Hall simulation: Modification to 5 doors


4.3.1 Introduction
As a modification to the simulation, the Monty Hall problem was extended to five
doors. There are five doors, behind which are four goats and one car. Like with
three doors, the player is given the choice of choosing one of the doors, and the
game host, instead of one door, opens three door with goats, and then ask if the
player wishes to change to last remaining door.

17

4.3.2 Probability of winning


As there are five doors, four goats, and one car, the probability of choosing a car
in one of the four doors is 1 in 5, or 20%, and the probability of choosing a goat
in one of the four doors is 4 in 5, or 80%. If the player does not change the door,
the probability of the player picking a car is 20%, and the probability of the
player picking a goat is 80%.
If the player decides to change the door, the outcome of the door chosen will
change. If the player chooses a car on the first try, and then change, the player
will pick a goat, and vice versa. Hence the 20% probability of the player choosing
a car initially, will change to the 20% probability of the player will choosing a
goat. The 80% probability of the player choosing a goat initially, will become the
80% probability of the player choosing a car. Hence the probability of picking a
goat is 20% and the probability of picking a car is 80% if the player decides to
change doors.
Table 3: Calculated probability of Monty Hall 5 doors
Car
Goat
Did not change
20%
80%
Changed
80%
20%
Therefore, by swapping, the probability of picking a goat is 20% by picking the
car the first time, and the probability of picking a car is 80%, by picking the goat
the first time.
Hence, the probability worked out shows that it is always to the players
advantage to swap as the chance of picking a car is 80%, as compared to the
chance of picking a car with 20% by not swapping.

4.3.3 VBA program: 5 doors simulation


In this Monty Hall simulation, the number of doors have been extended to 5
doors and run for 10,000 times, as seen in Appendix C. The location of the goat
and car, and the door chosen by the payer will be random. In each simulation,
the total number of wins out of the 10000 rounds will be computed and
displayed. The purpose of this simulation is to work out the probability of the
player winning if the player chooses to change the door, analyse the percentage
difference between original and modified, and if it agrees with the calculated
probability of choosing a car by changing doors.

4.3.4 Results

The results of the several VBA simulation shows about 7951 wins in 10000

18

rounds to about 8069 wins in 10000 rounds for each simulation, rounded up to
around 80-81% chance of winning.
The calculated probability of 80% is within the range of the simulation results,
and as both simulation results and calculated probability shows that if the player
changes door, the probability of the player winning is high, about 80% to 81%.
Therefore, it is always to the players advantage to change the door.

19

5 Appendix
Appendix A: VBA Program for Monty Hall simulation of 3 Doors

20

Appendix B: VBA Program for Monty Hall simulation of 4 Doors

21

Appendix C: VBA Program for Monty Hall simulation of 5 Doors

22

S-ar putea să vă placă și