Miletus.jl icon indicating copy to clipboard operation
Miletus.jl copied to clipboard

Update for recent Julia and Package versions

Open alecloudenback opened this issue 3 years ago • 1 comments

Wanted to run on recent Julia version (e.g. Julia 1.7) and got a ton of package downgrades. Started to update for newer dependency versions but have run into the following issues:

First:

Error During Test at /Users/alec/.julia/dev/Miletus/test/montecarlo.jl:31
  Test threw exception
  Expression: isapprox(value(m, c), value(mcm, c), rtol = 0.01)
  TypeError: in CurrencyQuantity, in T, expected T<:Real, got Type{Number}
  Stacktrace:
    [1] promote_type
      @ ~/.julia/dev/Miletus/src/currency.jl:88 [inlined]
    [2] _mean_promote(x::CurrencyQuantity{CurrencyUnit{:USD}, Float64}, y::CurrencyQuantity{CurrencyUnit{:USD}, Float64})
      @ Statistics /Users/sabae/src/julia/usr/share/julia/stdlib/v1.7/Statistics/src/Statistics.jl:166
    [3] mean(f::typeof(identity), itr::Base.Generator{Miletus.ScenarioIterator{MonteCarloModel{CoreModel{CurrencyQuantity{CurrencyUnit{:USD}, Float64}, Miletus.TermStructure.ConstantContinuousYieldCurve{Actual365, Float64}, Miletus.TermStructure.ConstantContinuousYieldCurve{Actual365, Float64}}, StepRange{Date, Day}, CurrencyQuantity{CurrencyUnit{:USD}, Float64}}}, Miletus.var"#5#6"{Miletus.When{Miletus.LiftObs{typeof(==), Tuple{Miletus.DateObs, Miletus.ConstObs{Date}}, Bool}, SingleStock}, Int64}})
      @ Statistics /Users/sabae/src/julia/usr/share/julia/stdlib/v1.7/Statistics/src/Statistics.jl:74
    [4] mean
      @ /Users/sabae/src/julia/usr/share/julia/stdlib/v1.7/Statistics/src/Statistics.jl:44 [inlined]
    [5] value(m::MonteCarloModel{CoreModel{CurrencyQuantity{CurrencyUnit{:USD}, Float64}, Miletus.TermStructure.ConstantContinuousYieldCurve{Actual365, Float64}, Miletus.TermStructure.ConstantContinuousYieldCurve{Actual365, Float64}}, StepRange{Date, Day}, CurrencyQuantity{CurrencyUnit{:USD}, Float64}}, c::Miletus.When{Miletus.LiftObs{typeof(==), Tuple{Miletus.DateObs, Miletus.ConstObs{Date}}, Bool}, SingleStock})
      @ Miletus ~/.julia/dev/Miletus/src/models/montecarlo.jl:94
    [6] top-level scope
      @ /Users/sabae/src/julia/usr/share/julia/stdlib/v1.7/Test/src/Test.jl:445
    [7] include(fname::String)
      @ Base.MainInclude ./client.jl:451
    [8] top-level scope
      @ ~/.julia/dev/Miletus/test/runtests.jl:11
    [9] include(fname::String)
      @ Base.MainInclude ./client.jl:451
   [10] top-level scope
      @ none:6
   [11] eval
      @ ./boot.jl:373 [inlined]
   [12] exec_options(opts::Base.JLOptions)
      @ Base ./client.jl:268
   [13] _start()
      @ Base ./client.jl:495
ERROR: LoadError: There was an error during testing
in expression starting at /Users/alec/.julia/dev/Miletus/test/montecarlo.jl:31
in expression starting at /Users/alec/.julia/dev/Miletus/test/runtests.jl:11
ERROR: Package Miletus errored during testing

Minimal reproducing case for this is:

mean([100USD,100USD])

Statistics doesn't like the currency to be a Number, so I tried editing line 11 in currency.jl to be:

struct CurrencyQuantity{U<:CurrencyUnit,T<:Real} <: Real

Then there's a method ambiguity issue with ForwardDiff:

