Abrazolica


Home     Archive     Tags     About        RSS
Naive Bayesian Analysis For Traders

Here is a simple example of using Bayesian methods for trading. The goal is to come up with a probability for the hypothesis that the stock market will go up tomorrow. For the sake of shorthand, label the hypothesis \(H\) and its negation, the market will not go up, \(\bar{H}\). To get a probability for \(H\) you need data or evidence that you believe has some bearing on \(H\). Let's label the evidence \(E\). What we want is the probability of \(H\) given the evidence \(E\) or \(P(H|E)\). Bayes' theorem lets us relate this to the probability of \(E\) given \(H\) as follows:

\[P(H|E) = \frac{P(E|H)P(H)}{P(E)}\]

This equation is useful because we can get \(P(E|H)\) from historical data. As an example suppose \(E\) consists of 3 pieces of data: \(A\), \(B\), and \(C\). \(A\) is whether treasuries went down in overnight trading before the market opens. \(B\) is whether the EUR/USD went up overnight and \(C\) is whether the stock market went up the previous day. So we have

\[P(E|H)=P(A,B,C|H)\]

\(A\), \(B\), and \(C\) are almost certainly not independent events but we can take the naive approach and assume they are. This simplifies things by turning the probability into a product:

\[P(A,B,C|H)=P(A|H)P(B|H)P(C|H)\]

You can get an estimate for these probabilities by looking at historical data. To estimate \(P(A|H)\) for example we could look at the previous 200 trading days, counting the number of times treasuries went down overnight and the stock market went up the next day. Divide this by the total number of times stocks went up and you have an estimate for \(P(A|H)\). Exactly how you estimate these probabilities is not that important as long as you do it consistently. In other words don't use the last 200 days to estimate \(P(A|H)\) and the last 20 days to estimate \(P(B|H)\). The formula for \(P(H|E)\) is then

\[P(H|E) = \frac{P(A|H)P(B|H)P(C|H)P(H)}{P(E)}\]

The only thing missing is \(P(E)\). It turns out you don't have to calculate this directly. You can use the fact that

\[P(H|E)+P(\bar{H}|E)=1\]

to get \(P(E)\). \(P(\bar{H}|E)\) is given by

\[P(\bar{H}|E) = \frac{P(A|\bar{H})P(B|\bar{H})P(C|\bar{H})P(\bar{H})}{P(E)}\]

which means that \(P(E)\) must equal

\[P(E)=P(A|H)P(B|H)P(C|H)P(H)+P(A|\bar{H})P(B|\bar{H})P(C|\bar{H})P(\bar{H})\]

Alternatively if all you really want to know is if \(P(H|E) \gt P(\bar{H}|E)\) then you can just check if

\[P(A|H)P(B|H)P(C|H)P(H) \gt P(A|\bar{H})P(B|\bar{H})P(C|\bar{H})P(\bar{H})\]

This method can be extended to any number of pieces of evidence.

For more examples of using probabilities for developing trading strategies see our book Simple Trading Strategies That Work.


© 2010-2012 Stefan Hollos and Richard Hollos

blog comments powered by Disqus