diff --git a/Project.toml b/Project.toml index de3295f..717a641 100644 --- a/Project.toml +++ b/Project.toml @@ -4,7 +4,7 @@ keywords = ["Finance", "Asset"] license = "MIT" desc = "Financial assets" authors = ["Eric Forgy ", "ScottPJones "] -version = "0.10.0" +version = "0.10.1" [deps] Currencies = "0fd90b74-7c1f-579e-9252-02cd883047b9" @@ -13,7 +13,7 @@ Instruments = "2a4f3d17-849a-48a1-809e-d780c70a95a0" [compat] Currencies = "0.18" -Instruments = "0.9" +Instruments = "0.10" [extras] Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/README.md b/README.md index c8d9221..f2a325b 100644 --- a/README.md +++ b/README.md @@ -21,8 +21,6 @@ When a currency is thought of as a financial instrument (as opposed to a mere la The @cash macro will set up short constants, matching the ISO 4217 names, so that you can use `USD` instead of `Cash{:USD,2}`. -One can also use the `cash` string macro, i.e. `cash"GBP"`, to refer to a particular Cash type. - For example: ```julia @@ -49,8 +47,9 @@ Although `Cash` is a singleton type, other financial instruments may contain var A `Position` represents an amount of ownership of a financial instrument. For example, Microsoft stock ```julia -const MSFT = stock(:MSFT,USD) +julia> @stock MSFT ``` + is a financial instrument. A position could be 1,000 shares of `MSFT` and can be represented in one of two ways: ```julia @@ -65,11 +64,6 @@ julia> 1000MSFT 1000MSFT ``` -The `stock` string macro can also be used, for example: -`stock"MSFT"` -or -`stock"GSK"gbp` (to indicate a stock, GlaxoSmithKline, denominated in British Pounds). - Similarly, cash positions can be constructed as ```julia diff --git a/src/Assets.jl b/src/Assets.jl index a6b006a..dd91bce 100644 --- a/src/Assets.jl +++ b/src/Assets.jl @@ -17,10 +17,8 @@ Licensed under MIT License, see LICENSE.md module Assets using Currencies, FixedPointDecimals, Instruments -import Currencies: unit, code, name -import Instruments: Position -export Position, Currency, Cash, cash, @cash +export Position, Currency, Cash, cash, @cash, unit, code, name export Stock, stock, @stock "`Cash` is an implementation of `Instrument` represented by a singleton type, with its currency symbol and the number of digits in the minor units, typically 0, 2, or 3, as parameters." @@ -31,7 +29,7 @@ struct Cash{S, N} <: Instrument{S,Currency{S}} end end -function Position(::Type{I},amt) where {S,N,I<:Cash{S,N}} +function Instruments.Position(::Type{I},amt) where {S,N,I<:Cash{S,N}} T = FixedDecimal{Int,N} Position{I,T}(T(amt)) end @@ -50,16 +48,16 @@ macro cash(syms) end end -unit(::Type{Cash{S,N}}) where {S,N} = N +Currencies.unit(::Type{Cash{S,N}}) where {S,N} = N -code(::Type{C}) where {S,C<:Cash{S}} = code(S) +Currencies.code(::Type{C}) where {S,C<:Cash{S}} = code(S) -name(::Type{C}) where {S,C<:Cash{S}} = name(S) +Currencies.name(::Type{C}) where {S,C<:Cash{S}} = name(S) """`Stock` is an implementation of a simple `Instrument` represented by a singleton type with a stock symbol and currency, e.g. `Stock{:MSFT,ccy"USD"}`. The currency can be omitted and it will default to USD, e.g. `Stock(:MSFT)`.""" struct Stock{S,C} <: Instrument{S,C} end -function Position(::Type{I},amt) where {I<:Stock} +function Instruments.Position(::Type{I},amt) where {I<:Stock} Position{I,Int}(amt) end diff --git a/test/runtests.jl b/test/runtests.jl index f0f3d92..6bd2eb4 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -15,7 +15,7 @@ currencies = ((USD, :USD, 2, 840, "US Dollar"), @testset "Basic currencies" begin for (pos, s, u, c, n) in currencies - ccy = currency(pos(1)) + ccy = currency(pos) @test symbol(ccy) == s @test unit(ccy) == u @test name(ccy) == n @@ -37,8 +37,8 @@ end pos = Position(ct,1) pt = typeof(pos) - @test currency(pos) == currency(ct) - @test currency(1pt) == ccy + @test currency(pt) == currency(ct) + @test currency(pt) == ccy @test 1pt == pos @test pos * 1 == pos @test 1pos + 1pos == Position(ct,2)