From d6ad9d0b82bf5684f835764ca3127f67291c998b Mon Sep 17 00:00:00 2001 From: bcicc Date: Fri, 13 Oct 2023 15:35:53 -0700 Subject: [PATCH] Fee Model Changes --- docs/src/api.md | 1 - src/SaguaroTrader.jl | 1 - src/broker/simulated_broker.jl | 6 +++--- src/fee_model/fee_model.jl | 7 +++---- src/fee_model/percent_fee_model.jl | 2 +- src/fee_model/zero_fee_model.jl | 2 +- src/order_sizer/utils.jl | 2 +- 7 files changed, 9 insertions(+), 12 deletions(-) diff --git a/docs/src/api.md b/docs/src/api.md index 7c5d76e..8ac734a 100644 --- a/docs/src/api.md +++ b/docs/src/api.md @@ -39,7 +39,6 @@ AlwaysOpenExchange # Fee Model ```@docs -FeeModel ZeroFeeModel PercentFeeModel calculate_fee diff --git a/src/SaguaroTrader.jl b/src/SaguaroTrader.jl index ae75467..5519d32 100644 --- a/src/SaguaroTrader.jl +++ b/src/SaguaroTrader.jl @@ -55,7 +55,6 @@ export AlwaysOpenExchange, # fee model - FeeModel, ZeroFeeModel, PercentFeeModel, calculate_fee, diff --git a/src/broker/simulated_broker.jl b/src/broker/simulated_broker.jl index a9546b3..c336241 100644 --- a/src/broker/simulated_broker.jl +++ b/src/broker/simulated_broker.jl @@ -11,7 +11,7 @@ Fields - `account_id::String` - `base_currency::String` - `initial_cash::Float64` -- `fee_model::FeeModel` +- `fee_model` - `cash_balances::Dict{String,Float64}` - `portfolios::Dict{String,Portfolio}` - `open_orders::Dict{String,Queue{Order}}` @@ -24,7 +24,7 @@ mutable struct SimulatedBroker <: Broker account_id::String base_currency::String initial_cash::Float64 - fee_model::FeeModel + fee_model slippage_model::SlippageModel # market_impact_model::AbstractMarketImpactModel # TODO: Implement cash_balances::Dict{String,Float64} @@ -38,7 +38,7 @@ mutable struct SimulatedBroker <: Broker account_id::String="", base_currency::String="USD", initial_cash::Float64=0.0, - fee_model::FeeModel=ZeroFeeModel(), + fee_model=ZeroFeeModel(), slippage_model::SlippageModel=ZeroSlippageModel(), ) @assert initial_cash >= 0.0 "initial cash must be >= 0" diff --git a/src/fee_model/fee_model.jl b/src/fee_model/fee_model.jl index 8e4a0bd..dff79ce 100644 --- a/src/fee_model/fee_model.jl +++ b/src/fee_model/fee_model.jl @@ -3,21 +3,20 @@ Abstract type to handle the calculation of brokerage fee, fees and taxes. """ -abstract type FeeModel end include("zero_fee_model.jl") include("percent_fee_model.jl") """ ```julia -calculate_fee(fee_model::FeeModel, quantity::Real, price::Float64) +calculate_fee(fee_model, quantity::Real, price::Float64) ``` Calculate the fee for an order Parameters ---------- -- `fee_model::FeeModel` +- `fee_model` - `quantity::Real` - `price::Float64` @@ -25,7 +24,7 @@ Returns ------- - `Float64`: The total fee for the order (tax + fee) """ -function calculate_fee(fee_model::FeeModel, quantity::Real, price::Float64) +function calculate_fee(fee_model, quantity::Real, price::Float64) tax = _calc_tax(fee_model, quantity, price) fee = _calc_fee(fee_model, quantity, price) return tax + fee diff --git a/src/fee_model/percent_fee_model.jl b/src/fee_model/percent_fee_model.jl index 6249c29..c003b8c 100644 --- a/src/fee_model/percent_fee_model.jl +++ b/src/fee_model/percent_fee_model.jl @@ -12,7 +12,7 @@ Fields - `fee_pct::Float64` = 0.0 - `tax_pct::Float64` = 0.0 """ -struct PercentFeeModel <: FeeModel +struct PercentFeeModel fee_pct::Float64 tax_pct::Float64 function PercentFeeModel(; fee_pct::Float64=0.0, tax_pct::Float64=0.0) diff --git a/src/fee_model/zero_fee_model.jl b/src/fee_model/zero_fee_model.jl index ea0bb17..2454b53 100644 --- a/src/fee_model/zero_fee_model.jl +++ b/src/fee_model/zero_fee_model.jl @@ -4,7 +4,7 @@ A FeeModel that produces no fee/fees/taxes. total_fee = 0.0 """ -struct ZeroFeeModel <: FeeModel end +struct ZeroFeeModel end function _calc_tax(fee_model::ZeroFeeModel, quantity::Real, price::Float64) return 0.0 diff --git a/src/order_sizer/utils.jl b/src/order_sizer/utils.jl index e9a3ae0..78c72db 100644 --- a/src/order_sizer/utils.jl +++ b/src/order_sizer/utils.jl @@ -21,7 +21,7 @@ calculate the quantity that we should buy to get as close as possible without going over. """ -function _calculate_asset_quantity(fee_model::FeeModel, max_cost::Float64, price::Float64) +function _calculate_asset_quantity(fee_model, max_cost::Float64, price::Float64) quantity = Int(floor(max_cost / price)) fee = calculate_fee(fee_model, quantity, price) while (quantity * price + fee) > max_cost