Forum Discussion
calof1
Jul 02, 2019Iron Contributor
Help to run multiple simulations in one cell - Monte Carlo
Hi Everyone, I am looking to run simulations in excel and find the min, max and median of the results. The formula used in each cell to run the simulation is =$B$4*(1+NORMINV(RAND(),$B$3,$B$2))....
maxhillawac
Feb 27, 2023Copper Contributor
calof1 I appreciate I'm very late to the party but i happened upon your problem while learning about Lambda and found it such a a neat solution. by making a recursive LAMBDA function to simulate each scenario, and MAKEARRAY to compile a set of scenarios, it was simple enough to get the entire simulation into an array. i then used LET to make that array sticky while computing the stats on it then a further MAKEARRAY just to spill the results onto the screen.
=LAMBDA(seed,sd,nominal,years,iter,
LET(iter,iter+1,
seed, seed*(1+NORMINV(RAND(),nominal,sd)),
IF(iter=years,seed,simulatenorminv(seed,sd,nominal,years,iter)
)
)
)
=LET(
sims,
MAKEARRAY(P6,1,
LAMBDA(row,column,
simulatenorminv(P4,P2,P3,P5,0)
)
),
MAKEARRAY(5,1,
LAMBDA(row,column,
SWITCH(row,
1,AVERAGE(sims),
2,MEDIAN(sims),
3,STDEV(sims),
4,MIN(sims),
5,MAX(sims)
)
)
)
)