Esempio n. 1
0
 public function testSetSubclass()
 {
     $newSubclass = new Subclass();
     $newSubclass->setId(1414);
     $this->queueItem->setSubclass($newSubclass);
     $this->assertEquals(1414, $this->queueItem->getSubclass()->getId());
 }
Esempio n. 2
0
 public function testSetSubclass()
 {
     $subclass = new Subclass();
     $subclass->setId(14);
     $this->security->setSubclass($subclass);
     $this->assertEquals(14, $this->security->getSubclass()->getId());
 }
Esempio n. 3
0
 public function findLotsBySubclass(Portfolio $portfolio, Subclass $subclass, Account $account = null)
 {
     $positions = $this->getPositionsByPortfolio($portfolio, $account, $subclass->getSecurity());
     $lotCollection = new LotCollection();
     foreach ($positions as $position) {
         $lots = $this->getLastPositionLots($portfolio, $position['security_id'], $position['client_system_account_id']);
         foreach ($lots as $lot) {
             $lotCollection->add($lot);
         }
         if ($position['muni_id']) {
             $muniLots = $this->getLastPositionLots($portfolio, $position['muni_id'], $position['client_system_account_id'], true);
             foreach ($muniLots as $muniLot) {
                 $lotCollection->add($muniLot);
             }
         }
     }
     return $lotCollection;
 }
Esempio n. 4
0
 public function testGetTotalAmount()
 {
     $this->assertEquals(1500, $this->subclass->getTotalAmount());
     /** @var Subclass $emptySubclass */
     $emptySubclass = $this->getMock('Model\\WealthbotRebalancer\\Subclass', null);
     $this->assertEquals(0, $emptySubclass->getTotalAmount());
     /** @var Subclass $subclassWithSecurity */
     $subclassWithSecurity = $this->getMock('Model\\WealthbotRebalancer\\Subclass', null);
     $security = new Security();
     $security->setAmount(200);
     $subclassWithSecurity->setSecurity($security);
     $this->assertEquals(200, $subclassWithSecurity->getTotalAmount());
     /** @var Subclass $subclassWithMuni */
     $subclassWithMuni = $this->getMock('Model\\WealthbotRebalancer\\Subclass', null);
     $muni = new Security();
     $muni->setAmount(722);
     $subclassWithMuni->setMuniSecurity($muni);
     $this->assertEquals(722, $subclassWithMuni->getTotalAmount());
 }
Esempio n. 5
0
 public function testAddSubclass()
 {
     $newSubclass = new Subclass();
     $newSubclass->setId(56);
     $this->assetClass->addSubclass($newSubclass);
     $subclasses = $this->assetClass->getSubclasses();
     $this->assertCount(3, $subclasses);
     $this->assertEquals(79, $subclasses[79]->getId());
     $this->assertEquals(100, $subclasses[100]->getId());
     $this->assertEquals(56, $subclasses[56]->getId());
 }
Esempio n. 6
0
 /**
  * Check Tax Loss Harvesting
  * 6.C step in spec
  *
  * @param Account $account
  * @param Subclass $subclass
  * @return boolean
  */
 public function checkTlh(Account $account, Subclass $subclass)
 {
     $client = $account->getClient();
     $ria = $client->getRia();
     /** @var LotRepository $lotRepository */
     $lotRepository = $this->getRepository('Lot');
     /** @var ClientRepository $clientRepository */
     $clientRepository = $this->getRepository('Client');
     $clientRepository->loadStopTlhValue($client);
     $date = new \DateTime();
     $clientLossesSum = $lotRepository->getClientLossesSumForYear($client, $date->format('Y'));
     if ($ria->getIsTlhEnabled() && $client->canUseTlh() && $account->isTaxable() && $subclass->hasTlhFund() && abs($clientLossesSum) >= $client->getStopTlhValue()) {
         $lots = $lotRepository->findLotsByAccountAndSecurity($account, $subclass->getSecurity());
         $amount = 0;
         /** @var Lot $lot */
         foreach ($lots as $lot) {
             $loss = $lot->getRealizedGainOrLoss();
             $lossPercent = round(($lot->getAmount() - $lot->getCostBasis()) / $lot->getAmount(), 2);
             if ($loss < 0 && abs($loss) >= $ria->getMinTlh() && abs($lossPercent) >= $ria->getMinTlhPercent()) {
                 $amount += $this->sellLot($lot, $subclass->getSecurity(), $account, $lot->getAmount());
             }
         }
         $this->buySecurity($subclass->getTaxLossHarvesting(), $account, $amount);
     }
 }
Esempio n. 7
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;
 }