Exemple #1
0
 public function testSetTaxLossHarvesting()
 {
     $taxLossHarvesting = new Security();
     $taxLossHarvesting->setId(12);
     $this->subclass->setTaxLossHarvesting($taxLossHarvesting);
     $this->assertEquals(12, $this->subclass->getTaxLossHarvesting()->getId());
 }
 /**
  * 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);
     }
 }