Skip to content

Commit

Permalink
Merge pull request #28 from bcicc/main
Browse files Browse the repository at this point in the history
Removing Unnecessary Argument Types for Fee Model
  • Loading branch information
tylerjthomas9 authored Oct 13, 2023
2 parents c38e88a + d6ad9d0 commit 29b4613
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 12 deletions.
1 change: 0 additions & 1 deletion docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ AlwaysOpenExchange

# Fee Model
```@docs
FeeModel
ZeroFeeModel
PercentFeeModel
calculate_fee
Expand Down
1 change: 0 additions & 1 deletion src/SaguaroTrader.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ export
AlwaysOpenExchange,

# fee model
FeeModel,
ZeroFeeModel,
PercentFeeModel,
calculate_fee,
Expand Down
6 changes: 3 additions & 3 deletions src/broker/simulated_broker.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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}}`
Expand All @@ -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}
Expand All @@ -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"
Expand Down
7 changes: 3 additions & 4 deletions src/fee_model/fee_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,28 @@
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`
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
Expand Down
2 changes: 1 addition & 1 deletion src/fee_model/percent_fee_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/fee_model/zero_fee_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/order_sizer/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 29b4613

Please sign in to comment.