MMA lines from MiER 6.3

Solve[{55*A + 1.06*B == 5, 48.5*A + 1.06*B == 0}, {A, B}]

Solve[{55*p + 47.5*q == 50, p + q == 1/1.06}, {p, q}]

a = Simplify[Solve[{p*up + q*down == 1, p + q == 1/R}, {p, q}]]

\(ClearAll[statePrices]; 

    statePrices[up_, \ down_, \ R_]\  := 
      \(Solve[{p*up\  + \ q*down\  == \ 1, p\  + \ q\  == \ 1/R}, \ {p, \ q}]
          \)[\([1]\)]\)ClearAll[binomialCall]binomialCall[s_, x_, n_]:=
	Sum[p^j*q^(n - j)*Binomial[n, j]*
              Max[s*up^j*down^(n - j) - x, 0], {j, 0, n}]/.
 statePrices[up,  down,  R]\(up\  = \ 1.1; 
down\  = \ 0.97; 
R\  = \ 1.06; \ 
    binomialCall[50, \ 50, \ 2]\)

\(a = Solve[
          
{\((pi*Log[u/d] + Log[d])\)*n == mu, 
	
              n*pi*\((1 - pi)\)*\((Log[u/d])\)^2 == var} /. pi -> 1/2, {u, d}]
          \)

a[[2]] /. {mu -> 0.12, var -> 0.2^2, p -> 0.5,  n -> 100}

pi = 0.5;
mu = 0.12; var = 0.2^2;
n = 100;
aa=ListPlot[
\(Table[{u^j*d^\((n - j)\), 
                      pi^j*\((1 - pi)\)^\((n - j)\)
\ 	*Binomial[n, j]}, {
                      j, 0, n}] /. a[\([2]\)]\),
		PlotJoined -> True,PlotRange -> All];

\(
Clear[q, u, d, pi, mu, sigma, n]\)\(mu\  = \ 0.12; sigma = 0.2; n = 100; 

    b = {pi -> \((1/2*\((1 + mu/sigma*Sqrt[1/n])\))\), 
		
        u -> E^\((sigma*Sqrt[1/n])\), d -> E^\((\(-sigma\)*Sqrt[1/n])\)}\)\(\(bb = 
      ListPlot[
		
        Table[{u^j*d^\((n - j)\), 
              pi^j*\((1 - pi)\)^\((n - j)\)*Binomial[n, j]}, 

            			{j, 0, n}] /. b, 
		PlotRange -> All, 
        PlotStyle -> PointSize[0.02]]; \)\)

Show[aa, bb]

\(up\  = \ 1.1; 
down\  = \ 0.95; 
r\  = \ 0.06; 

    stock\  = 
      Table[50*up^\((j\  - \ 1)\)*down^\((i\  - \ j)\), {i, 1, \ 5}, 
        \ {j, \ 1, \ i}]; 
MatrixForm[stock]\)

solution  = 
      Solve[{p*(1 + r) + q*(1 + r) == 1, up*p + down*q == 1}, {p, q}]

\(n = 4; 
p = solution[\([1, 1, 2]\)]; 
q = solution[\([1, 2, 2]\)]; 

    statePrices = 
      Table[p^\((j - 1)\)*q^\((i - j)\), {i, 1, n + 1}, {j, 1, i}]; 

    MatrixForm[statePrices]\)

\(Clear[payoffCall, payoffPut]; 
payoffCall[s_] := Max[s - X, 0]; 

    payoffPut[s_] := Max[X - s, 0]; \)

\(X = 45; 
statePrices[\([n + 1]\)] . payoffCall/@stock[\([n + 1]\)]\)

\(Clear[up, down, R, P, Q, EuropeanOption, EuropeanCall, EuropeanPut, 
      mean]; 
up[n_, sigma_, T_] := N[Exp[Sqrt[T/n]*sigma]]; 

    down[n_, sigma_, T_] := 1/up[n, sigma, T]; 

    R[n_, Rf_, T_] := N[Exp[Rf*T/n]]; 

    P[up_, down_, r_] := N[\(\((r - down)\)/\((up - down)\)\)/r]; 

    Q[up_, down_, r_] := N[1/r - P[up, down, r]]; 

    mean[m_List] := Plus@@m/Length[m]; \)

EuropeanOption[s_, sigma_, T_,  Rf_, exercise_Function, n_]:=
Module[{u = up[n, sigma, T], d = down[n, sigma, T], r = R[n, Rf, T], 
                 p,  q},
	p = P[u, d, r];
	q = Q[u, d, r];
	Sum[ exercise[s*u^j*d^(n - j)]*
Binomial[n, j]*p^j*q^(n - j), {j, 0, n}]];

\(payoffCall[\ s_, \ X_] := Max[s - X, \ 0]; 

      EuropeanCall[\ X_, \ s_, \ sigma_, \ T_, \ Rf_\ , \ n_, ] := 
        EuropeanOption[\ s, \ sigma, \ T, \ Rf, \ payoffCall, \ n]; \)

\(EuropeanCall[\ s_, \ X_, \ sigma_, \ T_, \ Rf_, \ n_\ ] := 
        EuropeanOption[\ s, \ sigma, \ T, \ Rf, \ Max[# - X, 0]&, \ n]; 

      EuropeanPut[\ s_, \ X_, \ sigma_, \ T_, \ Rf_, \ n_\ ] := 
        EuropeanOption[\ s, \ sigma, \ T, \ Rf, \ Max[X - #, 0]&, \ n]; \)

EuropeanCall[50, 45, 0.4, 1, 0.1, 100]EuropeanPut[50, 45, 0.4, 1, 0.1, 100]

AO = Table[0,  {i,  1,  n + 1},  {j, 1, i}];
AO[[n + 1]] = 
          Table[ payoffCall[stock[[n + 1, j]]],  {j, 1, n + 1}];
AO[[n + 1]] = Map[ payoffCall,  stock[[n + 1]] ];
\(For[\ nn = n, \ nn >= 1, \ \(nn--\), 
	
          For[\ j = 1, \ j <= nn, \ \(j++\), 
		
            AO[\([nn, j]\)] = 
              Max[\ payoffCall[stock[\([nn, j]\)]], 
				
                p*AO[\([nn + 1, \ j + 1]\)]\  + \ q*AO[\([nn + 1, j]\)]]
	]
            
]\);

\(AmericanOption[s_, \ sigma_, \ T_, \ Rf_, \ exercise_Function, \ 
          n_] := 
	
        Module[{u = up[n, \ sigma, \ T], \ d = down[n, \ sigma, \ T], \ 
            r = R[n, \ Rf, \ T], 
	p, \ q, \ OpRecurse}, 
	
          p = P[u, d, r]; 
	q = Q[u, d, r]; 
	
          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_, \ Rf_, \ n_] := 
	
        AmericanOption[s, \ sigma, \ T, \ Rf, \ Max[# - X, 0]&\ , \ n]; 

      AmericanPut[s_, \ X_, \ sigma_, \ T_, \ Rf_, \ n_] := 
	
        AmericanOption[s, \ sigma, \ T, \ Rf, \ Max[X - #, 0]&\ , n]; \)

AmericanCall[50, 45, 0.4, 0.5, 0.1, 30]AmericanPut[50, 45, 0.4, 0.5, 0.1, 30]