AppendTo[$Path, "/Users/andrzej/Documents/Work/Finance/"];

<< ItosLemma`

SetOptions[Integrate, 
        GenerateConditions -> False];

SetOptions[ItoD, 
        SuppressTime -> False];

{TimeSymbol, TimeIncrement, BrownianIncrement, 
          CorrelationSymbol} = {t, dt, dW, ρ};

Format[ItoIntegral[f_, {s_, a_, b_}]] := 
          HoldForm[(∫_a^b) f \[DifferentialD](Subscript[W, 1])[s]];

dB = ItoMake[B[t], 0, 1];
ItoIntegral[f_, {s_, a_, b_}] /; 
            b < a := -ItoIntegral[f, {s, b, a}]; 
ItoIntegral[
                f_, {s_, a__, c_, b__}] := 
ItoIntegral[
                  f, {s, a, c}] + ItoIntegral[f, {s, c, b}];
ItoIntegral[f_, {s_, a_, a_}] = 0; 
ItoIntegral[x_ + y_, l_List] := 
              ItoIntegral[x, l] + ItoIntegral[y, l];
B[0] = 0; 
ItoIntegral[
                  f_, {s_, a_, b_}] /; (FreeQ[f, s] && FreeQ[f, W] && 
                    FreeQ[f, B]) := f*(B[b] - B[a]);
ItoIntegral[
                h_*f_, {s_, a_, b_}] /; (FreeQ[h, s] && FreeQ[h, W] && 
                  FreeQ[h, B]) := h*ItoIntegral[f, {s, a, b}];
IntegralForm[expr_] := 
            Unique[c] + 
              Integrate[ Coefficient[expr, dt] /. t -> s, {s, 0, t}] + 
              ItoIntegral[
                Coefficient[expr, (Subscript[dW, 1])] /. t -> s, {s, 0, t}];
ItoGather[expr_] := 
            Simplify[Coefficient[expr, dt]]*dt  + 
              Simplify[Coefficient[expr, (Subscript[dW, 1])]]*(Subscript[dW, 1]);

Expect[x_ + y_] := Expect[x] + Expect[y];
Expect[α_?DeterministicQ*f_] := α Expect[f];
Expect[f_?DeterministicQ] := f;
DeterministicQ[x_?NumericQ] := True;
DeterministicQ[B[t_]] = False;
DeterministicQ[W] = False;
DeterministicQ[expr_?(Not[AtomQ[#]] && FreeQ[#, B] &)] := 
        Apply[And, Map[DeterministicQ, Level[expr, {-1}]]]
Expect[ItoIntegral[__]] = 0;
Expect[
            HoldForm[Integrate[_, {Subscript[W, 1][s], a, b}]]] = 0;
Expect[ItoIntegral[f_, {s_, a_, b_}]^2] := 
          Expect[Integrate[(f^2), {s, a, b}]];
Expect[
            HoldForm[Integrate[f_, {Subscript[W, 1][s_], a_, b_}]]^2] := 
          Expect[Integrate[(f^2), {s, a, b}]];
Expect[Integrate[f_, {s_, a_, b_}]] := 
          Integrate[Expect[f], {s, a, b}];
Expect[(Subscript[W, 1])] = 0;
Expect[B[t_]] = 0;
Expect[B[t_]^2] := t;
Expectation[p_] := Expect[Expand[p]];
MakeDeterministic[x__] := 
            Scan[(DeterministicQ[#] = True) &, {x}];