public function getRate($date = null)
 {
     if (!isset($this->rateHistory)) {
         $this->rateHistory = CurrencyDAO::GetInstance()->getCurrencyRateHistory($this->code);
     }
     if (is_null($date)) {
         return $this->rateHistory[0];
     } else {
         foreach ($this->rateHistory as $rateDate => $rate) {
             if ((new \DateTime($date))->diff(new \DateTime($rateDate))->invert) {
                 return $rate;
             }
         }
         throw new \Exception("No currency " . $this->code . " rate found for " . $date);
     }
 }