Clear[snormal1, snormal2, snormal3, snormal4]snormal1[x_] := 
      Integrate[Exp[-z^2/2]/Sqrt[2*Pi], {z, -Infinity, x}] // Nsnormal2[x_] := 
      NIntegrate[Exp[-z^2/2]/Sqrt[2*Pi], {z, -Infinity, x}] // Nsnormal3[x_] := Erf[x/Sqrt[2.]]/2 + 0.5 Needs["Statistics`Master`"]\(ndist = NormalDistribution[0, 1]; 

    snormal4[x_] := CDF[ndist, x] // N\)

snormal1[1]snormal2[1]snormal3[1]snormal4[1]

Timing[Table[snormal1[i/100], {i, 100}]; ][[1]]Timing[Table[snormal2[i/100], {i, 100}]; ][[1]]Timing[Table[snormal3[i/100], {i, 100}]; ][[1]]Timing[Table[snormal4[i/100], {i, 100}]; ][[1]]

Clear[snormal, d1, d2, bsCall, bsPut]\(snormal = snormal3; 

    d1[s_, \ x_, \ sigma_, \ T_, \ Rf_] := 
      \((Log[s/x] + \((Rf + sigma^2/2)\)*T)\)/\((sigma*Sqrt[T])\)\)d2[s_,  x_,  sigma_,  T_,  Rf_] := 
      d1[s,  x,  sigma,  T,  Rf] - sigma*Sqrt[T]\(		bsCall[s_, \ x_, \ sigma_, \ T_, \ Rf_] := 
      \(bsCall[s, x, sigma, T, Rf] = 
        s*snormal[d1[s, x, sigma, T, Rf]] - 
          x*Exp[\(-Rf\)*T]*snormal[d2[s, x, sigma, T, Rf]]\)\)\(		bsPut[s_, x_, sigma_, T_, Rf_] := 
      bsCall[s, x, sigma, T, Rf] + x*Exp[\(-Rf\)*T] - s\)

bsCall[50, 45, Sqrt[0.2], 0.25, 0.06]bsPut[45, 45, 0.3, 1, 0.08]

\(Plot[bsCall[s, 50, 0.2, 0.5, 0.05], {s, 0.01, 70}, 
	
      PlotRange -> All, AxesLabel -> {"stock price", "call price"}]
      \)

