Click here to Skip to main content
12,406,795 members (60,723 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

7.4K views
5 bookmarked
Posted

The Poisson Distribution in C#

, 14 Aug 2014 CPOL
Rate this:
Please Sign up or sign in to vote.
Poisson distribution in C#

Imagine you are playing poker, you’re making use of the Kelly Criterion to calculate the optimal limit of your betting. You’re also using something to evaluate what your chances of winning are. But being poker, there are several rounds of betting so how much of your Kelly Limit should you bet per round?

Should you bet everything all at once and hope to knock other players out or should you bet slowly to draw other players in? How aggressive should your betting style be?

We need a function that accumulates to 1 but also varies its peak as a variable (let’s call it k) representing the number of betting rounds increases.

One function that matches these requirement is the Poisson distribution.

So here’s the code for that:

public class PoissonEvaluator
{
decimal lambda;

public PoissonEvaluator(decimal lambda = 1.0M)
{
this.lambda = lambda;
}

public decimal ProbabilityMassFunction(int k)
{
//(l^k / k! ) * e^-l
//l = lamda
int kFactorial = Factorial(k);
double numerator = Math.Pow(Math.E, -(double)lambda) * Math.Pow((double)lambda, (double)k);

decimal p = (decimal)numerator / kFactorial;
return p;
}

public decimal CummulitiveDistributionFunction(int k)
{
double e = Math.Pow(Math.E, (double)-lambda);
int i = 0;
double sum=0.0;
while (i <= k)
{
double n = Math.Pow((double)lambda, i) / Factorial(i);
sum += n;
i++;
}
decimal cdf = (decimal)e * (decimal)sum;
return cdf;
}

private int Factorial(int k)
{
int count = k;
int factorial = 1;
while (count >= 1)
{
factorial = factorial * count;
count&ndash;;
}
return factorial;
}
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

CatchExAs
Technical Lead Alpha Integralis Limited
United Kingdom United Kingdom
CatchExAs aka Nick Wilton runs Alpha Integralis, a software development consultancy to companies in the City of London.

Main interests include exploring Algo-Trading, Quant Development and Physics using C# and Java.

www.nickwilton.info/Blog

You may also be interested in...

Comments and Discussions

 
Questioncount&ndash;; Pin
Mauricio Ruiz H5-Aug-15 11:52
memberMauricio Ruiz H5-Aug-15 11:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.160730.1 | Last Updated 14 Aug 2014
Article Copyright 2014 by CatchExAs
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid