Skip to main content

functions - Getting past "infinite expression 1/0 encountered"


The following function


Angel[startingBankroll_, investmentSize_, successProbability_, investmentsToMake_, targetReturnMultiple_, numberOfSimulations_] := 
With[{
simulationData = NestList[If[(RandomReal[] < successProbability) && # >= 0, (targetReturnMultiple) (investmentSize), Max[#-investmentSize, 0]] &,

startingBankroll,
investmentsToMake],
runs = Table[simulationData, {r, numberOfSimulations}],
finalBankrolls = Map[Last, runs],
frequencyOfBust = Count[finalBankrolls, u_ /; u <= 0] / Length[finalBankrolls],
frequencyOfOutsizedReturn = Count[finalBankrolls, u_ /; u >Max[(startingBankroll - (investmentsToMake)(investmentSize)),0]] / Length[finalBankrolls]
},
runs]
Angel[100000, 5000, 0.05, 10, 1000, 10]


yields an "infinite expression 1/0 encountered" error:



enter image description here



How does one get past this?




Comments