Esempio n. 1
0
 public function test_yields_beyond_lifetime_yearly_cadence()
 {
     $payments = PaymentsHelper::yields('DE0000000001', '2016-04-01', '2046-04-01');
     $this->assertNotNull($payments);
     $this->assertEquals(4, count($payments));
     $this->assertEquals(strtotime('2017-01-01'), $payments[0]->timestamp);
     $this->assertEquals(strtotime('2018-01-01'), $payments[1]->timestamp);
     $this->assertEquals(strtotime('2019-01-01'), $payments[2]->timestamp);
     $this->assertEquals(strtotime('2020-01-01'), $payments[3]->timestamp);
     foreach ($payments as $payment) {
         $this->assertEquals('cedola', $payment->tipo);
     }
 }
Esempio n. 2
0
 public static function timeline($isin, $quantita, $month_from, $month_to)
 {
     $payments = array();
     $conn = Db::get_connection();
     $stock = new Stock();
     if (!$stock->find_by_id($isin)) {
         return;
     }
     $yields = PaymentsHelper::yields($isin, $month_from, $month_to);
     $refunds = PaymentsHelper::refunds($isin, $month_from, $month_to);
     $events = array_merge($yields, $refunds);
     $payments = array();
     foreach ($events as $event) {
         if (is_array($quantita)) {
             // reset() rewinds array's internal pointer to the first element and returns the value of the first array element, or FALSE if the array is empty.
             $q = reset($quantita);
             foreach ($quantita as $date => $value) {
                 if (strtotime($date) < $event->timestamp) {
                     break;
                 }
                 $q = $value;
             }
         } else {
             $q = $quantita;
         }
         if ($event->tipo == 'rimborso') {
             switch ($event->stock->tipo) {
                 case 'obbligazione':
                     $event->importo *= $q / 100;
                     break;
                 default:
                     $event->importo *= $q;
             }
         } else {
             $event->importo *= $q;
         }
         $event->quantita = $q;
         $payments[] = $event;
     }
     // print_r($payments);
     Db::close_connection($conn);
     return $payments;
 }