Skip to content

Commit

Permalink
Merge pull request #12 from SaguaroCapital/dev
Browse files Browse the repository at this point in the history
Improve `get_bid`, `get_ask` performance
  • Loading branch information
tylerjthomas9 authored Mar 22, 2023
2 parents 681e5b8 + 1ffb7c9 commit 86cfb01
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 14 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "SaguaroTrader"
uuid = "26277856-a3f7-4646-aaac-f090473ab108"
authors = ["Tyler <[email protected]>"]
version = "0.1.0"
authors = ["Tyler Thomas <[email protected]>"]
version = "0.1.1"

[deps]
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
Expand Down
8 changes: 4 additions & 4 deletions src/data/daily_bar_csv.jl
Original file line number Diff line number Diff line change
Expand Up @@ -256,21 +256,21 @@ end

function get_bid(ds::CSVDailyBarSource, dt::DateTime, asset::Symbol)
df_bid_ask = ds.dict_asset_dfs[asset]
ix = findfirst(>(dt), df_bid_ask.timestamp::Vector{DateTime})::Union{Nothing,Int64}
ix = searchsortedfirst(df_bid_ask.timestamp::Vector{DateTime}, dt)::Union{Nothing,Int64}
if isnothing(ix) || (ix == 1)
return float(NaN)::Float64
else
return @inbounds df_bid_ask[ix - 1, :Bid]::Float64
return @inbounds df_bid_ask[ix, :Bid]::Float64
end
end

function get_ask(ds::CSVDailyBarSource, dt::DateTime, asset::Symbol)
df_bid_ask = ds.dict_asset_dfs[asset]
ix = findfirst(>(dt), df_bid_ask.timestamp::Vector{DateTime})::Union{Nothing,Int64}
ix = searchsortedfirst(df_bid_ask.timestamp::Vector{DateTime}, dt)::Union{Nothing,Int64}
if isnothing(ix) || (ix == 1)
return float(NaN)::Float64
else
return @inbounds df_bid_ask[ix - 1, :Ask]::Float64
return @inbounds df_bid_ask[ix, :Ask]::Float64
end
end

Expand Down
3 changes: 1 addition & 2 deletions src/risk_model/risk_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
"""
"""
struct RiskModel
end
struct RiskModel end
3 changes: 1 addition & 2 deletions src/slippage_model/slippage_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,4 @@ end
"""
"""
struct VolumeSharesSlippageModel <: SlippageModel
end
struct VolumeSharesSlippageModel <: SlippageModel end
6 changes: 2 additions & 4 deletions test/data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@
ds = CSVDailyBarSource("./test_data/"; csv_symbols=[:AMD, :NVDA])
@test ds.csv_symbols == [:AMD, :NVDA]

# bid = get_bid(ds, DateTime(2019, 4, 9, 14, 29), :AMD)
# @test bid == isnan(bid) #TODO: Do we want nan here?
bid = get_bid(ds, DateTime(2019, 4, 9, 14, 30), :AMD)
@test bid == 28.24

ask = get_ask(ds, DateTime(2019, 4, 9, 21, 0), :AMD)
@test ask == 27.24 # isnan(ask) #TODO: Do we want nan here?
ask = get_ask(ds, DateTime(2019, 4, 8, 21, 0), :AMD)
@test ask == 28.24
ask = get_ask(ds, DateTime(2019, 4, 9, 20, 59), :AMD)
@test ask == 27.24

Expand Down

0 comments on commit 86cfb01

Please sign in to comment.