« GeniusTrader/Graphics/Driver/SVG.pm
↑ Summary
GeniusTrader/CloseStrategy/LimitPeriodInTheMarket.pm »
| 1 | package Finance::GeniusTrader::PortfolioManager; | ||
| 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(); | ||
| 9 | |||
| 10 | #ALL# use Log::Log4perl qw(:easy); | ||
| 11 | use Finance::GeniusTrader::Portfolio; | ||
| 12 | use Finance::GeniusTrader::Prices; | ||
| 13 | use Finance::GeniusTrader::SystemManager; | ||
| 14 | use Finance::GeniusTrader::Eval; | ||
| 15 | |||
| 16 | =head1 NAME | ||
| 17 | |||
| 18 | Finance::GeniusTrader::PortfolioManager - Manages a portfolio | ||
| 19 | |||
| 20 | =head1 DESCRIPTION | ||
| 21 | |||
| 22 | A PortfolioManager is an entity interacting between a Portfolio, | ||
| 23 | a Trading System, money management rules and trade filters. | ||
| 24 | |||
| 25 | When it comes to starting a new position (ie submitting an order | ||
| 26 | to start a position), the money management system comes in again to | ||
| 27 | decide how much to put on the trade. | ||
| 28 | |||
| 29 | Filters can be applied to accept/refuse trades proposed by the | ||
| 30 | various trading systems. | ||
| 31 | |||
| 32 | =over | ||
| 33 | |||
| 34 | =item C<< my $manager = Finance::GeniusTrader::PortfolioManager->new($portfolio) >> | ||
| 35 | |||
| 36 | Create a new portfolio manager that implements a money management | ||
| 37 | strategy. | ||
| 38 | |||
| 39 | =cut | ||
| 40 | sub new { | ||
| 41 | my $type = shift; | ||
| 42 | my $class = ref($type) || $type; | ||
| 43 | my $portfolio = shift; | ||
| 44 | |||
| 45 | my $self = { "moneymanagement" => [] }; | ||
| 46 | |||
| 47 | bless $self, $class; | ||
| 48 | |||
| 49 | if (defined($portfolio)) { | ||
| 50 | $self->set_portfolio($portfolio); | ||
| 51 | } | ||
| 52 | |||
| 53 | return $self; | ||
| 54 | } | ||
| 55 | |||
| 56 | =item C<< $manager->set_portfolio($portfolio) >> | ||
| 57 | |||
| 58 | Change the portfolio managed. | ||
| 59 | |||
| 60 | =cut | ||
| 61 | sub set_portfolio { | ||
| 62 | my ($self, $portfolio) = @_; | ||
| 63 | |||
| 64 | #WAR# WARN "portfolio is defined" if ( defined($portfolio)); | ||
| 65 | |||
| 66 | $self->{"portfolio"} = $portfolio; | ||
| 67 | |||
| 68 | return; | ||
| 69 | } | ||
| 70 | |||
| 71 | =item C<< $manager->portfolio() >> | ||
| 72 | |||
| 73 | Returns the managed portfolio. | ||
| 74 | |||
| 75 | =cut | ||
| 76 | sub portfolio { | ||
| 77 | my ($self) = @_; | ||
| 78 | return $self->{'portfolio'}; | ||
| 79 | } | ||
| 80 | |||
| 81 | =item C<< $order = $manager->buy_market_price($calc, $source) >> | ||
| 82 | |||
| 83 | =item C<< $order = $manager->buy_limited_price($calc, $source, $price) >> | ||
| 84 | |||
| 85 | =item C<< $order = $manager->buy_conditional($calc, $source, $price [, $price2]) >> | ||
| 86 | |||
| 87 | =item C<< $order = $manager->virtual_buy_at_open($calc, $source) >> | ||
| 88 | |||
| 89 | =item C<< $order = $manager->virtual_buy_at_high($calc, $source) >> | ||
| 90 | |||
| 91 | =item C<< $order = $manager->virtual_buy_at_low($calc, $source) >> | ||
| 92 | |||
| 93 | =item C<< $order = $manager->virtual_buy_at_close($calc, $source) >> | ||
| 94 | |||
| 95 | =item C<< $order = $manager->virtual_buy_at_signal($calc, $source) >> | ||
| 96 | |||
| 97 | =item C<< $order = $manager->sell_market_price($calc, $source) >> | ||
| 98 | |||
| 99 | =item C<< $order = $manager->sell_limited_price($calc, $source, $price) >> | ||
| 100 | |||
| 101 | =item C<< $order = $manager->sell_conditional($calc, $source, $price [, $price2]) >> | ||
| 102 | |||
| 103 | =item C<< $order = $manager->virtual_sell_at_open($calc, $source) >> | ||
| 104 | |||
| 105 | =item C<< $order = $manager->virtual_sell_at_high($calc, $source) >> | ||
| 106 | |||
| 107 | =item C<< $order = $manager->virtual_sell_at_low($calc, $source) >> | ||
| 108 | |||
| 109 | =item C<< $order = $manager->virtual_sell_at_close($calc, $source) >> | ||
| 110 | |||
| 111 | =item C<< $order = $manager->virtual_sell_at_signal($calc, $source) >> | ||
| 112 | |||
| 113 | Those functions are used to create orders that may be modified | ||
| 114 | and submitted later. | ||
| 115 | |||
| 116 | =cut | ||
| 117 | |||
| 118 | # TODO | ||
| 119 | # put an indicatory price to allow money management to decide of | ||
| 120 | # quantity | ||
| 121 | |||
| 122 | sub buy_market_price { | ||
| 123 | my ($self, $calc, $source) = @_; | ||
| 124 | |||
| 125 | my $order = Finance::GeniusTrader::Portfolio::Order->new; | ||
| 126 | $order->set_buy_order; | ||
| 127 | $order->set_type_market_price; | ||
| 128 | $order->set_code($calc->code); | ||
| 129 | $order->set_source($source); | ||
| 130 | return $order; | ||
| 131 | } | ||
| 132 | |||
| 133 | sub buy_limited_price { | ||
| 134 | my ($self, $calc, $source, $price) = @_; | ||
| 135 | |||
| 136 | my $order = Finance::GeniusTrader::Portfolio::Order->new; | ||
| 137 | $order->set_buy_order; | ||
| 138 | $order->set_type_limited; | ||
| 139 | $order->set_code($calc->code); | ||
| 140 | $order->set_source($source); | ||
| 141 | $order->set_price($price); | ||
| 142 | return $order; | ||
| 143 | } | ||
| 144 | |||
| 145 | sub buy_conditional { | ||
| 146 | my ($self, $calc, $source, $price, $price2) = @_; | ||
| 147 | |||
| 148 | my $order = Finance::GeniusTrader::Portfolio::Order->new; | ||
| 149 | $order->set_buy_order; | ||
| 150 | $order->set_code($calc->code); | ||
| 151 | $order->set_source($source); | ||
| 152 | $order->set_price($price); | ||
| 153 | |||
| 154 | if (defined($price2)) { | ||
| 155 | $order->set_type_stop_limited; | ||
| 156 | $order->set_second_price($price2); | ||
| 157 | } else { | ||
| 158 | $order->set_type_stop; | ||
| 159 | } | ||
| 160 | return $order; | ||
| 161 | } | ||
| 162 | |||
| 163 | sub virtual_buy_at_open { | ||
| 164 | my ($self, $calc, $source) = @_; | ||
| 165 | |||
| 166 | my $order = Finance::GeniusTrader::Portfolio::Order->new; | ||
| 167 | $order->set_buy_order; | ||
| 168 | $order->set_type_theoric_at_open; | ||
| 169 | $order->set_code($calc->code); | ||
| 170 | $order->set_source($source); | ||
| 171 | return $order; | ||
| 172 | } | ||
| 173 | |||
| 174 | sub virtual_buy_at_high { | ||
| 175 | my ($self, $calc, $source) = @_; | ||
| 176 | |||
| 177 | my $order = Finance::GeniusTrader::Portfolio::Order->new; | ||
| 178 | $order->set_buy_order; | ||
| 179 | $order->set_type_theoric_at_high; | ||
| 180 | $order->set_code($calc->code); | ||
| 181 | $order->set_source($source); | ||
| 182 | return $order; | ||
| 183 | } | ||
| 184 | |||
| 185 | sub virtual_buy_at_low { | ||
| 186 | my ($self, $calc, $source) = @_; | ||
| 187 | |||
| 188 | my $order = Finance::GeniusTrader::Portfolio::Order->new; | ||
| 189 | $order->set_buy_order; | ||
| 190 | $order->set_type_theoric_at_low; | ||
| 191 | $order->set_code($calc->code); | ||
| 192 | $order->set_source($source); | ||
| 193 | return $order; | ||
| 194 | } | ||
| 195 | |||
| 196 | sub virtual_buy_at_close { | ||
| 197 | my ($self, $calc, $source) = @_; | ||
| 198 | |||
| 199 | my $order = Finance::GeniusTrader::Portfolio::Order->new; | ||
| 200 | $order->set_buy_order; | ||
| 201 | $order->set_type_theoric_at_close; | ||
| 202 | $order->set_code($calc->code); | ||
| 203 | $order->set_source($source); | ||
| 204 | return $order; | ||
| 205 | } | ||
| 206 | |||
| 207 | sub virtual_buy_at_signal { | ||
| 208 | my ($self, $calc, $source) = @_; | ||
| 209 | |||
| 210 | my $order = Finance::GeniusTrader::Portfolio::Order->new; | ||
| 211 | $order->set_buy_order; | ||
| 212 | $order->set_type_theoric_at_signal; | ||
| 213 | $order->set_code($calc->code); | ||
| 214 | $order->set_source($source); | ||
| 215 | return $order; | ||
| 216 | } | ||
| 217 | |||
| 218 | sub sell_market_price { | ||
| 219 | my ($self, $calc, $source) = @_; | ||
| 220 | |||
| 221 | my $order = Finance::GeniusTrader::Portfolio::Order->new; | ||
| 222 | $order->set_sell_order; | ||
| 223 | $order->set_type_market_price; | ||
| 224 | $order->set_code($calc->code); | ||
| 225 | $order->set_source($source); | ||
| 226 | return $order; | ||
| 227 | } | ||
| 228 | |||
| 229 | sub sell_limited_price { | ||
| 230 | my ($self, $calc, $source, $price) = @_; | ||
| 231 | |||
| 232 | my $order = Finance::GeniusTrader::Portfolio::Order->new; | ||
| 233 | $order->set_sell_order; | ||
| 234 | $order->set_type_limited; | ||
| 235 | $order->set_code($calc->code); | ||
| 236 | $order->set_source($source); | ||
| 237 | $order->set_price($price); | ||
| 238 | return $order; | ||
| 239 | } | ||
| 240 | |||
| 241 | sub sell_conditional { | ||
| 242 | my ($self, $calc, $source, $price, $price2) = @_; | ||
| 243 | |||
| 244 | my $order = Finance::GeniusTrader::Portfolio::Order->new; | ||
| 245 | $order->set_sell_order; | ||
| 246 | $order->set_code($calc->code); | ||
| 247 | $order->set_source($source); | ||
| 248 | $order->set_price($price); | ||
| 249 | |||
| 250 | if (defined($price2)) { | ||
| 251 | $order->set_type_stop_limited; | ||
| 252 | $order->set_second_price($price2); | ||
| 253 | } else { | ||
| 254 | $order->set_type_stop; | ||
| 255 | } | ||
| 256 | return $order; | ||
| 257 | } | ||
| 258 | |||
| 259 | sub virtual_sell_at_open { | ||
| 260 | my ($self, $calc, $source) = @_; | ||
| 261 | |||
| 262 | my $order = Finance::GeniusTrader::Portfolio::Order->new; | ||
| 263 | $order->set_sell_order; | ||
| 264 | $order->set_type_theoric_at_open; | ||
| 265 | $order->set_code($calc->code); | ||
| 266 | $order->set_source($source); | ||
| 267 | return $order; | ||
| 268 | } | ||
| 269 | |||
| 270 | sub virtual_sell_at_high { | ||
| 271 | my ($self, $calc, $source) = @_; | ||
| 272 | |||
| 273 | my $order = Finance::GeniusTrader::Portfolio::Order->new; | ||
| 274 | $order->set_sell_order; | ||
| 275 | $order->set_type_theoric_at_high; | ||
| 276 | $order->set_code($calc->code); | ||
| 277 | $order->set_source($source); | ||
| 278 | return $order; | ||
| 279 | } | ||
| 280 | |||
| 281 | sub virtual_sell_at_low { | ||
| 282 | my ($self, $calc, $source) = @_; | ||
| 283 | |||
| 284 | my $order = Finance::GeniusTrader::Portfolio::Order->new; | ||
| 285 | $order->set_sell_order; | ||
| 286 | $order->set_type_theoric_at_low; | ||
| 287 | $order->set_code($calc->code); | ||
| 288 | $order->set_source($source); | ||
| 289 | return $order; | ||
| 290 | } | ||
| 291 | |||
| 292 | sub virtual_sell_at_close { | ||
| 293 | my ($self, $calc, $source) = @_; | ||
| 294 | |||
| 295 | my $order = Finance::GeniusTrader::Portfolio::Order->new; | ||
| 296 | $order->set_sell_order; | ||
| 297 | $order->set_type_theoric_at_close; | ||
| 298 | $order->set_code($calc->code); | ||
| 299 | $order->set_source($source); | ||
| 300 | return $order; | ||
| 301 | } | ||
| 302 | |||
| 303 | sub virtual_sell_at_signal { | ||
| 304 | my ($self, $calc, $source) = @_; | ||
| 305 | |||
| 306 | my $order = Finance::GeniusTrader::Portfolio::Order->new; | ||
| 307 | $order->set_sell_order; | ||
| 308 | $order->set_type_theoric_at_signal; | ||
| 309 | $order->set_code($calc->code); | ||
| 310 | $order->set_source($source); | ||
| 311 | return $order; | ||
| 312 | } | ||
| 313 | |||
| 314 | =item C<< $manager->set_order_partial($order, $ratio) >> | ||
| 315 | |||
| 316 | When you want to close a position, you may want to not close it | ||
| 317 | fully. With this function, you indicate how much of the initial position | ||
| 318 | you want to close. | ||
| 319 | |||
| 320 | =cut | ||
| 321 | sub set_order_partial { | ||
| 322 | my ($self, $order, $ratio, $position) = @_; | ||
| 323 | |||
| 324 | #WAR# WARN "ratio is positive" if ( $ratio > 0); | ||
| 325 | #WAR# WARN "order is defined" if ( defined($order)); | ||
| 326 | #WAR# WARN "position is defined" if ( defined($position)); | ||
| 327 | |||
| 328 | my $init_quant = defined($position->initial_quantity) ? | ||
| 329 | $position->initial_quantity : | ||
| 330 | $position->quantity; | ||
| 331 | $order->{'quantity'} = int($init_quant * $ratio); | ||
| 332 | |||
| 333 | #WAR# WARN "order quantity is positive" if ( $order->quantity > 0); | ||
| 334 | |||
| 335 | return $order; | ||
| 336 | } | ||
| 337 | |||
| 338 | =item C<< $manager->discard_all_orders($calc, $source) >> | ||
| 339 | |||
| 340 | Discards all orders concerning this share and this source. | ||
| 341 | |||
| 342 | =cut | ||
| 343 | sub discard_all_orders { | ||
| 344 | my ($self, $calc, $source) = @_; | ||
| 345 | |||
| 346 | foreach (grep { $_->code eq $calc->code } | ||
| 347 | $self->{'portfolio'}->list_pending_orders($source)) | ||
| 348 | { | ||
| 349 | $self->{'portfolio'}->discard_order($_->{'id'}); | ||
| 350 | } | ||
| 351 | return; | ||
| 352 | } | ||
| 353 | |||
| 354 | =item C<< $manager->submit_order($order, $i, $calc) >> | ||
| 355 | |||
| 356 | =item C<< $manager->submit_order_in_position($position, $order, $i, $calc) >> | ||
| 357 | |||
| 358 | Submit the prepared order, either an order that will start a new position | ||
| 359 | or as an order that will modify an existing position. | ||
| 360 | |||
| 361 | =cut | ||
| 362 | sub submit_order { | ||
| 363 | my ($self, $order, $i, $calc) = @_; | ||
| 364 | |||
| 365 | #WAR# WARN "order is defined" if ( defined($order)); | ||
| 366 | #WAR# WARN "day number $i is valid" if ( $i >= 0); | ||
| 367 | #WAR# WARN "calc is defined" if ( defined($calc)); | ||
| 368 | |||
| 369 | $order->set_timeframe($calc->current_timeframe); | ||
| 370 | |||
| 371 | # Short positions only possible with marged positions | ||
| 372 | $order->set_marged if ($order->is_sell_order); | ||
| 373 | |||
| 374 | if (! defined($order->quantity)) { | ||
| 375 | if (! $self->decide_quantity($order, $i, $calc)) | ||
| 376 | { | ||
| 377 | # Trade refused by money management | ||
| 378 | return 0; | ||
| 379 | } | ||
| 380 | } | ||
| 381 | |||
| 382 | #WAR# WARN "order quantity is positive" if ( $order->quantity > 0); | ||
| 383 | |||
| 384 | # TODO | ||
| 385 | # Update other fields of the order like dates and so on | ||
| 386 | $self->{'portfolio'}->add_order($order); | ||
| 387 | return 1; | ||
| 388 | } | ||
| 389 | |||
| 390 | sub submit_order_in_position { | ||
| 391 | my ($self, $position, $order, $i, $calc) = @_; | ||
| 392 | |||
| 393 | #WAR# WARN "order is defined" if ( defined($order)); | ||
| 394 | #WAR# WARN "day number $i is valid" if ( $i >= 0); | ||
| 395 | #WAR# WARN "calc is defined" if ( defined($calc)); | ||
| 396 | #WAR# WARN "position quantity is positive" if ( $position->quantity > 0); | ||
| 397 | |||
| 398 | $order->set_timeframe($calc->current_timeframe); | ||
| 399 | |||
| 400 | $order->set_marged if ($position->is_marged); | ||
| 401 | |||
| 402 | if (! defined($order->quantity)) { | ||
| 403 | $order->set_quantity($position->quantity); | ||
| 404 | } | ||
| 405 | |||
| 406 | #WAR# WARN "order quantity is positive" if ( $order->quantity > 0); | ||
| 407 | |||
| 408 | # Mark the position as being closed | ||
| 409 | if ($order->quantity == $position->quantity) | ||
| 410 | { | ||
| 411 | if ($position->is_long) | ||
| 412 | { | ||
| 413 | if ($order->is_sell_order) | ||
| 414 | { | ||
| 415 | $position->set_intent_to_close; | ||
| 416 | } | ||
| 417 | } else { | ||
| 418 | if ($order->is_buy_order) | ||
| 419 | { | ||
| 420 | $position->set_intent_to_close; | ||
| 421 | } | ||
| 422 | } | ||
| 423 | } | ||
| 424 | |||
| 425 | # TODO | ||
| 426 | # Update other fields of the order like dates and so on | ||
| 427 | $position->add_order($order); | ||
| 428 | return; | ||
| 429 | } | ||
| 430 | |||
| 431 | |||
| 432 | sub park_order { | ||
| 433 | my ($self, $order, $i, $calc) = @_; | ||
| 434 | |||
| 435 | #WAR# WARN "order is defined" unless (defined($order)); | ||
| 436 | #WAR# WARN "day number $i is valid" unless ($i >= 0); | ||
| 437 | #WAR# WARN "calc is defined" unless (defined($calc)); | ||
| 438 | |||
| 439 | $order->set_timeframe($calc->current_timeframe); | ||
| 440 | |||
| 441 | # Short positions only possible with marged positions | ||
| 442 | $order->set_marged if ($order->is_sell_order); | ||
| 443 | |||
| 444 | push @{$self->{'portfolio'}->{'parked-orders'}}, | ||
| 445 | [$order, $i, $calc ]; | ||
| 446 | |||
| 447 | return 1; | ||
| 448 | } | ||
| 449 | |||
| 450 | sub submit_parked_orders { | ||
| 451 | my $self = shift; | ||
| 452 | |||
| 453 | foreach my $p ( @{$self->{'portfolio'}->{'parked-orders'}} ) { | ||
| 454 | my $order = $p->[0]; | ||
| 455 | my $i = $p->[1]; | ||
| 456 | my $calc = $p->[2]; | ||
| 457 | |||
| 458 | # print $i . " --> " . $calc->code() . "\n"; | ||
| 459 | |||
| 460 | if (! defined($order->quantity)) { | ||
| 461 | if (! $self->decide_quantity($order, $i, $calc) ) | ||
| 462 | { | ||
| 463 | # Trade refused by money management | ||
| 464 | next; | ||
| 465 | } elsif (! defined($order->quantity)) { | ||
| 466 | next; | ||
| 467 | } | ||
| 468 | } | ||
| 469 | |||
| 470 | #WAR# warn "order quantity is positive " . $order->quantity if ($order->quantity > 0); | ||
| 471 | |||
| 472 | # TODO | ||
| 473 | # Update other fields of the order like dates and so on | ||
| 474 | $self->{'portfolio'}->add_order($order); | ||
| 475 | |||
| 476 | } | ||
| 477 | |||
| 478 | @{$self->{'portfolio'}->{'parked-orders'}} = (); | ||
| 479 | } | ||
| 480 | |||
| 481 | sub delete_parked_orders { | ||
| 482 | my $self = shift; | ||
| 483 | @{$self->{'portfolio'}->{'parked-orders'}} = (); | ||
| 484 | } | ||
| 485 | |||
| 486 | =item C<< $manager->add_money_management_rule($mm_rule) >> | ||
| 487 | |||
| 488 | =item C<< $manager->delete_all_money_management_rule() >> | ||
| 489 | |||
| 490 | =item C<< $manager->default_money_management_rule($mm_rule) >> | ||
| 491 | |||
| 492 | Use a money management rule and remove all money management | ||
| 493 | rules currently used. | ||
| 494 | |||
| 495 | =cut | ||
| 496 | sub add_money_management_rule { | ||
| 497 | my ($self, $mmrule) = @_; | ||
| 498 | |||
| 499 | push @{$self->{'moneymanagement'}}, $mmrule; | ||
| 500 | |||
| 501 | return; | ||
| 502 | } | ||
| 503 | sub delete_all_money_management_rule { | ||
| 504 | my ($self) = @_; | ||
| 505 | |||
| 506 | $self->{'moneymanagement'} = []; | ||
| 507 | |||
| 508 | return; | ||
| 509 | } | ||
| 510 | sub default_money_management_rule { | ||
| 511 | my ($self, $mmrule) = @_; | ||
| 512 | |||
| 513 | if (! scalar(@{$self->{'moneymanagement'}})) | ||
| 514 | { | ||
| 515 | push @{$self->{'moneymanagement'}}, $mmrule; | ||
| 516 | } | ||
| 517 | |||
| 518 | return; | ||
| 519 | } | ||
| 520 | |||
| 521 | =item C<< $manager->decide_quantity($order, $i, $calc) >> | ||
| 522 | |||
| 523 | Apply the various money management rules and decide the size | ||
| 524 | of the position. | ||
| 525 | |||
| 526 | =cut | ||
| 527 | sub decide_quantity { | ||
| 528 | my ($self, $order, $i, $calc) = @_; | ||
| 529 | |||
| 530 | foreach my $mm (@{$self->{'moneymanagement'}}) | ||
| 531 | { | ||
| 532 | my $nq = $mm->manage_quantity($order, $i, $calc, $self->{'portfolio'}); | ||
| 533 | $order->set_quantity($nq); | ||
| 534 | } | ||
| 535 | return $order->quantity; | ||
| 536 | } | ||
| 537 | |||
| 538 | =item C<< $manager->finalize() >> | ||
| 539 | |||
| 540 | Finalize the setup of the manager. Calculate its name. You can get its | ||
| 541 | name afterward using $manager->get_name. | ||
| 542 | |||
| 543 | =cut | ||
| 544 | sub finalize { | ||
| 545 | my ($self) = @_; | ||
| 546 | |||
| 547 | my $name = join "|", map { get_standard_name($_) } | ||
| 548 | @{$self->{'moneymanagement'}}; | ||
| 549 | $self->{'name'} = $name; | ||
| 550 | |||
| 551 | return $name; | ||
| 552 | } | ||
| 553 | |||
| 554 | =item C<< $manager->get_name() >> | ||
| 555 | |||
| 556 | Return the name of the system. | ||
| 557 | |||
| 558 | =cut | ||
| 559 | sub get_name { | ||
| 560 | my ($self) = @_; | ||
| 561 | #ERR# ERROR "name is defined" if ( defined($self->{'name'})); | ||
| 562 | return $self->{'name'}; | ||
| 563 | } | ||
| 564 | |||
| 565 | =item C<< $manager->setup_from_name($name) >> | ||
| 566 | |||
| 567 | Setup the portfolio manager according to the name, it will create the | ||
| 568 | corresponding money management rules. | ||
| 569 | |||
| 570 | =cut | ||
| 571 | sub setup_from_name { | ||
| 572 | my ($self, $name) = @_; | ||
| 573 | |||
| 574 | # Add all money management rules | ||
| 575 | foreach (split (/\|/, $name)) | ||
| 576 | { | ||
| 577 | s/^\s+//g; s/\s+$//g; | ||
| 578 | my ($obj_name, @args) = split /\s+/; | ||
| 579 | my $object = create_standard_object($obj_name, @args); | ||
| 580 | |||
| 581 | if (ref($object) =~ /MoneyManagement::/) { | ||
| 582 | $self->add_money_management_rule($object); | ||
| 583 | } | ||
| 584 | } | ||
| 585 | return; | ||
| 586 | } | ||
| 587 | |||
| 588 | =pod | ||
| 589 | |||
| 590 | =back | ||
| 591 | |||
| 592 | =cut | ||
| 593 | 1; |