Monte Carlo Simulation
Risk analysis is part of every decision we make. Monte Carlo simulation is a computerized mathematical technique that allows people to account for risk in quantitative analysis and decision making. The technique is used by professionals in such widely disparate fields as finance, energy and manufacturing. Monte Carlo simulation equips the decision-maker with a range of possible outcomes and the probabilities. SInce its introduction in World War 2, Monte Carlo simulation has been used to model a variety of physical and conceptual systems.
I cannot post all of my code here(its over 200 lines and in multiple parts since it is distributed) The following is the code to demonstrate one of the investment strategies I have used.
def investment(capital,years,per1,per2,per3,per4,per5): yearsX = [] capitalY = [] yearsX.append(0) capitalY.append(capital) for i in range(0,years): r1 = random_generator1() r2 = random_generator2() r3 = random_generator3() r4 = random_generator4() r5 = random_generator5() cap1 = (float(per1/100.00))*capital cap2 = (float(per2/100.00))*capital cap3 = (float(per3/100.00))*capital cap4 = (float(per4/100.00))*capital cap5 = (float(per5/100.00))*capital profit1 = (float(r1/100.00))*cap1 #print "Profit 1 =", profit1,"." profit2 = (float(r2/100.00))*cap2 #print "Profit 2 =", profit2,"." profit3 = (float(r3/100.00))*cap3 #print "Profit 3 =", profit3,"." profit4 = (float(r4/100.00))*cap4 #print "Profit 4 =", profit4,"." profit5 = (float(r5/100.00))*cap5 #print "Profit 5 =", profit5,"." finalcap = capital + profit1 + profit2 + profit3 + profit4 + profit5 #print "Yearly returns = ", finalcap , "." capital = finalcap yearsX.append(i + 1) capitalY.append(finalcap) returns1.append(finalcap) plt.figure(1) plt.plot(yearsX,capitalY)
My (somewhat) complete analysis can be found here.