/** * @param SystemClientAccountModel $account */ public function calculateValue(SystemClientAccountModel $account) { $todayDate = $this->getCurDate(); $yesterdayDate = $this->getModifyDate('-1 day'); // Get today account value $todayValue = $this->accountValueRepo->getTodayValue($account->getId(), $todayDate); // Get yesterday account value $yesterdayValue = $this->accountValueRepo->getYesterdayValue($account->getId(), $todayDate); // Calculate NET Cash Flow $yesterdayNetCashFlow = Functions::calculateCashFlow($this->transactionRepo->sumContribution($account->getId(), $yesterdayDate), $this->transactionRepo->sumWithdrawal($account->getId(), $yesterdayDate, TransactionRepo::AMOUNT_TYPE_NET)); // Calculate today NET TWR $todayNetTWR = Functions::calculateTodayTwr($todayValue, $yesterdayNetCashFlow, $yesterdayValue); // Calculate GROSS Cash Flow $yesterdayGrossCashFlow = Functions::calculateCashFlow($this->transactionRepo->sumContribution($account->getId(), $yesterdayDate), $this->transactionRepo->sumWithdrawal($account->getId(), $yesterdayDate, TransactionRepo::AMOUNT_TYPE_GROSS)); // Calculate today GROSS TWR $todayGrossTWR = Functions::calculateTodayTwr($todayValue, $yesterdayGrossCashFlow, $yesterdayValue); $model = new AccountTwrValueModel(); $model->setDate($todayDate->format('Y-m-d')); $model->setNetValue($todayNetTWR); $model->setGrossValue($todayGrossTWR); $model->setAccountNumber($account->getAccountNumber()); // Save today TWR value $this->valueRepo->save($model); Factory::get($account->getClientId())->addTodayValue($todayValue); Factory::get($account->getClientId())->addYesterdayValue($yesterdayValue); Factory::get($account->getClientId())->addYesterdayNetCashFlow($yesterdayNetCashFlow); Factory::get($account->getClientId())->addYesterdayGrossCashFlow($yesterdayGrossCashFlow); }
/** * @param SystemClientAccountModel $account * @param array $data */ public function process(SystemClientAccountModel $account, array $data) { $lots = $this->lotRepo->findAllClosedBy(array('date' => $data['close_date'], 'quantity' => $data['shares_sold'], 'account_id' => $account->getId())); foreach ($lots as $lot) { $realizedGain = (int) $lot->getRealizedGain(); $realizedGainST = (int) $data['st_gain_loss']; $realizedGainLT = (int) $data['lt_gain_loss']; if ($realizedGain < 0) { $status = $realizedGainST == abs($realizedGain) ? DocumentRealizedRepo::STATUS_MATCH : DocumentRealizedRepo::STATUS_NOT_MATCH; } else { $status = $realizedGainLT == abs($realizedGain) ? DocumentRealizedRepo::STATUS_MATCH : DocumentRealizedRepo::STATUS_NOT_MATCH; } $this->docRelizedRepo->changeStatusById($data['_id'], $status); } }
/** * @param SystemClientAccountModel $account * @param array $data */ public function process(SystemClientAccountModel $account, array $data) { foreach ($data as $row) { if (null == ($security = $this->securityRepo->findOneBySymbol($row['symbol']))) { $this->docUnrealizedRepo->changeStatusById($row['_id'], DocumentBaseRepo::STATUS_NOT_POSTED); continue; } $lot = $this->lotRepo->findOneBy(array('status' => WealthbotLot::LOT_INITIAL, 'quantity' => $row['current_qty'], 'security_id' => $security->getId(), 'client_system_account_id' => $account->getId())); if (null == $lot) { $this->docUnrealizedRepo->changeStatusById($row['_id'], DocumentBaseRepo::STATUS_NOT_POSTED); continue; } $this->docUnrealizedRepo->update($row['_id'], array('status' => DocumentBaseRepo::STATUS_POSTED, 'lot_date' => $lot->getDate(), 'lot_amount' => $lot->getAmount(), 'lot_quantity' => $lot->getQuantity())); } }
/** * @param SystemClientAccountModel $account * @param SecurityModel $security * @param array $data * @return mixed */ public function process(SystemClientAccountModel $account, SecurityModel $security, array $data) { $model = new LotModel(); $model->setSymbol($data['symbol']); $model->setTransactionCode($data['transaction_code']); $model->setInitialLotId(null); $model->setQuantity($data['qty']); $model->setStatus(WealthbotLot::LOT_INITIAL); $model->setDate($data['tx_date']); $model->setWasClosed(false); $model->setAmount($data['net_amount']); $model->setCostBasis($data['gross_amount']); $model->setRealizedGain(null); $model->setSecurityId($security->getId()); $model->setClientSystemAccountId($account->getId()); $model->setWasRebalancerDiff(false); $class = Factory::make($model->isBuy() ? 'Buy' : 'Sell'); // Create new lot return $class->create($model); }
/** * Create transaction * * @param \Model\Pas\SystemClientAccount $account * @param array $data * @return int|null */ public function create(SystemClientAccountModel $account, array $data) { if (null == ($security = $this->getSecurity($data['symbol']))) { return null; } if (null == ($closingMethod = $this->getClosingMethod($data['closing_method']))) { return null; } if (null == ($transactionType = $this->getTransactionType($data['transaction_code']))) { return null; } $model = new TransactionModel(); $model->loadFromArray($data); $model->setStatus('verified'); $model->setAccountId($account->getId()); $model->setSecurityId($security->getId()); $model->setClosingMethodId($closingMethod->getId()); $model->setTransactionTypeId($transactionType->getId()); $id = $this->getRepository('Transaction')->save($model); if ($id && $model->isCreateLot()) { $data['transaction_id'] = $id; $this->collection[$data['tx_date']][] = $data; } if ($id) { // Update bill item fee collected $this->updateFeeCollected($account, $model); } return $id; }