Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cross-currency swap #1

Open
EricForgy opened this issue Mar 1, 2016 · 2 comments
Open

Cross-currency swap #1

EricForgy opened this issue Mar 1, 2016 · 2 comments

Comments

@EricForgy
Copy link

Hi @pazzo83

This package looks great and will be a good inspiration for me and my team.

I also considered QuantLib originally, but we are based in Asia and one of the most important swaps in this part of the world for institutional investors would be cross-currency swaps. I may have misunderstood, but it wasn't clear how QuantLib would handle cross-currency swaps. For example, see the "Further Developments" sections here:

It indicates an initial design flaw with QuantLib. Could this (or has this) been corrected with JQuantLib?

For our internal work, we value instruments not with a simple float, but with a type that has units, e.g. 10usd, 20sgd, etc.

Best regards,
Eric

@pazzo83
Copy link
Owner

pazzo83 commented Mar 2, 2016

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?

@EricForgy
Copy link
Author

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 :)

pazzo83 pushed a commit that referenced this issue Jan 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants