Code (PHP) pasted on 2019-04-15, 20:40 Raw Source
- <?php
 - public function getAssetAllocation(Depot $depot)
 - {
 - $stocks = $depot->getStocks();
 - $step = 0.01;
 - $maxIterations = ($stockCount - $step) / $step;
 - for ($i = 0; $i <= $maxIterations; $i++) {
 - // 3 possible values: +$step -$step and 0
 - for ($t = 0; $t <= 17; $t++) {
 - $depots[$t] = clone $depot;
 - /**
 - * build variants with depots
 - */
 - /** @var Stock $stock */
 - foreach ($depots[$t]->getStocks() as $stock) {
 - $stock->setAmount();
 - }
 - /**
 - * get current yield/volatility
 - */
 - $currentYield = $this->getDepotExpectedYield($depot);
 - $currentVola = $this->getDepotStandardDeviation($depot);
 - /**
 - * get the depot with best yield/volatility ratio
 - */
 - foreach($depots as $key => $d){
 - $yield = $this->getDepotExpectedYield($d);
 - $vola = $this->getDepotStandardDeviation($d);
 - if($vola <= $currentVola && $yield >= $currentYield){
 - // better match found. change $depot to new one.
 - $depot = $d;
 - }
 - }
 - }
 - }
 - }