Пример #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());
 }
Пример #2
0
 private function checkCollection(SubclassCollection $subclassCollection, array $subclassesData)
 {
     $subclass = $subclassCollection->first();
     $this->assertCount(count($subclassesData), $subclassCollection);
     /** @var Subclass $subclass */
     foreach ($subclassesData as $subclassData) {
         $security = $subclass->getSecurity();
         $muniSecurity = $subclass->getMuniSecurity();
         $this->assertEquals($subclassData['security']['symbol'], $security->getSymbol());
         $this->assertEquals($subclassData['target_allocation'], $subclass->getTargetAllocation());
         $this->assertEquals($subclassData['security']['amount'], $security->getAmount());
         $this->assertEquals($subclassData['security']['qty'], $security->getQty());
         $this->assertEquals($subclassData['tolerance_band'], $subclass->getToleranceBand());
         if ($subclassData['muni_security']) {
             $this->assertEquals($subclassData['muni_security']['name'], $muniSecurity->getName());
             $this->assertEquals($subclassData['muni_security']['symbol'], $muniSecurity->getSymbol());
             $this->assertEquals($subclassData['muni_security']['qty'], $muniSecurity->getQty());
             $this->assertEquals($subclassData['muni_security']['amount'], $muniSecurity->getAmount());
         }
         $subclass = $subclassCollection->next();
     }
 }
Пример #3
0
 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));
 }
Пример #4
0
 /**
  * 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();
     }
 }
Пример #5
0
 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;
 }
Пример #6
0
 public function testGetOnePercentAmount()
 {
     $this->assertEquals(150, $this->subclassCollection->getOnePercentAmount());
 }