Code Monkey home page Code Monkey logo

Comments (2)

pazzo83 avatar pazzo83 commented on July 22, 2024

Thanks @EricForgy! I haven't gotten to cross-currency swaps yet, but I will definitely take into account that design flaw in QuantLib itself (I wasn't aware of it). I'm curious about the units that you mention, do you have a separate type for that?

from quantlib.jl.

EricForgy avatar EricForgy commented on July 22, 2024

Hi @pazzo83 ,

I'm curious about the units that you mention, do you have a separate type for that?

I've been thinking of this problem for a while and it recently came up on julia-users group here:

For the time being, I decided not go that route, i.e. implement each unit as a type and handle dispatch through parameters, and instead implemented a type:

Units = Union{Currency,Identifier}
type Holding{Q<:Number,U<:Units}
    quantity::Q
    units::U
end
Holding() = Holding{Int64,Currency}(0,HKD)
Holding(quantity,units) = Holding{typeof(quantity),typeof(units)}(quantity,units)

My Currency type is an enum, so I would define

hkd = Holding(1,HKD)

and then define arithmetic operators so that

julia> 10hkd
Holding:
  Quantity: 10
  Units: HKD

julia> 10hkd + 20hkd
Holding:
  Quantity: 30
  Units: HKD

julia> 10hkd + 5usd
ERROR: Unit mismatch

I haven't done any benchmarking yet, so I don't know if this is a horrible idea, but at least I'm able to make progress :)

from quantlib.jl.

Related Issues (16)

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.