Skip to content

Instantly share code, notes, and snippets.

@milktrader
Last active August 29, 2015 14:17
Show Gist options
  • Save milktrader/97d96b51b53eec747a19 to your computer and use it in GitHub Desktop.
Save milktrader/97d96b51b53eec747a19 to your computer and use it in GitHub Desktop.
Reactive getindex hack
julia> using Grist #brings in Reactive and other experimental packages
julia> res
10-element Array{Timestamps.Timestamp{T},1}:
2000-01-03 | 200 Stock 95.0 $ AAPL
2000-03-15 | -100 Stock 116.25 $ AAPL
2000-05-25 | 100 Stock 87.27 $ AAPL
2000-08-07 | -100 Stock 47.94 $ AAPL
2000-10-17 | 100 Stock 20.12 $ AAPL
2000-12-28 | -100 Stock 14.81 $ AAPL
2001-03-13 | 100 Stock 19.56 $ AAPL
2001-05-23 | -100 Stock 23.23 $ AAPL
2001-08-03 | 100 Stock 19.5 $ AAPL
2001-10-19 | -100 Stock 18.3 $ AAPL
julia> A = Input(res[1].value)
ticker: AAPL
basis: 111.94
quantity: 100
currency: USD
tick: 0.01
multiplier: 1.0
id: NA
julia> A.value.basis = 100; # make mental math easier
julia> A
ticker: AAPL
basis: 100.0
quantity: 100
currency: USD
tick: 0.01
multiplier: 1.0
id: NA
julia> buysome = Input((100,90.00))
(100,90.0)
julia> function Base.getindex{T<:Input}(I::T, n::Int64)
Input(I.value[n])
end
getindex (generic function with 172 methods)
julia> bot_some = lift((fa, qty, fill) -> transact(fa,qty,fill), A, buysome[1], buysome[2])
200
julia> A
ticker: AAPL
basis: 95.0
quantity: 200
currency: USD
tick: 0.01
multiplier: 1.0
id: NA
@milktrader
Copy link
Author

@shashi provided this solution

julia> initial_buy = (100,90.00)
(100,90.0)
julia> buysome = Input(initial_buy)
(100,90.0)
julia> bot_some = lift(A, buysome) do fa, buy
    qty, fill = buy
    transact(fa,qty,fill)
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment