Skip to content

Commit 8e96230

Browse files
committed
Simplified the functor
1 parent 1b53c49 commit 8e96230

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

lib/model/trade.ml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ open CalendarLib
66
open Market
77
open Validator
88
open List
9+
open Taxfee
910

10-
module Trade(T : Trade_sig) : Trade_sig with module TaxFeeForTrade = T.TaxFeeForTrade = struct
11-
module TaxFeeForTrade = T.TaxFeeForTrade
11+
module Trade(TaxFeeForMarket: TaxFee) : Trade_sig = struct
12+
module TaxFeeForTrade = TaxFeeForMarket
1213

1314
type money = float
1415

@@ -32,6 +33,8 @@ module Trade(T : Trade_sig) : Trade_sig with module TaxFeeForTrade = T.TaxFeeFor
3233
let net_amount t: money =
3334
principal t +. (List.fold_left (fun acc (_, v) -> acc +. v) 0. t.tax_fees)
3435

36+
let tax_fees t = t.tax_fees
37+
3538
let value_as t tax_fee =
3639
let tax_fee_rate = List.assoc tax_fee TaxFeeForTrade.tax_fee_rates in
3740
tax_fee_rate *. (principal t)

lib/model/trade_sig.ml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module type Trade_sig = sig
1111
type t
1212
type money
1313

14+
(* create a validated trade *)
1415
val create_trade:
1516
account_no: Accountno.t
1617
-> isin: ISINCode.t
@@ -21,10 +22,15 @@ module type Trade_sig = sig
2122
-> trade_date: Calendar.t
2223
-> value_date: Calendar.t option -> (t, string) validator_result
2324

25+
(* decorate a trade with tax/fees and net amount *)
2426
val with_tax_fees: t -> t
2527

28+
(* get the principal amount of the trade *)
2629
val principal: t -> money
2730

31+
(* get the net amount of the trade *)
2832
val net_amount: t -> money
33+
34+
val tax_fees: t -> (TaxFeeForTrade.t * money) list
2935

3036
end

0 commit comments

Comments
 (0)