use of name.abuchen.portfolio.money.ExchangeRate in project portfolio by buchen.
the class ChainedExchangeRateTimeSeries method lookupRate.
@Override
public Optional<ExchangeRate> lookupRate(LocalDate requestedTime) {
BigDecimal value = BigDecimal.ONE;
for (int ii = 0; ii < series.length; ii++) {
Optional<ExchangeRate> answer = series[ii].lookupRate(requestedTime);
if (!answer.isPresent())
return answer;
value = value.multiply(answer.get().getValue());
}
return Optional.of(new ExchangeRate(requestedTime, value));
}
use of name.abuchen.portfolio.money.ExchangeRate in project portfolio by buchen.
the class ECBExchangeRateProvider method fillInDefaultData.
/**
* Make sure we have at least one exchange rate available. The program might
* not have a connection to the internet (run behind a proxy) and is unable
* to load current exchange rate series from ECB.
*/
@SuppressWarnings("nls")
private void fillInDefaultData(ECBData summary) {
ExchangeRateTimeSeriesImpl s = new ExchangeRateTimeSeriesImpl(this, EUR, "CHF");
s.addRate(new ExchangeRate(LocalDate.parse("2015-12-18"), BigDecimal.valueOf(1.0768)));
summary.addSeries(s);
s = new ExchangeRateTimeSeriesImpl(this, EUR, "HRK");
s.addRate(new ExchangeRate(LocalDate.parse("2015-12-18"), BigDecimal.valueOf(7.6495)));
summary.addSeries(s);
s = new ExchangeRateTimeSeriesImpl(this, EUR, "MXN");
s.addRate(new ExchangeRate(LocalDate.parse("2015-12-18"), BigDecimal.valueOf(18.4429)));
summary.addSeries(s);
s = new ExchangeRateTimeSeriesImpl(this, EUR, "LVL");
s.addRate(new ExchangeRate(LocalDate.parse("2013-12-31"), BigDecimal.valueOf(0.702804)));
summary.addSeries(s);
s = new ExchangeRateTimeSeriesImpl(this, EUR, "MTL");
s.addRate(new ExchangeRate(LocalDate.parse("2007-12-31"), BigDecimal.valueOf(0.4293)));
summary.addSeries(s);
s = new ExchangeRateTimeSeriesImpl(this, EUR, "LTL");
s.addRate(new ExchangeRate(LocalDate.parse("2014-12-31"), BigDecimal.valueOf(3.4528)));
summary.addSeries(s);
s = new ExchangeRateTimeSeriesImpl(this, EUR, "ZAR");
s.addRate(new ExchangeRate(LocalDate.parse("2015-12-18"), BigDecimal.valueOf(16.2998)));
summary.addSeries(s);
s = new ExchangeRateTimeSeriesImpl(this, EUR, "INR");
s.addRate(new ExchangeRate(LocalDate.parse("2015-12-18"), BigDecimal.valueOf(71.955)));
summary.addSeries(s);
s = new ExchangeRateTimeSeriesImpl(this, EUR, "CNY");
s.addRate(new ExchangeRate(LocalDate.parse("2015-12-18"), BigDecimal.valueOf(7.0274)));
summary.addSeries(s);
s = new ExchangeRateTimeSeriesImpl(this, EUR, "THB");
s.addRate(new ExchangeRate(LocalDate.parse("2015-12-18"), BigDecimal.valueOf(39.175)));
summary.addSeries(s);
s = new ExchangeRateTimeSeriesImpl(this, EUR, "TRL");
s.addRate(new ExchangeRate(LocalDate.parse("2004-12-31"), BigDecimal.valueOf(1836200)));
summary.addSeries(s);
s = new ExchangeRateTimeSeriesImpl(this, EUR, "AUD");
s.addRate(new ExchangeRate(LocalDate.parse("2015-12-18"), BigDecimal.valueOf(1.5206)));
summary.addSeries(s);
s = new ExchangeRateTimeSeriesImpl(this, EUR, "ILS");
s.addRate(new ExchangeRate(LocalDate.parse("2015-12-18"), BigDecimal.valueOf(4.221)));
summary.addSeries(s);
s = new ExchangeRateTimeSeriesImpl(this, EUR, "KRW");
s.addRate(new ExchangeRate(LocalDate.parse("2015-12-18"), BigDecimal.valueOf(1280.16)));
summary.addSeries(s);
s = new ExchangeRateTimeSeriesImpl(this, EUR, "JPY");
s.addRate(new ExchangeRate(LocalDate.parse("2015-12-18"), BigDecimal.valueOf(131.6)));
summary.addSeries(s);
s = new ExchangeRateTimeSeriesImpl(this, EUR, "PLN");
s.addRate(new ExchangeRate(LocalDate.parse("2015-12-18"), BigDecimal.valueOf(4.2806)));
summary.addSeries(s);
s = new ExchangeRateTimeSeriesImpl(this, EUR, "GBP");
s.addRate(new ExchangeRate(LocalDate.parse("2015-12-18"), BigDecimal.valueOf(0.72666)));
summary.addSeries(s);
s = new ExchangeRateTimeSeriesImpl(this, EUR, "IDR");
s.addRate(new ExchangeRate(LocalDate.parse("2015-12-18"), BigDecimal.valueOf(15096.1)));
summary.addSeries(s);
s = new ExchangeRateTimeSeriesImpl(this, EUR, "HUF");
s.addRate(new ExchangeRate(LocalDate.parse("2015-12-18"), BigDecimal.valueOf(314.25)));
summary.addSeries(s);
s = new ExchangeRateTimeSeriesImpl(this, EUR, "PHP");
s.addRate(new ExchangeRate(LocalDate.parse("2015-12-18"), BigDecimal.valueOf(51.253)));
summary.addSeries(s);
s = new ExchangeRateTimeSeriesImpl(this, EUR, "TRY");
s.addRate(new ExchangeRate(LocalDate.parse("2015-12-18"), BigDecimal.valueOf(3.1581)));
summary.addSeries(s);
s = new ExchangeRateTimeSeriesImpl(this, EUR, "CYP");
s.addRate(new ExchangeRate(LocalDate.parse("2007-12-31"), BigDecimal.valueOf(0.585274)));
summary.addSeries(s);
s = new ExchangeRateTimeSeriesImpl(this, EUR, "RUB");
s.addRate(new ExchangeRate(LocalDate.parse("2015-12-18"), BigDecimal.valueOf(77.1005)));
summary.addSeries(s);
s = new ExchangeRateTimeSeriesImpl(this, EUR, "HKD");
s.addRate(new ExchangeRate(LocalDate.parse("2015-12-18"), BigDecimal.valueOf(8.4005)));
summary.addSeries(s);
s = new ExchangeRateTimeSeriesImpl(this, EUR, "ISK");
s.addRate(new ExchangeRate(LocalDate.parse("2008-12-09"), BigDecimal.valueOf(290)));
summary.addSeries(s);
s = new ExchangeRateTimeSeriesImpl(this, EUR, "DKK");
s.addRate(new ExchangeRate(LocalDate.parse("2015-12-18"), BigDecimal.valueOf(7.4613)));
summary.addSeries(s);
s = new ExchangeRateTimeSeriesImpl(this, EUR, "USD");
s.addRate(new ExchangeRate(LocalDate.parse("2015-12-18"), BigDecimal.valueOf(1.0836)));
summary.addSeries(s);
s = new ExchangeRateTimeSeriesImpl(this, EUR, "CAD");
s.addRate(new ExchangeRate(LocalDate.parse("2015-12-18"), BigDecimal.valueOf(1.5123)));
summary.addSeries(s);
s = new ExchangeRateTimeSeriesImpl(this, EUR, "MYR");
s.addRate(new ExchangeRate(LocalDate.parse("2015-12-18"), BigDecimal.valueOf(4.644)));
summary.addSeries(s);
s = new ExchangeRateTimeSeriesImpl(this, EUR, "BGN");
s.addRate(new ExchangeRate(LocalDate.parse("2015-12-18"), BigDecimal.valueOf(1.9558)));
summary.addSeries(s);
s = new ExchangeRateTimeSeriesImpl(this, EUR, "EEK");
s.addRate(new ExchangeRate(LocalDate.parse("2010-12-31"), BigDecimal.valueOf(15.6466)));
summary.addSeries(s);
s = new ExchangeRateTimeSeriesImpl(this, EUR, "NOK");
s.addRate(new ExchangeRate(LocalDate.parse("2015-12-18"), BigDecimal.valueOf(9.5)));
summary.addSeries(s);
s = new ExchangeRateTimeSeriesImpl(this, EUR, "ROL");
s.addRate(new ExchangeRate(LocalDate.parse("2005-06-30"), BigDecimal.valueOf(36030)));
summary.addSeries(s);
s = new ExchangeRateTimeSeriesImpl(this, EUR, "RON");
s.addRate(new ExchangeRate(LocalDate.parse("2015-12-18"), BigDecimal.valueOf(4.516)));
summary.addSeries(s);
s = new ExchangeRateTimeSeriesImpl(this, EUR, "SGD");
s.addRate(new ExchangeRate(LocalDate.parse("2015-12-18"), BigDecimal.valueOf(1.53)));
summary.addSeries(s);
s = new ExchangeRateTimeSeriesImpl(this, EUR, "SKK");
s.addRate(new ExchangeRate(LocalDate.parse("2008-12-31"), BigDecimal.valueOf(30.126)));
summary.addSeries(s);
s = new ExchangeRateTimeSeriesImpl(this, EUR, "CZK");
s.addRate(new ExchangeRate(LocalDate.parse("2015-12-18"), BigDecimal.valueOf(27.03)));
summary.addSeries(s);
s = new ExchangeRateTimeSeriesImpl(this, EUR, "SEK");
s.addRate(new ExchangeRate(LocalDate.parse("2015-12-18"), BigDecimal.valueOf(9.266)));
summary.addSeries(s);
s = new ExchangeRateTimeSeriesImpl(this, EUR, "NZD");
s.addRate(new ExchangeRate(LocalDate.parse("2015-12-18"), BigDecimal.valueOf(1.616)));
summary.addSeries(s);
s = new ExchangeRateTimeSeriesImpl(this, EUR, "BRL");
s.addRate(new ExchangeRate(LocalDate.parse("2015-12-18"), BigDecimal.valueOf(4.2265)));
summary.addSeries(s);
s = new ExchangeRateTimeSeriesImpl(this, EUR, "SIT");
s.addRate(new ExchangeRate(LocalDate.parse("2006-12-29"), BigDecimal.valueOf(239.64)));
summary.addSeries(s);
}
use of name.abuchen.portfolio.money.ExchangeRate in project portfolio by buchen.
the class ECBExchangeRateProvider method load.
@Override
public synchronized void load(IProgressMonitor monitor) throws IOException {
monitor.beginTask(MessageFormat.format(Messages.MsgLoadingExchangeRates, getName()), 2);
// read summary first (contains only latest rates, but is fast)
File file = getStorageFile(FILE_SUMMARY);
if (file.exists()) {
@SuppressWarnings("unchecked") Map<String, ExchangeRate> loaded = (Map<String, ExchangeRate>) xstream().fromXML(file);
ECBData summary = new ECBData();
for (Map.Entry<String, ExchangeRate> entry : loaded.entrySet()) {
ExchangeRateTimeSeriesImpl s = new ExchangeRateTimeSeriesImpl(this, EUR, entry.getKey());
s.addRate(entry.getValue());
summary.addSeries(s);
}
data = summary;
}
monitor.worked(1);
// read all historic exchange rates
file = getStorageFile(FILE_STORAGE);
if (file.exists()) {
ECBData loaded = (ECBData) xstream().fromXML(file);
loaded.doPostLoadProcessing(this);
data = loaded;
}
monitor.worked(1);
}
use of name.abuchen.portfolio.money.ExchangeRate in project portfolio by buchen.
the class ECBUpdater method readCubes.
private void readCubes(ExchangeRateProvider provider, ECBData data, XMLStreamReader reader) throws XMLStreamException, ParseException {
// lookup map by term currency
Map<String, ExchangeRateTimeSeriesImpl> currency2series = new HashMap<String, ExchangeRateTimeSeriesImpl>();
for (ExchangeRateTimeSeriesImpl series : data.getSeries()) currency2series.put(series.getTermCurrency(), series);
LocalDate currentDate = null;
while (reader.hasNext()) {
int event = reader.next();
if (event != XMLStreamConstants.START_ELEMENT)
continue;
if (// $NON-NLS-1$
!"Cube".equals(reader.getLocalName()))
continue;
// lookup currency first: it is more likely to show up
// $NON-NLS-1$
String termCurrency = reader.getAttributeValue(null, "currency");
if (termCurrency != null) {
ExchangeRateTimeSeriesImpl series = currency2series.get(termCurrency);
if (series == null) {
series = new ExchangeRateTimeSeriesImpl();
series.setProvider(provider);
series.setBaseCurrency(ECBExchangeRateProvider.EUR);
series.setTermCurrency(termCurrency);
currency2series.put(termCurrency, series);
data.addSeries(series);
}
// $NON-NLS-1$
String rateValue = reader.getAttributeValue(null, "rate");
BigDecimal rateNumber = new BigDecimal(rateValue);
ExchangeRate rate = new ExchangeRate(currentDate, rateNumber);
series.addRate(rate);
} else {
// $NON-NLS-1$
String time = reader.getAttributeValue(null, "time");
if (time != null)
currentDate = LocalDate.parse(time);
}
}
}
use of name.abuchen.portfolio.money.ExchangeRate in project portfolio by buchen.
the class AbstractSecurityTransactionModel method updateExchangeRate.
protected void updateExchangeRate() {
// do not auto-suggest exchange rate when editing an existing transaction
if (hasSource())
return;
if (getTransactionCurrencyCode().equals(getSecurityCurrencyCode())) {
setExchangeRate(BigDecimal.ONE);
} else if (!getTransactionCurrencyCode().isEmpty() && !getSecurityCurrencyCode().isEmpty()) {
ExchangeRateTimeSeries series = //
getExchangeRateProviderFactory().getTimeSeries(getSecurityCurrencyCode(), getTransactionCurrencyCode());
if (series != null)
setExchangeRate(series.lookupRate(date).orElse(new ExchangeRate(date, BigDecimal.ONE)).getValue());
else
setExchangeRate(BigDecimal.ONE);
}
}
Aggregations