Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5

Monte Carlo Simulation For Traders
#1

Monte Carlo simulation is very important when it comes to testing a trading strategy. In this thread I will discuss Monte Carlo simulation with financial applications that traders can use in their trading strategies. Before we start discussing Monte Carlo simulation, we need to have some basic understanding of stochastic calculus. Most of the traders don't have any knowledge of stochastic calculus. So I will start from the very basics in this thread and take you by hand step by step. So let's start first with Probability theory.

Probability Spaces

As a trader you should have some basic understanding of probability theory. Probability Spaces is an important concept to understand. Discussion on probability space starts with a sample space. Sample space is the set of all possible outcomes of an experiment. When trading, our sample space will be set of all possible prices of a currency pair or a stock. Sample space is denoted by Ω. Sample point is the most basic element in the sample space. When defining probability spaces, the concept of sigma algebra is used. We will not use this concept here and try to keep the things as much simple as possible.

Any subset of the sample space is called an Event. Events are denoted by A, B, C etc. An empty set is always a subset of the sample space and is usually denoted by ∅. Sample points are also known as elementary events and denoted by {a} where a is any elementary event. Complement of an event A is denoted by A'. Intersection of two events A and B is denoted by AnB or AB. AnB is the set of elements common to A and B both. Union of two events A and B is denoted by AuB. AuB is the set of elements that belong to A or B.

Probability Measure
We have a sample space and events on that sample space. These events are subsets of the sample space. A Probability Measure is a function also called a mapping that maps each event onto the unit interval [0,1] on the real line. Symbolically we show a probability measure as P: Ω-->[0,1]. What this means is that in simple terms P takes every subset of S and assigns it a value between 0 and 1. Now P cannot be any function. P needs to satisfy the following three conditions before we can call it a probability measure on sample space Ω:

1) P(Ω)=1 what this means is that the probability measure assigned to the sample space is 1. Sample space is always a sure event meaning whatever happens happens within the sample space Ω.
2) For any event A: 0 <P(A)<1 meaning that probability of an event is always between 0 and 1.
3) For any set of events {A1, A2, A3, A4,...} that are mutually disjoint meaning AinAj=∅ we have P(UAi)=∑P(Ai). This means that probability measure is additive for mutually disjoint events that have nothing in common with each other.

For any two events A and B that are not disjoint we have P(AuB)=P(A)+P(B)-P(AnB).

Conditional Probability and Independence
Concept of independence and conditional probability is important. Any two events A and B are independent if P(AB)=P(A)P(B). Similarly events A, B, C and D are independent if P(ABCD)=P(A)P(B)P©P(D). Let A and B be two events. Conditional probability of A given B is denoted by P(A|B) and P(A|B)=P(AB)/P(B). If A and B are independent events than P(A|B)=P(A). What this means is that probability of A happening is independent of probability of event B happening or in other words if B happens it does not affect A in any manner whatsoever.

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/
Reply
#2

Calculate PI with Monte Carlo Simulation
Let's do a simple Monte Carlo experiment. We know PI is an irrational number. PI was first discovered when mathematicians tried to measure the circumference of a circle and then calculate its area. In this experiment we measure PI by throwing a needle on a board with parallel lines on it. When the needle lands on a line, we call it a hit. When it lands on space without any line we call is a miss. We calculate the probability of hit. We don't have to do it physically. We will simulated the whole experiment on a computer. Below is the MATLAB code that does the Monte Carlo computer simulation for us:

% we will throw the needle 10,000 times.
>> trials=10000;
% we generate 10000 random variables for the position
>> x=rand(1,trials);
% we also generate 10000 random variable for the angle
>> theta=rand(1,trials);
>> theta=0.5*pi*theta;
>> hits=x<=0.5*sin(theta);
>> sum(hits);
% Estimated value of PI
>> piEst=trials/sum(hits);

>> piEst

piEst = 3.1328

So in 10,000 throws of the needle, the estimate value of PI is 3.1328. Now let's refine our computer simulation. We want to calculate the standard deviation of the sample so that we know how wide the variance is in the calculated value of PI. Below is the MATLAB code that does that:

% we reduce each trial to 1000
>> trials = 1000;
%however we replicate the trails 20,000 times
>> repeat=20000;
% the for loop that does the job
>> for i=1:repeat
       x=rand(1,trials);
       theta=0.5*pi*rand(1,trials);
       hits= x<=0.5*sin(theta);
       y(i)=sum(hits)/trials;
end
>> hist(y)
>> recipEst=sum(y)/repeat

reciprocalEst =

    0.3183

>> vVec=(y-reciprocalEst).*(y-reciprocalEst);
>> v=sum(vVec)/(repeat-1);
>> stddev=sqrt(v)

stddeviation =

    0.0148

>> piEst=1/reciprocalEst

piEst =

    3.1413

So this time the estimated value of PI is 3.1413 with the standard deviation of 0.0148. So you can see we can do 20,000 repetitions of a random experiment in a few seconds on our computer. This is something powerful that can help us simulate random experiments on our computers.

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/
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)