Git Product home page Git Product logo

Comments (2)

alecloudenback avatar alecloudenback commented on August 16, 2024

Proposed in #41:

mt = UltimateMortality([0.5,0.5])

# whole life insurance
ins = Insurance(
        SingleLife(mort = mt,issue_age = 0),
        Yields.Constant(0.05)
) 

@test survival(ins) == [1.0,0.5]
@test discount(ins) == [1.0 / 1.05, 1 / 1.05^2]
@test benefit(ins) == [1.0,1.0]
@test probability(ins) == [0.5,0.25]
@test cashflows(ins) == [0.5,0.25]
@test cashflows(ins) == benefit(ins) .* probability(ins)
@test timepoints(ins) == [1.0,2.0]
@test present_value(ins)   0.5 / 1.05 + 0.5 * 0.5 / 1.05 ^ 2

Status Quo:

ins = LifeContingency(
    SingleLife(
        mort = mt,
        issue_age = 0
    ),
    Yields.Constant(0.05)
)

And then all you can do is this:

@test insurance(ins)  0.5 / 1.05 + 0.5 * 0.5 / 1.05 ^ 2

from lifecontingencies.jl.

alecloudenback avatar alecloudenback commented on August 16, 2024

Benchmarks indicate that the new API would be slower, but that's solvable (specialize on the functions, build a pipeline that doesn't allocate the intermediate steps, etc)

julia> @benchmark present_value(Insurance($ins   ))		#new
BenchmarkTools.Trial: 
  memory estimate:  111.30 KiB
  allocs estimate:  1579
  --------------
  minimum time:     81.200 μs (0.00% GC)
  median time:      83.301 μs (0.00% GC)
  mean time:        92.890 μs (6.73% GC)
  maximum time:     3.461 ms (96.72% GC)
  --------------
  samples:          10000
  evals/sample:     1

julia> @benchmark insurance($ins   )              		#old
BenchmarkTools.Trial: 
  memory estimate:  83.88 KiB
  allocs estimate:  740
  --------------
  minimum time:     35.000 μs (0.00% GC)
  median time:      48.000 μs (0.00% GC)
  mean time:        48.172 μs (6.57% GC)
  maximum time:     2.160 ms (96.04% GC)
  --------------
  samples:          10000**

from lifecontingencies.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.