Beispiel #1
0
 public function testSetSubclasses()
 {
     $subclassCollection = new SubclassCollection();
     $subclass1 = new Subclass();
     $subclass1->setId(45);
     $subclassCollection->add($subclass1);
     $subclass2 = new Subclass();
     $subclass2->setId(50);
     $subclassCollection->add($subclass2);
     $subclass3 = new Subclass();
     $subclass3->setId(55);
     $subclassCollection->add($subclass3);
     $this->assetClass->setSubclasses($subclassCollection);
     $subclasses = $this->assetClass->getSubclasses();
     $this->assertCount(3, $subclasses);
     $this->assertEquals(45, $subclasses[45]->getId());
     $this->assertEquals(50, $subclasses[50]->getId());
     $this->assertEquals(55, $subclasses[55]->getId());
 }
 public function testGetBuyAndSellLimitNotOutOfBalance()
 {
     $subclassesData = array(array('id' => 1, 'target_allocation' => 30, 'current_allocation' => 30, 'security' => array('id' => 1, 'amount' => 3000)), array('id' => 2, 'target_allocation' => 10, 'current_allocation' => 10, 'security' => array('id' => 2, 'amount' => 1000)), array('id' => 3, 'target_allocation' => 25, 'current_allocation' => 25, 'security' => array('id' => 3, 'amount' => 2500)), array('id' => 4, 'target_allocation' => 15, 'current_allocation' => 15, 'security' => array('id' => 4, 'amount' => 1500)), array('id' => 5, 'target_allocation' => 20, 'current_allocation' => 20, 'security' => array('id' => 5, 'amount' => 2000)));
     $subclassCollection = new SubclassCollection();
     foreach ($subclassesData as $data) {
         $subclass = $this->getMockSubclass($data);
         $subclassCollection->add($subclass);
     }
     $this->assertEquals(0, $this->rebalancer->getBuyAndSellLimit($subclassCollection));
 }
 /**
  * By required cash for client accounts
  */
 public function buyRequiredCash()
 {
     $client = $this->getClient();
     /** @var Account $account */
     foreach ($client->getAccounts() as $account) {
         $cashNeeds = $account->getTotalCashNeeds();
         if ($account->getIsReadyToRebalance() && $cashNeeds > 0) {
             $subclasses = new SubclassCollection();
             /** @var Security $security */
             foreach ($account->getSecurities() as $security) {
                 $subclasses->add($security->getSubclass());
             }
             $oobSubclasses = $subclasses->sortByOob();
             $subclassToSell = $oobSubclasses->first();
             $needToBuy = $cashNeeds;
             while ($needToBuy > 0 && $subclassToSell) {
                 $sellAmount = $this->sellSubclass($subclassToSell, $account, $needToBuy, false);
                 $needToBuy -= $sellAmount;
                 $account->setTotalCash($sellAmount + $account->getTotalCash());
                 $subclassToSell = $oobSubclasses->next();
             }
         }
         $account->updateCashForBuy();
     }
 }
 protected function bindSubclassCollection(array $data, SecurityCollection $securityCollection)
 {
     $subclassCollection = new SubclassCollection();
     foreach ($data as $values) {
         $subclass = new Subclass();
         $subclass->loadFromArray($values);
         /** @var Security $security */
         $security = $securityCollection->get($values['security_id']);
         $security->setSubclass($subclass);
         $subclass->setSecurity($security);
         if (isset($values['muni_substitution_id']) && $values['muni_substitution_id']) {
             $sql = "SELECT sp.price FROM " . self::TABLE_SECURITY_PRICE . " sp\n                        WHERE sp.is_current = true AND sp.security_id = :security_id\n                          ORDER BY sp.datetime DESC\n                          LIMIT 1\n                        ";
             $parameters = array('security_id' => $values['muni_substitution_id']);
             $securityPriceData = $this->db->query($sql, $parameters);
             $muni = new Security();
             $muni->setId($values['muni_substitution_id']);
             $muni->setSubclass($subclass);
             $muni->setIsPreferredBuy(true);
             $muni->setName($values['muni_name']);
             $muni->setSymbol($values['muni_symbol']);
             $muni->setPrice($securityPriceData[0]['price']);
             $subclass->setMuniSecurity($muni);
         }
         $subclassCollection->add($subclass);
     }
     return $subclassCollection;
 }