Clear[EuropeanOption, EuropeanCall, EuropeanPut]EuropeanOption[s_, sigma_, T_,  r_, exercise_Function, n_]:=
	Module[\({u = N[\ Exp[\ Sqrt[T/n]\ *sigma]\ ], 
            d = N[\ Exp[\ \(-\ Sqrt[T/n]\)*\ sigma]\ ], 
			
            R = N[\ Exp[\ r*\ T/n]\ ]}\),
	p = (R - d)/(R*(u - d));	q = (u - R)/(R*(u - d));
				Sum[ exercise[s*u^j*d^(n - j)]*
Binomial[n, j]*p^j*q^(n - j), {j, 0, n}]
		]\(EuropeanCall[\ s_, \ x_, \ sigma_, \ T_, \ r_, \ n_\ ] := 
	
      \(EuropeanCall[\ s, \ x, \ sigma, \ T, \ r, \ n\ ] = 
	
        EuropeanOption[\ s, \ sigma, \ T, \ r, \ Max[# - x, 0]&, \ n]\); 


    EuropeanPut[\ s_, \ x_, \ sigma_, \ T_, \ r_, \ n_\ ] := 
	
      \(EuropeanPut[\ s, \ x, \ sigma, \ T, \ r, \ n\ ] = 
	
        EuropeanOption[\ s, \ sigma, \ T, \ r, \ Max[x - #, 0]&, \ n]\); 

    EuropeanCall[50, 50, 0.4, 1, 0.10, 50]\)EuropeanPut[50, 50, 0.4, 1, 0.10, 50]

Clear[AmericanOption, AmericanCall, AmericanPut]
AmericanOption[s_, sigma_, T_,  r_, exercise_Function, n_]:=
	Module[\({u = N[\ Exp[\ Sqrt[T/n]\ *sigma]\ ], 
                d = N[\ Exp[\ \(-\ Sqrt[T/n]\)*\ sigma]\ ], 
			
                R = N[\ Exp[\ r*\ T/n]\ ], p, q, OpRecurse}\),
	p = (R - d)/(R*(u - d));	q = (u - R)/(R*(u - d));
	\(OpRecurse[node_, \ level_] := 
                    \(OpRecurse[node, \ level] = 
		
                      If[\ level == n, \ 
                        exercise[s*\ d^node*u^\((level - node)\)], 
			
                        Max[{p, q}.{OpRecurse[node, \ \ \ level + 1], 

                              				\ \ \ 
                              OpRecurse[node + 1, \ level + 1]}, 
				
                          exercise[s*d^node*u^\((level - node)\)]
		]]\)\);
	OpRecurse[0, 0]];

\(AmericanCall[\ s_, \ x_, \ sigma_, \ T_, \ r_, \ n_\ ] := 	
          \(AmericanCall[\ s, \ x, \ sigma, \ T, \ r, \ n\ ] = 
	
            AmericanOption[\ s, \ sigma, \ T, \ r, \ Max[# - x, 0]&, \ n]\)\);
\(AmericanPut[\ s_, \ x_, \ sigma_, \ T_, \ r_, \ n_\ ] := 	
          \(AmericanPut[\ s, \ x, \ sigma, \ T, \ r, \ n\ ] = 
	
            AmericanOption[\ s, \ sigma, \ T, \ r, \ Max[x - #, 0]&, \ n]\)\);

\(n = 50; 

AmericanCall[50, 45, 0.4, 1, 0.10, n]\)AmericanPut[50, 45, 0.4, 1, 0.10, n]EuropeanCall[50, 45, 0.4, 1, 0.10, n]EuropeanPut[50, 45, 0.4, 1, 0.10, n]

\(\(
a = 
      Table[{n, 
          AmericanPut[50, 45, 0.4, 1, 0.10, n] - 
            EuropeanPut[50, 45, 0.4, 1, 0.10, n]}, {n, 10, 80, 10}]; 

    ListPlot[a\ , 
	PlotStyle -> PointSize[0.025], 
      Frame -> {True, True, False, False}, 
	
      FrameLabel -> {"n = iterations", difference}, 
		
      PlotLabel -> "Difference Between American and European Put", 
	
      DefaultFont -> {"Helvetica", 9}\ ]; \)\)

\(\(\ \(ListPlot[a\ , 
	PlotStyle -> PointSize[0.025], 

      AxesLabel -> {"n = iterations", ""}, 
		
      PlotLabel -> 
        "        Difference Between American and European Put Values", 

      	DefaultFont -> {"Helvetica", 9}\ ]; \)\)\)

Clear[AsianOption, AmerAvgCall, EurAvgCall, AmerAvgPut, EurAvgPut]mean[q_List] := Apply[ Plus,  q]/Length[q];
\(AsianOption[s_, \ n_, \ sigma_, \ T_, \ r_, 
	
            exerciseAtT_Function, \ earlyExercise_Function] := 
	
          Module[{u = N[\ Exp[\ Sqrt[T/n]\ *sigma]\ ], 
              d = N[\ Exp[\ \(-\ Sqrt[T/n]\)*\ sigma]\ ], 
			
              R = N[\ Exp[\ r*\ T/n]\ ], p, q, OpRecurse}, 
	
            p = \((R - d)\)/\((R*\((u - d)\))\); 	
            q = \((u - R)\)/\((R*\((u - d)\))\); 
	
            Op[prices_List, \ level_] := \ 
              If[\ level == n, \ exerciseAtT[prices], 
		
                Max[{Op[Append[\ prices, \ u\ Last[prices]], \ level + 1], 

                      		\ \ \ \ \ 
                      Op[Append[\ prices, \ d\ Last[prices]], \ level + 1]}.{
                      p, q}, 
		earlyExercise[prices]]]; 
	Op[{s}, \ 0]]
            \);

\(AmerAvgCall[s_, n_, sigma_, T_, r_] := 
          AsianOption[s, \ n, \ sigma, \ T, \ r, 
		
            Max[0, \ mean[#] - Last[#]]&, 
		Max[0, \ mean[#] - Last[#]]&]
            \);
\(EurAvgCall[s_, n_, sigma_, T_, r_] := 
	
          AsianOption[s, \ n, \ sigma, \ T, \ r, 
            Max[0, \ mean[#] - Last[#]]&, \ 0&]\);

AmerAvgCall[50,  10,  0.4,  5/12,  0.1]EurAvgCall[50,  10,  0.4,  5/12,  0.1]

Clear[AsianOption, AmerAvgCall, EurAvgCall, mean]mean[x_List] := Apply[Plus, x]/Length[x] // N
\(AsianOption[s_, \ \ sigma_, \ T_, r_, 	exerciseAtT_Function, \ 
              earlyExercise_Function, n_] := 
	
            Module[{u = N[\ Exp[\ Sqrt[T/n]\ *sigma]\ ], 
                d = N[\ Exp[\ \(-\ Sqrt[T/n]\)*\ sigma]\ ], 
		
                R = N[\ Exp[\ r*\ T/n]\ ], p, q, \ OpRecurse}, 

              p = \((R - d)\)/\((R*\((u - d)\))\); 	
              q = \((u - R)\)/\((R*\((u - d)\))\); 
	
              OpRecurse[prices_List, \ level_] := \ 
                If[\ level == n, \ exerciseAtT[prices], 
		
                  Max[{OpRecurse[Append[\ prices, \ u\ Last[prices]], \ 
                          level + 1], 
		\ \ \ \ \ 
                        OpRecurse[Append[\ prices, \ d\ Last[prices]], \ 
                          level + 1]}.{p, q}, 
		earlyExercise[prices]]]; 
              
	OpRecurse[{s}, \ 0]
]\);

\(AmerAvgCall[s_, sigma_, T_, r_, n_] := 
          \(AmerAvgCall[s, sigma, T, r, n] = 
	
            AsianOption[s, sigma, \ T, r, Max[0, \ mean[#] - Last[#]]&, 
              Max[0, \ mean[#] - Last[#]]&, n]\)\);
\(EurAvgCall[s_, sigma_, T_, r_, n_] := 
          \(EurAvgCall[s, sigma, T, r, n] = 
	
            AsianOption[s, sigma, \ T, \ r, Max[0, \ mean[#] - Last[#]]&, \ 
              0&, n]\)\);

\(AmerAvgPut[s_, sigma_, T_, r_, n_] := 
          \(AmerAvgPut[s, sigma, T, r, n] = 
	
            AsianOption[s, sigma, \ T, r, Max[0, \ Last[#] - mean[#]]&, 
              Max[0, \ Last[#] - mean[#]]&, n]\)\);
\(EurAvgPut[s_, sigma_, T_, r_, n_] := 
          \(EurAvgPut[s, sigma, T, r, n] = 
	
            AsianOption[s, \ sigma, \ T, \ r, Max[0, \ Last[#] - mean[#]]&, \ 
              0&, n]\)\);

\(s = 100; sigma = 0.35; T = 0.5; r = 0.08; n = 10; 

    AmerAvgCall[s, sigma, T, r, n]\)EurAvgCall[s, sigma, T, r, n]AmerAvgPut[s, sigma, T, r, n]EurAvgPut[s, sigma, T, r, n]

\(\(Clear[s, sigma, T, r, n]; 
s = 100; sigma = 0.35; r = 0.08; n = 5; 

    Plot[AmerAvgCall[s, sigma, T, r, n] - EurAvgCall[s, sigma, T, r, n], {T, 
        0, 1}, 
		Frame -> {True, True, False, False}, 
		
      PlotLabel -> "Difference between
 AmerAvgCall  and EurAvgCall", 

      		FrameLabel -> {"T=time to maturity", ""}, 
	
      DefaultFont -> {"Helvetica", 10}]
\)\)