diff --git a/Project.toml b/Project.toml index b76f356..0339dfb 100644 --- a/Project.toml +++ b/Project.toml @@ -1,26 +1,30 @@ name = "SaguaroTrader" uuid = "26277856-a3f7-4646-aaac-f090473ab108" authors = ["Tyler Thomas "] -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"] diff --git a/src/SaguaroTrader.jl b/src/SaguaroTrader.jl index 34f1a19..63fa9a8 100644 --- a/src/SaguaroTrader.jl +++ b/src/SaguaroTrader.jl @@ -4,6 +4,7 @@ using CSV using DataFrames using Dates using DataStructures +using Impute using Random using UUIDs @@ -81,7 +82,6 @@ export Portfolio, total_market_value, total_equity, - subscribe_funds, # alpha model AlphaModel, diff --git a/src/data/daily_bar_csv.jl b/src/data/daily_bar_csv.jl index d82059c..0566722 100644 --- a/src/data/daily_bar_csv.jl +++ b/src/data/daily_bar_csv.jl @@ -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 @@ -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 @@ -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, diff --git a/src/portfolio_construction_model/portfolio_construction_model.jl b/src/portfolio_construction_model/portfolio_construction_model.jl index 243b972..5b3431d 100644 --- a/src/portfolio_construction_model/portfolio_construction_model.jl +++ b/src/portfolio_construction_model/portfolio_construction_model.jl @@ -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 @@ -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) diff --git a/test/runtests.jl b/test/runtests.jl index fd457da..c2c602d 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,4 +1,5 @@ +using Aqua using CSV using DataFrames using Dates @@ -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