| 1 | package Finance::GeniusTrader::Brokers::SelfTrade; | ||
| 2 | |||
| 3 | # Copyright 2000-2002 Raphaël Hertzog, Fabien Fulhaber | ||
| 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 | use strict; | ||
| 8 | use vars qw(@NAMES @ISA); | ||
| 9 | |||
| 10 | use Finance::GeniusTrader::Brokers; | ||
| 11 | use Finance::GeniusTrader::Eval; | ||
| 12 | use Finance::GeniusTrader::Conf; | ||
| 13 | |||
| 14 | @NAMES = ("SelfTrade[#1]"); | ||
| 15 | @ISA = qw(Finance::GeniusTrader::Brokers); | ||
| 16 | |||
| 17 | =head1 Finance::GeniusTrader::Brokers::SelfTrade | ||
| 18 | |||
| 19 | =head2 Overview | ||
| 20 | |||
| 21 | This module will calculate all commissions and charges according to | ||
| 22 | SelfTrade rules. | ||
| 23 | |||
| 24 | =head2 Calculation | ||
| 25 | |||
| 26 | Forfait Découverte : 6.5 Euros HT / order up o 3000 Euros + 0.30 % HT after | ||
| 27 | |||
| 28 | Forfait Intégral : 14.95 Euros HT / order up to 10000 Euros + 0.15 % HT after | ||
| 29 | |||
| 30 | For both options, there's no annual account charge ! | ||
| 31 | |||
| 32 | =head2 Parameters | ||
| 33 | |||
| 34 | The first parameter could be initialized to : | ||
| 35 | "Découverte" => Forfait Découverte | ||
| 36 | "Intégral" => Forfait Intégral | ||
| 37 | |||
| 38 | =cut | ||
| 39 | |||
| 40 | sub new { | ||
| 41 | my $type = shift; | ||
| 42 | my $class = ref($type) || $type; | ||
| 43 | my $args = shift; | ||
| 44 | my $option = "Découverte"; | ||
| 45 | |||
| 46 | if (Finance::GeniusTrader::Conf::get("Brokers::SelfTrade::Forfait")) { | ||
| 47 | $option = Finance::GeniusTrader::Conf::get("Brokers::SelfTrade::Forfait"); | ||
| 48 | } | ||
| 49 | |||
| 50 | my $self = { 'args' => defined($args) ? $args : [ $option ] }; | ||
| 51 | |||
| 52 | $args->[0] = $option if (! defined($args->[0])); | ||
| 53 | |||
| 54 | return manage_object(\@NAMES, $self, $class, $self->{'args'}, ''); | ||
| 55 | } | ||
| 56 | |||
| 57 | =head2 $broker->calculate_order_commission($order) | ||
| 58 | |||
| 59 | Return the amount of money ask by the broker for the given order. | ||
| 60 | |||
| 61 | =cut | ||
| 62 | |||
| 63 | sub calculate_order_commission { | ||
| 64 | my ($self, $order) = @_; | ||
| 65 | my $forfait = $self->{'args'}[0]; | ||
| 66 | my $TVA = (1 + 19.6 / 100); | ||
| 67 | my $commission = 0; | ||
| 68 | |||
| 69 | # Override $TVA if Brokers::TVA is already defined in the user | ||
| 70 | # configuration file | ||
| 71 | |||
| 72 | if (Finance::GeniusTrader::Conf::get("Brokers::TVA")) { | ||
| 73 | $TVA = (1 + Finance::GeniusTrader::Conf::get("Brokers::TVA") / 100); | ||
| 74 | } | ||
| 75 | |||
| 76 | if ( (defined($order->quantity) && $order->quantity) and | ||
| 77 | (defined($order->price) && $order->price) ) { | ||
| 78 | |||
| 79 | my $investment = $order->quantity * $order->price; | ||
| 80 | |||
| 81 | if ($forfait eq "Découverte") { | ||
| 82 | |||
| 83 | if ($investment < 3000) { | ||
| 84 | $commission = sprintf("%.2f", (6.50 * $TVA)); | ||
| 85 | } else { | ||
| 86 | $commission = sprintf("%.2f", (6.50 * $TVA + (($investment - 3000) * 0.30 / 100 * $TVA))); | ||
| 87 | } | ||
| 88 | } | ||
| 89 | |||
| 90 | if ($forfait eq "Intégral") { | ||
| 91 | |||
| 92 | if ($investment < 10000) { | ||
| 93 | $commission = sprintf("%.2f", (14.95 * $TVA)); | ||
| 94 | } else { | ||
| 95 | $commission = sprintf("%.2f", (14.95 * $TVA + (($investment - 10000) * 0.15 / 100 * $TVA))); | ||
| 96 | } | ||
| 97 | } | ||
| 98 | |||
| 99 | # Add the "Impôt de bourse" | ||
| 100 | my $impot_de_bourse = $investment * 0.30 / 100; | ||
| 101 | my $abattement = 150 / 6.55957; | ||
| 102 | my $plafond = 4000 / 6.55957; | ||
| 103 | |||
| 104 | if ($impot_de_bourse > $abattement) { | ||
| 105 | $impot_de_bourse = $plafond if (($impot_de_bourse - $abattement) > $plafond); | ||
| 106 | $commission += sprintf("%.2f", ($impot_de_bourse - $abattement)); | ||
| 107 | } | ||
| 108 | |||
| 109 | return $commission if ($commission != 0);; | ||
| 110 | } | ||
| 111 | } | ||
| 112 | |||
| 113 | =head2 $broker->calculate_annual_account_charge($portfolio, $year) | ||
| 114 | |||
| 115 | Return the amount of money ask by the broker for the given year | ||
| 116 | according to the given portfolio. | ||
| 117 | |||
| 118 | =cut | ||
| 119 | |||
| 120 | sub calculate_annual_account_charge { | ||
| 121 | my ($self, $portfolio, $year) = @_; | ||
| 122 | |||
| 123 | return 0; | ||
| 124 | |||
| 125 | } | ||
| 126 | |||
| 127 | 1; |