Using Monte Carlo Simulation to price a European call 
/////////////////////////////////
  --------------------------------------------------------------
  To price a call, we need the following 5 parameters: 
        s: today's stock price
        X: exercise price 
        T: maturity date in years
        r: risk-free rate (compounded continuously)
   sigma : volatility

       payoff (call) =  Max (sT-X,0)
                 where ST is the terminal stock price at time T 
      

bsCallSimulation<-function(s,x,r,T,sigma,n=100){

    sT<-s*exp((r-sigma*sigma/2.0)*T + sigma*rnorm(n)*sqrt(T))
    payoff<-((sT-x) + abs(sT-x))/2
    mean(payoff)*exp(-r*T)

}

 bsCallSimulation(42,40,0.1,0.5,0.2,5000)
  #[1] 4.728094

 bsCall<-function(s,x,T,r,sigma){
     d1 = (log(s/x)+(r+sigma*sigma/2.)*T)/(sigma*sqrt(T))
     d2 = d1-sigma*sqrt(T)
     s*pnorm(d1)-x*exp(-r*T)*pnorm(d2)
  }

 > bsCall(42,40,0.1,0.5,0.2)
   [1] 4.015032

/////////////////////////////////

Simulation for European put
/////////////////////////////////
To price a put, we need the following 5 parameters: 

        s: today's stock price
        X: exercise price 
        T: maturity date in years
        r: risk-free rate (compounded continuously)
   sigma : volatility

 payoff (put) =  Max (x-sT,0)
       where ST is the terminal stock price at time T 
     
bsmPutSimulation<-function(s,x,r,myT,sigma,n=100){
  
  temp1<-(r-sigma*sigma/2.0)*myT
  temp2<-sigma*rnorm(n)*sqrt(myT)
  sT<-s*exp(temp1 + temp2)
  a<-x-sT
  payoff<-(a + abs(a))/2
  mean(payoff)*exp(-r*myT)
}

bsmPutSimulation(42,40,0.1,0.5,0.2,5000)
# [1] 0.7536638

bsmPut<-function(s,x,T,r,sigma){
     d1 = (log(s/x)+(r+sigma*sigma/2.)*T)/(sigma*sqrt(T))
     d2 = d1-sigma*sqrt(T)
     put<-x*exp(-r*T)*pnorm(-d2)-s*pnorm(-d1)
     return(put)
  }

 > bsmPut(42,40,0.1,0.5,0.2)
  0.064209
/////////////////////////////////

Using Monte Carlo Simulation to price Asian options
/////////////////////////////////
  -------------------------------------------------------------- 
 Asian options are type of path dependent options while European and American options 
 are path independent. Here is an example of European call. 

 Assume that terminal stock price is $50 while the exercise price is $45. 
   Since the payoff of a call is Max(sT-X,0), we have Max(50-45,0) = 5
   In other words, our payoff is $5. This payoff has nothing to do with the path. 

  Payoff(Asian options, average price) = Max(s_average - X, 0) 
      where s_average is the average price before maturity (T)

  For many cases, Asian options are more meaningful for hedging. 
    Let's use a simple example. 

  A refinery uses huge amount of crude oil. If the price increase, the refinery would 
    suffer a loss if no hedge. The company could buy a call option. 

  Let's look at the two payoffs:

     Payoff( call)       = Max(sT-X,0)
   
     payoff( Asian call) = Max(s_average -X,0) 

  Since, the company use crude oil every day, they should be more concerned about
    the average daily price they paid instead of the end of year price. 

R program
-----------
  asian_call_ave_price<-function(S,r,T,n_steps,sigma,x,n_trial){
      payoff<-payoff<-rep(0,time=n_trial) # initialization
      for(i in 1:n_trial){
           Saverage<- mean(sT_path_f(S,r,T,n_steps,sigma))
           payoff[i]<-max(Saverage-x,0)
     }
     return(mean(payoff)*exp(-r*T))
  }
> asian_call_ave_price(42,0.1,0.5,1000,0.2,40,100)
[1] 3.247508
/////////////////////////////////