Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
Remove import

Update test so currency method acts on position type (not instance)

Update Project.toml
  • Loading branch information
Eric Forgy authored and Eric Forgy committed Jul 6, 2020
1 parent cced416 commit 15d6b8a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 21 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ keywords = ["Finance", "Asset"]
license = "MIT"
desc = "Financial assets"
authors = ["Eric Forgy <[email protected]>", "ScottPJones <[email protected]>"]
version = "0.10.0"
version = "0.10.1"

[deps]
Currencies = "0fd90b74-7c1f-579e-9252-02cd883047b9"
Expand All @@ -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"
Expand Down
10 changes: 2 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
14 changes: 6 additions & 8 deletions src/Assets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand All @@ -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
Expand All @@ -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

Expand Down
6 changes: 3 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 15d6b8a

Please sign in to comment.