Monte Carlo Simulation with R

Stochastic Modeling


A stochastic model is a tool for modeling data where uncertainty is present with the input. When input has certain uncertainty or probability associated with it then output will also have some probability associated with it. Hence stochastic modeling helps in predicting outcome when input does not have a fixed value. The input to model can be either a value from defined range or from a probability distribution. One of performing stochastic modeling is through Monte Carlo algorithms.

Monte Carlo Methods



It is a class of algorithms which uses random number in the numerical calculation. So if we have a input coming from a set of numbers or distribution and we have a numerical formula to be calculated then  Monte Carlo is the answer.
The Monte Carlo simulation is a Monte Carlo Method. This technique is used by professional in wide variety of fields as finance, project management, energy, manufacturing, engineering, research and development. It was first developed by Stanislaw Ulam while working on atom bomb to study nuclear cascades. It was named after the famous Casino de Monte Carlo in Monaco.

Monte carlo simulation helps the decision maker by providing a range of outcome along with their probability. Due to this feature it is helpful in understanding the risk and uncertainty in project management, costing, risk analysis and stock market.

Application of Monte Carlo Simulation

 1. Calculating Integrals: There are certain functions which cannot be integrated due to high dimensionality In those scenerio Monte Carlo methods are of great help.

2.Portfolio assessment: In finance, there are lot of parameters which determine a portfolio value and they all have some uncertainty associated. Hence Monte Carlo methods are best in these scenerios.

Steps of Monte Carlo Simulation

1. Identify a mathematical model of process you want to explore.
2. Define the parameters like mean and standard deviation for each factor of your model
3. Create random data according to those parameters.
4. Simulate and analyze the output of the process.

Example of Monte Carlo Simulation in R

Let us take a simple example of calculating profit for a new company which make some parts. Following are the input needed to calculate the profit.

1)Raw material for part (rc)= It can have three values-80,90,100 and these value follows uniform distribution. Which means all three have equal probability of being found.
2)Labour cost (lc)=It can have five values (43,44,45,46,47) and probability of each one is (.1,.2,.4,.2,.1). It follows normal distribution.
3)Initial cost = 1000000 will be needed to set up the production plant.
4)Cost of part = 250. The cost of part being sold will be 250.
5)No of part manufactured in first year=15000

Profit = (250- (rc+lc))*15000 ) - 1000000

So now we have all the input variables along with their probability distribution and numerical model.
Let us apply Monte Carlo Simulation on this model using R.

############################################
## install the package
install.packages("mc2d")
## load the library
library(mc2d)
## create first input parameter with variable input and its probability
labourcost=mcstoc(rempiricalD, values=c(43,44,45,46,47),prob=c(.1,.2,.4,.2,.1))
## create second input parameter with variable input and its probabilit
partcost=mcstoc(rempiricalD,values=c(80,90,100),prob=c(0.2,0.2,0.2))
## put the final numerical formula in another variable.
profit=((249-(labourcost+partcost)*15000)- 1000000
## generate the model by mc function
MC=mc(labourcost,partcost,profit)
## print summary and plot of model
print(MC)
summary(MC)
plot(MC)
hist(MC)
############################################









3 comments:

  1. Positive site, where did u come up with the information on this posting?I have read a few of the articles on your website now, and I really like your style. Thanks a million and please keep up the effective work. R Programming institutes in Chennai | R Programming Training in Chennai | R Programming Course Fees

    ReplyDelete

  2. Amazing article. Your blog helped me to improve myself in many ways thanks for sharing this kind of wonderful informative blogs in live. I have bookmarked more article from this website. Such a nice blog you are providing ! Kindly Visit Us hadoop training in chennai velachery | hadoop training course fees in chennai | Hadoop Training in Chennai Omr





    ReplyDelete
  3. R programming is the best fit for everything starting from data import and cleaning to statistics and analytics. It is likewise used in creating different trading applications and simulations. Immaterial of what strategy is followed R programming assumes a significant role in a wide range of industries. R is used as the primary programming language by many quantitative finance analysts.
    For More Info: R Programming Training in Gurgaon

    ReplyDelete

Translate

Monte Carlo Simulation with R

Stochastic Modeling A stochastic model is a tool for modeling data where uncertainty is present with the input. When input has cert...