public function testGetAccountForBuySubclassTraditionalIRA()
 {
     /** @var Subclass $subclass */
     $subclass = $this->getMock('Model\\WealthbotRebalancer\\Subclass', null);
     $subclass->setAccountType(Subclass::ACCOUNT_TYPE_TRADITIONAL_IRA);
     $security = $this->getMock('Model\\WealthbotRebalancer\\Security', null);
     $security->setId(2);
     $subclass->setSecurity($security);
     $account = $this->collection->getAccountForBuySubclass($subclass);
     $this->assertEquals(4, $account->getId());
 }
示例#2
0
 public function getAccountsByRebalancerAction(RebalancerAction $rebalancerAction)
 {
     $client = $rebalancerAction->getClient();
     if ($client->isHouseholdLevelRebalancer()) {
         $collection = $this->findClientAccounts($client);
     } else {
         $account = $this->findAccountById($rebalancerAction->getAccountId());
         $account->setClient($client);
         $collection = new AccountCollection();
         $collection->add($account);
     }
     return $collection;
 }
 public function testBuyRequiredCash()
 {
     $securityCollection1 = new SecurityCollection();
     $securityCollection2 = new SecurityCollection();
     $subclass1 = $this->getMockSubclass(array('id' => 1, 'current_allocation' => 5, 'target_allocation' => 20));
     $security1 = $this->getMockSecurity(array('id' => 1, 'amount' => 1000, 'qty' => 100, 'name' => 'Security1', 'symbol' => 'Sec1'));
     $subclass2 = $this->getMockSubclass(array('id' => 2, 'current_allocation' => 25, 'target_allocation' => 45));
     $security2 = $this->getMockSecurity(array('id' => 2, 'amount' => 5000, 'qty' => 10, 'name' => 'Security2', 'symbol' => 'Sec2'));
     $subclass3 = $this->getMockSubclass(array('id' => 3, 'current_allocation' => 70, 'target_allocation' => 35));
     $security3 = $this->getMockSecurity(array('id' => 5, 'amount' => 14000, 'qty' => 20, 'name' => 'Security3', 'symbol' => 'Sec3'));
     $security1->setSubclass($subclass1);
     $subclass1->setSecurity($security1);
     $security2->setSubclass($subclass2);
     $subclass2->setSecurity($security2);
     $security3->setSubclass($subclass3);
     $subclass3->setSecurity($security3);
     $securityCollection1->add($security1);
     $securityCollection1->add($security2);
     $securityCollection2->add($security3);
     $lotsData = array(array('id' => 1, 'is_muni' => false, 'quantity' => 100, 'amount' => 1000, 'status' => Lot::LOT_IS_OPEN, 'security' => $security1, 'date' => '2012-01-01', 'initial' => array('id' => 1, 'date' => '2012-01-01')), array('id' => 2, 'is_muni' => false, 'quantity' => 10, 'amount' => 5000, 'status' => Lot::LOT_IS_OPEN, 'security' => $security2, 'date' => '2012-01-01', 'initial' => array('id' => 1, 'date' => '2012-01-01')), array('id' => 3, 'is_muni' => false, 'quantity' => 20, 'amount' => 14000, 'status' => Lot::LOT_IS_OPEN, 'security' => $security3, 'date' => '2012-01-01', 'initial' => array('id' => 1, 'date' => '2012-01-01')));
     $lots = [];
     foreach ($lotsData as $key => $data) {
         /** @var Lot $lot */
         $lot = $this->getMock('Model\\WealthbotRebalancer\\Lot', null);
         $lot->loadFromArray($data);
         $lots[$key + 1] = $lot;
     }
     $accountsData = array(array('id' => 1, 'is_ready_to_rebalance' => true, 'total_cash' => 100000, 'cash_buffer' => 2000, 'sas_cash' => 1000, 'billing_cash' => 500, 'scheduled_distribution' => 2300, 'one_time_distribution' => 0, 'client' => array('portfolio' => array('id' => 1), 'ria' => array('ria_company_information' => array('use_transaction_fees' => true, 'transaction_min_amount' => 400, 'transaction_min_amount_percent' => 1.5)))), array('id' => 2, 'is_ready_to_rebalance' => true, 'total_cash' => 150000, 'cash_buffer' => 1000, 'sas_cash' => 300, 'billing_cash' => 100, 'scheduled_distribution' => 0, 'one_time_distribution' => 2400, 'client' => array('portfolio' => array('id' => 1), 'ria' => array('ria_company_information' => array('use_transaction_fees' => true, 'transaction_min_amount' => 400, 'transaction_min_amount_percent' => 1.5)))));
     $accountCollection = new AccountCollection();
     foreach ($accountsData as $key => $data) {
         /** @var Account $account */
         $account = $this->getMock('Model\\WealthbotRebalancer\\Account', null);
         $account->loadFromArray($data);
         $securityCollectionVar = 'securityCollection' . ($key + 1);
         $account->setSecurities(${$securityCollectionVar});
         $accountCollection->add($account);
     }
     $client = $this->getMockClient(array('portfolio' => array('id' => 1)));
     $client->setAccounts($accountCollection);
     $lotRepository = $this->getMockLotRepository(array('findOrderedLots'));
     $lotRepository->expects($this->any())->method('findOrderedLots')->will($this->returnCallback(function (Security $security) use($lots) {
         $lotCollection = new LotCollection();
         $lotCollection->add($lots[$security->getSubclass()->getId()]);
         return $lotCollection;
     }));
     $securityTransactionRepository = $this->getMockSecurityTransactionRepository(array('findOneByPortfolioAndSecurity'));
     /** @var WealthbotRebalancer $rebalancer */
     $rebalancer = $this->getMockWealthbotRebalancer(array('getRepository', 'getJob', 'getClient', 'checkShortTermRedemption', 'checkTransaction', 'getRebalancerAction'), false);
     $rebalancer->expects($this->any())->method('getRepository')->will($this->returnCallback(function ($repositoryName) use($lotRepository, $securityTransactionRepository) {
         if ($repositoryName === 'Lot') {
             return $lotRepository;
         } elseif ($repositoryName === 'SecurityTransaction') {
             return $securityTransactionRepository;
         }
         return null;
     }));
     $rebalancer->expects($this->any())->method('getJob')->will($this->returnValue($this->getMockJob(array('id' => 1))));
     $rebalancer->expects($this->any())->method('getClient')->will($this->returnValue($client));
     $rebalancer->expects($this->any())->method('checkShortTermRedemption')->will($this->returnValue(true));
     $rebalancer->expects($this->any())->method('getRebalancerAction')->will($this->returnValue($this->getMockRebalancerAction(array('id' => 2))));
     $rebalancer->buyRequiredCash();
     $queue = $rebalancer->getRebalancerQueue();
     $this->assertCount(3, $queue);
     $item1 = $queue[0];
     $this->assertEquals('Sec1', $item1->getSecurity()->getSymbol());
     $this->assertEquals(100, $item1->getQuantity());
     $this->assertEquals(0, $item1->getSecurity()->getQty());
     $item2 = $queue[1];
     $this->assertEquals('Sec2', $item2->getSecurity()->getSymbol());
     $this->assertEquals(8, $item2->getQuantity());
     $this->assertEquals(2, $item2->getSecurity()->getQty());
     $item3 = $queue[2];
     $this->assertEquals('Sec3', $item3->getSecurity()->getSymbol());
     $this->assertEquals(4, $item3->getQuantity());
     $this->assertEquals(16, $item3->getSecurity()->getQty());
     $this->assertEquals(6000, $accountCollection->get(1)->getTotalCash());
     $this->assertEquals(4300, $accountCollection->get(2)->getTotalCash());
 }