User Defined Function ... Risk of Ruin

SBF12345

Well-known Member
Joined
Jul 26, 2014
Messages
614
Greetings,

I am trying to put together a user defined function called risk of ruin. I would like it to output the probability associated with the occurrence of the 'bankroll' variable falling to <= 0. I am receiving 0 values as output for some reason. My graphing calculator and wikipedia tells me the correct value given the chosen inputs should be about 13%. what is occurring here?

Code:
Public Function Risk_of_Ruin(mu As Integer, st_dev As Integer, bankroll As Integer) As Integer
    
    'Risk of Ruin calculates the probability of reaching a less than or equal to zero value for the bankroll value
    'Inputs should be entered as whole dollar values
    
    Dim r As Integer
    
    r = Application.WorksheetFunction.Sqrt(mu ^ 2 + st_dev ^ 2)
    
    Risk_of_Ruin = (((2 / (1 + mu / r)) - 1) ^ (bankroll / r))


    Risk_of_Ruin = output


End Function
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Three problems immediately apparent:

1. You can't use WorksheetFunction.Sqrt. Use the VBA function Sqr() instead.

2. You don't want to be rounding r (i.e. by declaring as integer)

3. why are you setting Risk_of_Ruin = output (and what is output?) when you have already calculated Risk_of_Ruin in the previous code line?
 
Last edited:
Upvote 0
I made the changes you identified and the function is producing values as expected.

I am still familiarizing myself with user defined functions and good coding practices. Thanks!
 
Upvote 0

Forum statistics

Threads
1,214,929
Messages
6,122,314
Members
449,081
Latest member
tanurai

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top