public function testIsOutOfBalance()
 {
     $this->assertTrue($this->subclassCollection->isOutOfBalance());
     $this->subclassCollection->get(1)->setCurrentAllocation(30);
     $this->subclassCollection->get(2)->setCurrentAllocation(70);
     $this->assertFalse($this->subclassCollection->isOutOfBalance());
 }
Esempio n. 2
0
 /**
  * Get buy and sell limit
  * Returns max amount which can be sold and bought
  *
  * @param SubclassCollection $subclassCollection
  * @param Account $contextAccount
  * @return float
  */
 public function getBuyAndSellLimit(SubclassCollection $subclassCollection, Account $contextAccount = null)
 {
     $sellAmount = 0;
     $buyAmount = 0;
     if ($subclassCollection->isOutOfBalance()) {
         /** @var Subclass $subclass */
         foreach ($subclassCollection as $subclass) {
             if ($subclass->calcOOB() == 0) {
                 continue;
             }
             $amount = $subclassCollection->getOnePercentAmount() * abs($subclass->calcOOB());
             if ($subclass->calcOOB() > 0) {
                 if ($contextAccount) {
                     $sellAmount += $this->sellSubclass($subclass, $contextAccount, $amount, true);
                 } else {
                     $sellAmount += $this->sellSubclassHousehold($subclass, $amount, true);
                 }
             } elseif ($subclass->calcOOB() < 0) {
                 if ($contextAccount) {
                     $buyAmount += $this->buySubclass($subclass, $contextAccount, $amount, true);
                 } else {
                     $buyAmount += $this->buySubclassHousehold($subclass, $amount, true);
                 }
             }
         }
     }
     $result = min($sellAmount, $buyAmount);
     $this->logger->logInfo("Limit for buy and sell: {$result}.");
     return $result;
 }