Exemplo n.º 1
0
 public function testSetSecurity()
 {
     $security = new Security();
     $security->setId(11);
     $this->subclass->setSecurity($security);
     $this->assertEquals(11, $this->subclass->getSecurity()->getId());
 }
Exemplo n.º 2
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;
 }
Exemplo n.º 3
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);
     }
 }