GeniusTrader/Brokers/Dubus.pm untested

filter: Statementstmt 0.0% 0 / 62 Branchbran 0.0% 0 / 34 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 127 CC 18 SCAR 50.0
CC
18
Cov
0%
calculate_order_commission
240.0
new
20.0
calculate_annual_account_charge
2.0
CRAP 147.7
1 package Finance::GeniusTrader::Brokers::Dubus;
2  
3 # Copyright 2005 Yannick Tournedouet
4 # This file is distributed under the terms of the General Public License
5 # version 2 or (at your option) any later version.
6  
7 # v1.0 : Initial version
8  
9 use strict;
10 use vars qw(@NAMES @ISA);
11  
12 use Finance::GeniusTrader::Brokers;
13 use Finance::GeniusTrader::Eval;
14 use Finance::GeniusTrader::Conf;
15  
16 @NAMES = ("Dubus[#1]");
17 @ISA = qw(Finance::GeniusTrader::Brokers);
18  
19 =head1 Finance::GeniusTrader::Brokers::Dubus
20  
21 =head2 Overview
22  
23 This module will calculate all commissions and charges according to
24 Dubus rules.
25  
26 =head2 Calculation
27  
28 Tarif Normal :
29  
30 4.9 Euros HT / order up o 2000 Euros + 0.30 % HT after (since 26/05/2005 4.9 € instead of 4 €)
31
32 Account charge : 0.37 € HT (min 100 €)
33  
34 Tarif Forfait :
35  
36 4.9 Euros HT / order up o 2000 Euros + 0.30 % HT after (since 26/05/2005 4.9 € instead of 4 €)
37 15 € Euros HT / order up to 30000 Euros
38 25 € Euros HT / order up to 75000 Euros
39 50 € Euros HT / more than 75000 Euros
40
41 Account charge : 76 €
42  
43 =head2 Parameters
44  
45 The first parameter could be initialized to :
46 "Normal" => Tarif Normal
47 "Forfait" => Tarif Forfait
48  
49 =cut
50  
51 sub new {
52 my $type = shift;
53 my $class = ref($type) || $type;
54 my $args = shift;
55 my $option = "Normal";
56
57 if (Finance::GeniusTrader::Conf::get("Brokers::Dubus::Tarif")) {
58 $option = Finance::GeniusTrader::Conf::get("Brokers::Dubus::Tarif");
59 }
60  
61 my $self = { 'args' => defined($args) ? $args : [ $option ]};
62  
63 $args->[0] = $option if (! defined($args->[0]));
64  
65 return manage_object(\@NAMES, $self, $class, $self->{'args'}, '');
66 }
67  
68 =head2 $broker->calculate_order_commission($order)
69  
70 Return the amount of money ask by the broker for the given order.
71  
72 =cut
73  
74 sub calculate_order_commission {
75 my ($self, $order) = @_;
76 my $forfait = $self->{'args'}[0];
77 my $TVA = (1 + 19.6 / 100);
78 my $commission = 0;
79 my $account = "";
80
81 # Override $TVA if Brokers::TVA is already defined in the user
82 # configuration file
83
84 if (Finance::GeniusTrader::Conf::get("Brokers::TVA")) {
85 $TVA = (1 + Finance::GeniusTrader::Conf::get("Brokers::TVA") / 100);
86 }
87
88 # get the account : PEA or simple account
89 if (Finance::GeniusTrader::Conf::get("Brokers::Account")) {
90 $account = Finance::GeniusTrader::Conf::get("Brokers::Account");
91 }
92
93 if ( (defined($order->quantity) && $order->quantity) and
94 (defined($order->price) && $order->price) ) {
95  
96 my $investment = $order->quantity * $order->price;
97
98 if ($forfait eq "Normal") {
99
100 if ($investment <= 2000) {
101 $commission = sprintf("%.2f", (6.9 * $TVA));
102 } else {
103 $commission = sprintf("%.2f", (($investment * 0.30) / 100 * $TVA));
104 }
105 }
106
107 if ($forfait eq "Forfait") {
108  
109 if ($investment <= 2000) {
110 $commission = sprintf("%.2f", (6.9 * $TVA));
111 } elsif ($investment <= 30000) {
112 $commission = sprintf("%.2f", (15 * $TVA));
113 } elsif ($investment <= 75000) {
114 $commission = sprintf("%.2f", (25 * $TVA));
115 } elsif ($investment > 75000) {
116 $commission = sprintf("%.2f", (50 * $TVA));
117 }
118 }
119
120 # Add the "Impôt de bourse"
121 if ($account ne "PEA") {
122 my $impot_de_bourse = $investment * 0.30 / 100;
123 my $abattement = 150 / 6.55957;
124 my $plafond = 4000 / 6.55957;
125
126 if ($impot_de_bourse > $abattement) {
127 $impot_de_bourse = $plafond if (($impot_de_bourse - $abattement) > $plafond);
128 $commission += sprintf("%.2f", ($impot_de_bourse - $abattement));
129 }
130 }
131
132 return $commission if ($commission != 0);
133 }
134 }
135  
136 =head2 $broker->calculate_annual_account_charge($portfolio, $year)
137  
138 Return the amount of money ask by the broker for the given year
139 according to the given portfolio.
140  
141 =cut
142  
143 sub calculate_annual_account_charge {
144 my ($self, $portfolio, $year) = @_;
145  
146 return 0;
147  
148 }
149  
150 1;