Skip to content

Commit

Permalink
Merge pull request #17 from SaguaroCapital/dev
Browse files Browse the repository at this point in the history
Add Aqua, Impute dependencies
  • Loading branch information
tylerjthomas9 authored Jun 5, 2023
2 parents e5d31c3 + 8ef5625 commit 44ddd39
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 34 deletions.
10 changes: 7 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
name = "SaguaroTrader"
uuid = "26277856-a3f7-4646-aaac-f090473ab108"
authors = ["Tyler Thomas <[email protected]>"]
version = "0.2.0"
version = "0.2.1"

[deps]
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Impute = "f7bf1975-0170-51b9-8c5f-a992d46b9575"
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"

[compat]
Aqua = "0.6"
CSV = "0.10"
DataFrames = "1"
DataStructures = "0.18"
Impute = "0.6"
PrecompileTools = "1"
julia = "1.6"

[extras]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test"]
test = ["Aqua", "Test"]
2 changes: 1 addition & 1 deletion src/SaguaroTrader.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ using CSV
using DataFrames
using Dates
using DataStructures
using Impute
using Random
using UUIDs

Expand Down Expand Up @@ -81,7 +82,6 @@ export
Portfolio,
total_market_value,
total_equity,
subscribe_funds,

# alpha model
AlphaModel,
Expand Down
33 changes: 6 additions & 27 deletions src/data/daily_bar_csv.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,31 +77,6 @@ function _detect_adj_column(columns::Vector{String}, identifier::String)
return error("Unable to detect '$identifier' column in columns: $columns")
end

"""
Taken from Impute.jl, because it was breaking the build
"""
function _impute_locf(data::AbstractVector{Union{T,Missing}}, limit=nothing) where {T}
@assert !all(ismissing, data)
start_idx = findfirst(!ismissing, data)
count = 1

@inbounds for i in (start_idx + 1):lastindex(data)
if ismissing(data[i])
if limit === nothing
data[i] = data[i - 1]
elseif count <= limit
data[i] = data[start_idx]
count += 1
end
else
start_idx = i
count = 1
end
end

return data
end

"""
Estimate Bid-Ask spreads from OHLCV data
Expand Down Expand Up @@ -166,7 +141,11 @@ function _convert_bar_frame_into_df_bid_ask(
df_bid = vcat(df_open, df_close; cols=:union)
sort!(df_bid, time_col)
if any(ismissing.(df_bid.Ask))
df_bid = transform(df_bid, "Ask" .=> _impute_locf; renamecols=false)
df_bid = transform(
df_bid,
"Ask" .=> x -> impute(x, LOCF(; limit=limit); dims=:cols);
renamecols=false,
)
end
df_bid.Bid = df_bid.Ask

Expand Down Expand Up @@ -214,7 +193,7 @@ struct CSVDailyBarSource <: DataSource
csv_symbols::Union{Nothing,Vector{Symbol}}=nothing,
market_open::Dates.CompoundPeriod=Hour(14) + Minute(30),
market_close::Dates.CompoundPeriod=Hour(20) + Minute(59),
start_dt::DateTime=DateTime(1900), #TODO: multiple dispatch
start_dt::DateTime=DateTime(1900),
end_dt::DateTime=DateTime(2100),
time_col::Symbol=:timestamp,
open_col::Symbol=:Open,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ function _create_rebalance_orders(
target_positions::Dict{Asset,Int},
dt::DateTime,
)
# TODO: Add the ability to ride positions for longer without trimming/adding every period
# zero out positions not in target portfolio
target_positions_assets = keys(target_positions)
rebalance_orders_dict = Dict{Asset,Order}()
for (_, position) in current_positions
Expand Down Expand Up @@ -88,7 +86,6 @@ Returns
- `Dict{Asset, Int}`: Rebalance orders
"""
function _create_rebalance_orders(pcm::PortfolioConstructionModel, dt::DateTime)
# full_asset = _get_assets(pcm) # TODO: do we need the full asset list?
weights = pcm.alpha_model(dt)
target_positions = pcm.order_sizer(pcm.broker, pcm.portfolio_id, weights, dt)
current_positions = _get_current_positions(pcm)
Expand Down
5 changes: 5 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

using Aqua
using CSV
using DataFrames
using Dates
Expand Down Expand Up @@ -29,3 +30,7 @@ for t in tests
println("* $fp ...")
include(fp)
end

@testset verbose = true "Code quality (Aqua.jl)" begin
Aqua.test_all(SaguaroTrader; ambiguities=false)
end

0 comments on commit 44ddd39

Please sign in to comment.