Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
hic
Former Employee
Former Employee

In some situations in Business Intelligence you need to make simulations, sometimes referred to as "Monte Carlo methods". These are algorithms that use repeated random number sampling to obtain approximate numerical results. In other words – using a random number as input many times, the methods calculate probabilities just like actually playing and logging your results in a real casino situation: hence the name.

These methods are used mainly to model phenomena with significant uncertainty in inputs, e.g. the calculation of risks, the prices of stock options, etc.

QlikView is very well suited for Monte Carlo simulations.

The basic idea is to generate data in the QlikView script using the random number generator Rand() in combination with a Load … Autogenerate, which generates a number of records without using an explicit input table.

To describe your simulation model properly, you need to do some programming in the QlikView script. Sometimes a lot. However, this is straightforward if you are used to writing formulae and programming code, e.g. Visual Basic scripts.

The Rand() function creates a uniformly distributed random number in the interval [0,1], which probably isn’t good enough for your needs: You most likely need to generate numbers that are distributed according to some specific probability density function. Luckily, it is in many cases not difficult to convert the result of Rand() to a random number with a different distribution.

The method used for this is called Inverse Transform Sampling: Basically, you take the cumulative probability function of the distribution, invert it, and use the Rand() function as input. See figure below.

Inverse Transform Sampling.png

The most common probability distributions already exist in QlikView as inverse cumulative functions; Normal T, F and Chi-squared. Additional functions can be created with some math knowledge. The following definitions can be used for the most common distributions:

  • Normal distribution: NormInv( Rand(), m, s )
  • Log-Normal distribution: Exp( NormInv( Rand(), m, s ))
  • Student's T-distribution: TInv( Rand(), d )
  • F-distribution: FInv( Rand(), d1, d2 )
  • Chi-squared distribution: ChiInv( Rand(), d )
  • Exponential distribution: -m * Log( Rand() )
  • Cauchy distribution: Tan( Pi() * (Rand()-0.5) )

Finally, an example that shows the principles around Monte Carlo methods: You want to estimate π (pi) using a Monte Carlo method. Then you could generate an arbitrary position x,y where both x and y are between 0 and 1, and calculate the distance to the origin. The script would e.g. be:

Load *,

     Sqrt(x*x + y*y) as r;

Load

     Rand() as x,

     Rand() as y,

     RecNo() as ID

     Autogenerate 1000;

Pi-estimate.png

The ratio between the number of instances that are within one unit of distance from the origin and the total number of instances should be π/4. Hence π can be estimated through 4*Count( If(r<=1, ID)) / Count(ID).

Bottom line: Should you need to make Monte Carlo simulations – don’t hesitate to use QlikView. You will be able to do quite a lot.

HIC

See also the Tech Brief on how to generate data.

25 Comments
Not applicable

Never even thought of using QlikView in this way. Thanks Henric - this could be a real eye opener for me.

0 Likes
2,610 Views
christophebrault
Specialist
Specialist

Thanks, that's a good example.

if i well understood, in this ROI app, we input values in ths script to evaluate scenario.

The Monte Carlo Method is used for the 10 000 inputs and with a random model based on utilization rate, give results ?

0 Likes
2,610 Views
hic
Former Employee
Former Employee

Correct.

0 Likes
2,623 Views
christophebrault
Specialist
Specialist

Ok, I'll think about how to use it now.

0 Likes
2,623 Views
fosuzuki
Partner - Specialist III
Partner - Specialist III

Hi Henric, this ROI Calculator is a fantastic example!! Is it available somewhere for download? Or could you please share it here?

0 Likes
2,623 Views
mir
Former Employee
Former Employee

Regarding the QlikView ROI Calculator, you can learn more about it from this free datasheet posted here:  Resource Library | QlikView.  We are not distributing the app publicly but we can offer any customer/prospect with a custom ROI Calculator workshop.  In an hour or less, the ROI Calculator app can be introduced by the local account team and customized with the client's inputs.  Additionally, you can download a free Monte Carlo QlikView app here:  http://community.qlik.com/message/329612#329612

0 Likes
2,623 Views
Not applicable

Thank you . If i have chance to use i will use it.

0 Likes
2,623 Views
fosuzuki
Partner - Specialist III
Partner - Specialist III

Hi Mike, thanks for your response.

In fact, I'm from a Master Reseller here in Brazil, and since QlikTech doesn't have an office here, we are an official QT sales representative. I was hoping you could share this application with us. It would be very useful in our negotiations with our customers/prospects.

0 Likes
2,623 Views
kouroshkarimi
Creator III
Creator III

Thanks for this Henric, this is exactly the type of blog posts we need more of.

0 Likes
2,576 Views
cotiso_hanganu
Partner - Creator III
Partner - Creator III

Thank you, Henric for this.

Sempre fi,

Cotiso

0 Likes
2,576 Views