Error During Test at /Users/alec/.julia/dev/Miletus/test/greeks.jl:20
  Test threw exception
  Expression: delta(gbm1, c1; autodiff = true) ≈ delta(gbm1, c1)
  MethodError: *(::CurrencyQuantity{CurrencyUnit{:USD}, ForwardDiff.Dual{Nothing, Float64, 1}}, ::ForwardDiff.Dual{Nothing, Float64, 1}) is ambiguous. Candidates:
    *(x::Real, y::ForwardDiff.Dual{Ty}) where Ty in ForwardDiff at /Users/alec/.julia/packages/ForwardDiff/5gUap/src/dual.jl:140
    *(x::CurrencyQuantity{U}, y::Real) where U<:CurrencyUnit in Miletus.Currency at /Users/alec/.julia/dev/Miletus/src/currency.jl:46
  Possible fix, define
    *(::CurrencyQuantity{U}, ::ForwardDiff.Dual{Ty}) where {U<:CurrencyUnit, Ty}
  Stacktrace:
   [1] black(F::CurrencyQuantity{CurrencyUnit{:USD}, ForwardDiff.Dual{Nothing, Float64, 1}}, K::CurrencyQuantity{CurrencyUnit{:USD}, Float64}, s::Float64)
     @ Miletus ~/.julia/dev/Miletus/src/utils/black.jl:47
   [2] value(m::GeomBMModel{CoreModel{CurrencyQuantity{CurrencyUnit{:USD}, ForwardDiff.Dual{Nothing, Float64, 1}}, Miletus.TermStructure.ConstantContinuousYieldCurve{Actual365, Float64}, Miletus.TermStructure.ConstantContinuousYieldCurve{Actual365, Float64}}, Float64}, c::EuropeanCall{SingleStock, CurrencyQuantity{CurrencyUnit{:USD}, Float64}})
     @ Miletus ~/.julia/dev/Miletus/src/models/geombm.jl:54
   [3] delta(::GeomBMModel{CoreModel{CurrencyQuantity{CurrencyUnit{:USD}, Float64}, Miletus.TermStructure.ConstantContinuousYieldCurve{Actual365, Float64}, Miletus.TermStructure.ConstantContinuousYieldCurve{Actual365, Float64}}, Float64}, ::EuropeanCall{SingleStock, CurrencyQuantity{CurrencyUnit{:USD}, Float64}}; autodiff::Bool)
     @ Miletus ~/.julia/dev/Miletus/src/greeks.jl:51
   [4] macro expansion
     @ /Users/sabae/src/julia/usr/share/julia/stdlib/v1.7/Test/src/Test.jl:445 [inlined]
   [5] top-level scope
     @ ~/.julia/dev/Miletus/test/greeks.jl:20
ERROR: LoadError: There was an error during testing
in expression starting at /Users/alec/.julia/dev/Miletus/test/greeks.jl:3
in expression starting at /Users/alec/.julia/dev/Miletus/test/runtests.jl:12
ERROR: Package Miletus errored during testing

I'm unsure of the best way to proceed from here?

alecloudenback avatar Sep 22 '21 03:09 alecloudenback

I'm not sure if it will fix the issue but I don't think the package is supposed to overload promote_type. Instead, I believe we should define promote_rule.

andreasnoack avatar Sep 27 '21 16:09 andreasnoack

I'm not sure if it will fix the issue but I don't think the package is supposed to overload promote_type. Instead, I believe we should define promote_rule.

promote_type doesn't seem to be extending (a ChainRule?) and is local to the package I think.

alecloudenback avatar Sep 04 '22 04:09 alecloudenback

I think the updates are good to be reviewed now. I'm not sure if the CI is still functional; I tried to add a github actions version but it didn't trigger any tests, then subsequently removed. To see tests passing, it may need someone from @julpro to update the tests to something more current.

Locally:


(Miletus) pkg> test
     Testing Miletus
...
Precompiling project...
  3 dependencies successfully precompiled in 3 seconds. 66 already precompiled.
     Testing Running tests...
     Testing Miletus tests passed 

alecloudenback avatar Sep 04 '22 04:09 alecloudenback

@aviks edits have been resolved (I'm not sure if you get notified when I do that)

alecloudenback avatar Sep 05 '22 20:09 alecloudenback

Github actions tests are running after #6

aviks avatar Sep 14 '22 16:09 aviks