Hi

MyMoneyFile::price(...) retrieves the price of securities, and also the 
exchange rate of currencies. The latter is restricted to known currency pairs 
(likely foreign currency versus base currency). E.g., even if EUR:USD is known 
and EUR:CHF is also known, the exchange rate USD:CHF is not returned.

I implemented a function with the requirement that both 'base exchange rates' 
(EUR:USD and EUR:CHF in above example) must be for the same date. It is a crude 
implementation and succeeds only if the date of the newest first 'base exchange 
rate' is a valid exact date for the second 'base exchange rate' (else no 
exchange rate is returned, even if both 'base exchange rates' would be 
available for let's say one day earlier).

Has anybody a better implementation of such function? Else, is there a wider 
interest in such function?



MyMoneyMoney MyClass::rate(const MyMoneySecurity &from, const MyMoneySecurity 
&to, const QDate& date, bool exactDate) const {
   MyMoneyFile* file = MyMoneyFile::instance();
   MyMoneyPrice price = file->price(from.id(), to.id(), date, exactDate);
   if (price.isValid()) return price.rate(to.id());    // direct hit from:to or 
to:from (else needs detour via base currency)
   price = file->price(file->baseCurrency().id(), from.id(), date, exactDate); 
   if (!price.isValid()) return MyMoneyMoney(0, 100);
   MyMoneyPrice price2 = file->price(file->baseCurrency().id(), to.id(), 
price.date(), true);
   if (!price2.isValid()) return MyMoneyMoney(0, 100);
   return price.rate(file->baseCurrency().id()) * price2.rate(to.id());}



Best

Al_
-- 
NEU: FreePhone - 0ct/min Handyspartarif mit Geld-zurück-Garantie!               
Jetzt informieren: http://www.gmx.net/de/go/freephone
_______________________________________________
KMyMoney-devel mailing list
KMyMoney-devel@kde.org
https://mail.kde.org/mailman/listinfo/kmymoney-devel

Reply via email to