# Method error in function

**URL:** <https://discourse.julialang.org/t/method-error-in-function/91831>\
**Category:** New to Julia\
**Created:** [December 19, 2022, 6:16am UTC](https://discourse.julialang.org/t/method-error-in-function/91831 "2022-12-19T06:16:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![hamza\_malik](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hamza_malik/32/45188_2.png) [@hamza\_malik](https://discourse.julialang.org/u/hamza_malik)\
**Post date:** [December 19, 2022, 6:16am UTC](https://discourse.julialang.org/t/method-error-in-function/91831/1 "2022-12-19T06:16:49Z")

</div>

I am running the following code in Julia.

code: function lsmc\_am\_put(S, K, r, σ, t, N, P)  
Δt = t / N  
R = exp(r \* Δt)  
T = typeof(S \* exp(-σ^2 \* Δt / 2 + σ \* √Δt \* 0.1) / R)  
X = Array{T}(undef, N+1, P)

```
              for p = 1:P
                  X[1, p] = x = S
                  for n = 1:N
                      x *= R * exp(-σ^2 * Δt / 2 + σ * √Δt * randn())
                      X[n+1, p] = x
                  end
              end

              V = [max(K - x, 0) / R for x in X[N+1, :]]

              for n = N-1:-1:1
                  I = V .!= 0
                  A = [x^d for d = 0:3, x in X[n+1, :]]
                  β = A[:, I]' \ V[I]
                  cV = A' * β
                  for p = 1:P
                      ev = max(K - X[n+1, p], 0)
                      if I[p] && cV[p] < ev
                          V[p] = ev / R
                      else
                          V[p] /= R
                      end
                  end
              end

              return max(mean(V), K - S)
          end

```

after this, I import ForwardDiff: Dual and then run

lsmc\_am\_put(Dual(100,1,0),90,0.5,Dual(0.3,0.1),180/365,1000,10000) but I get the error

error: MethodError: no method matching \_mul\_partials(::ForwardDiff.Partials{2, Int64}, ::ForwardDiff.Partials{1, Float64}, ::Float64, ::Int64)

Closest candidates are:

\_mul\_partials(::ForwardDiff.Partials{0, A}, ::ForwardDiff.Partials{N, B}, ::Any, ::Any) where {N, A, B} at ~/.julia/packages/ForwardDiff/QdStj/src/partials.jl:141

\_mul\_partials(::ForwardDiff.Partials{N, A}, ::ForwardDiff.Partials{0, B}, ::Any, ::Any) where {N, A, B} at ~/.julia/packages/ForwardDiff/QdStj/src/partials.jl:142

\_mul\_partials(::ForwardDiff.Partials{N}, ::ForwardDiff.Partials{N}, ::Any, ::Any) where N at ~/.julia/packages/ForwardDiff/QdStj/src/partials.jl:118

…

Stacktrace:

[1] **dual\_definition\_retval(**#unused#::Val{Nothing}, val::Float64, deriv1::Float64, partial1::ForwardDiff.Partials{2, Int64}, deriv2::Int64, partial2::ForwardDiff.Partials{1, Float64}**)**

@ ForwardDiff ~/.julia/packages/ForwardDiff/QdStj/src/dual.jl:203

[2] \*\*\*\*\*

@ ~/.julia/packages/ForwardDiff/QdStj/src/dual.jl:271 [inlined]

[3] **lsmc\_am\_put(S::Dual{Nothing, Int64, 2}, K::Int64, r::Float64, σ::Dual{Nothing, Float64, 1}, t::Float64, N::Int64, P::Int64)**

@ Main ./REPL[56]:4

[4] top-level scope

@ REPL[68]💯

Can someone please help me with this? I am unable to trace what I am getting wrong and how I should fix it.
