11-12-2018, 04:30 PM
Probability is the logic of randomness and uncertainty. If you are interested in algorithmic trading or want to become a professional quant, you must master probability theory. I find probability theory very fascinating. Probability theory started its journey many centuries back when Gerolamo Cardano wrote the book: The Book On The Game Of Chance. He was trying to calculate the probability of throwing a dice which had become very important for the professional gamblers in those days. You can read the history of probability theory online just Google it. First we discuss probability theory and then we discuss statistics.
Let start with sampling. I hope you are familiar with R language. R is a very powerful language specifically developed for statistical data analysis. If you are not familiar with R, you can refer the thread: Introduction to R in the Algorithmic Trading with R forum where I have introduced the basic R commands for those who are very new and don't know R.
Sampling and Simulation
The heart of probabilistic analysis is sampling and simulation. Most of the time we would want to draw samples from a distribution. R can help a lot in drawing samples from all sorts of probability distributions.
> sample(10,5)
[1] 8 2 10 6 4
> sample(2:8,12, replace=TRUE)
[1] 3 6 8 3 8 7 8 5 2 3 4 8
In R we use sample() command to sample randomly from a set of numbers with equal probability also known as discrete uniform probability. In the first sample command, we told R to sample randomly with equal probability betwen numbers 1 and 10 and sample 5 times without replacement. In the second sample command, we told R that we want sampling with replacement by using replace=TRUE numbers between 2 and 8 and we want 12 samples. We can also sample from the English alphabet letters:
> sample(letters, 8)
[1] "g" "r" "m" "k" "p" "y" "q" "x"
> sample(1:5,12, replace=TRUE, prob=c(0.2,0.1,0.3,0.2,0.2))
[1] 3 2 3 1 2 2 5 2 5 1 5 1
In the above sample command, we allowed the sampling of numbers 1,2,3,4,5 with unequal probabilities. Many books on probability discuss birthday matching problems. Suppose there are 23 people in a room what is the probability of 2 people having the same birthday. R has build in functions for these types of birthday problems:
> pbirthday(23)
[1] 0.5072972
As you can see 23 people have almost 50% probability of having 2 people amongst them with matching birthdays. On your birthday party, if you have invited a lot of people something like 43 friends of yours, there is almost 90% chance that two of them will have matching birthdays:
> pbirthday(43)
[1] 0.9239229
Let start with sampling. I hope you are familiar with R language. R is a very powerful language specifically developed for statistical data analysis. If you are not familiar with R, you can refer the thread: Introduction to R in the Algorithmic Trading with R forum where I have introduced the basic R commands for those who are very new and don't know R.
Sampling and Simulation
The heart of probabilistic analysis is sampling and simulation. Most of the time we would want to draw samples from a distribution. R can help a lot in drawing samples from all sorts of probability distributions.
> sample(10,5)
[1] 8 2 10 6 4
> sample(2:8,12, replace=TRUE)
[1] 3 6 8 3 8 7 8 5 2 3 4 8
In R we use sample() command to sample randomly from a set of numbers with equal probability also known as discrete uniform probability. In the first sample command, we told R to sample randomly with equal probability betwen numbers 1 and 10 and sample 5 times without replacement. In the second sample command, we told R that we want sampling with replacement by using replace=TRUE numbers between 2 and 8 and we want 12 samples. We can also sample from the English alphabet letters:
> sample(letters, 8)
[1] "g" "r" "m" "k" "p" "y" "q" "x"
> sample(1:5,12, replace=TRUE, prob=c(0.2,0.1,0.3,0.2,0.2))
[1] 3 2 3 1 2 2 5 2 5 1 5 1
In the above sample command, we allowed the sampling of numbers 1,2,3,4,5 with unequal probabilities. Many books on probability discuss birthday matching problems. Suppose there are 23 people in a room what is the probability of 2 people having the same birthday. R has build in functions for these types of birthday problems:
> pbirthday(23)
[1] 0.5072972
As you can see 23 people have almost 50% probability of having 2 people amongst them with matching birthdays. On your birthday party, if you have invited a lot of people something like 43 friends of yours, there is almost 90% chance that two of them will have matching birthdays:
> pbirthday(43)
[1] 0.9239229
Subscribe My YouTube Channel:
https://www.youtube.com/channel/UCUE7VPo...F_BCoxFXIw
Join Our Million Dollar Trading Challenge:
https://www.doubledoji.com/million-dolla...challenge/