/** * @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); }
public function calculateValue() { $model = new PortfolioTwrValueModel(); $model->setDate($this->getCurDate()->format('Y-m-d')); $model->setClientId($this->getKey()); $model->setNetValue(Functions::calculateTodayTwr($this->getSumTodayClientValue(), $this->getSumYesterdayClientNetCashFlow(), $this->getSumYesterdayClientValue())); $model->setGrossValue(Functions::calculateTodayTwr($this->getSumTodayClientValue(), $this->getSumYesterdayClientGrossCashFlow(), $this->getSumYesterdayClientValue())); // Save portfolio value return $model->getNetValue() && $model->getGrossValue() ? $this->valueRepo->save($model) : null; }
public function testCalculateAnnualizedTwr() { $actualTwr = TwrFunctions::calculateActualTwr($this->fixture); $annualizedTwr = TwrFunctions::calculateAnnualizedTwr($actualTwr, 30); $this->assertEquals(163800.0, $annualizedTwr); }
/** * @return float */ public function calculate() { $dateFrom = $this->getDateFrom(); $index = $dateFrom instanceof \DateTime ? $dateFrom->format('dmY') : 'index'; $identificator = $this->getIdentificator(); if (!isset($this->dataHash[$identificator][$index])) { $this->dataHash[$identificator][$index] = $this->valueRepo->findAllByPeriod($identificator, $dateFrom, $this->getDateTo()); } $values = $this->normalizeData($this->dataHash[$identificator][$index]); return Functions::calculateActualTwr($values); }