Class FxRatesCsvLoader
- java.lang.Object
-
- com.opengamma.strata.loader.csv.FxRatesCsvLoader
-
public final class FxRatesCsvLoader extends Object
Loads a set of FX rates into memory from CSV resources.The rates are expected to be in a CSV format, with the following header row:
Valuation Date, Currency Pair, Value
.- The 'Valuation Date' column provides the valuation date, allowing data from different days to be stored in the same file
- The 'Currency Pair' column is the currency pair in the format 'EUR/USD'.
- The 'Value' column is the value of the rate.
Each file may contain entries for many different dates.
For example:
Valuation Date, Currency Pair, Value 2014-01-22, EUR/USD, 1.10 2014-01-22, GBP/USD, 1.50 2014-01-23, EUR/USD, 1.11
Note that Microsoft Excel prefers the CSV file to have no space after the comma.CSV files sometimes contain a Unicode Byte Order Mark. Callers are responsible for handling this, such as by using
UnicodeBom
.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static ImmutableMap<FxRateId,FxRate>
load(LocalDate marketDataDate, ResourceLocator... resources)
Loads one or more CSV format FX rate files for a specific date.static ImmutableMap<FxRateId,FxRate>
load(LocalDate marketDataDate, Collection<ResourceLocator> resources)
Loads one or more CSV format FX rate files for a specific date.static ImmutableMap<LocalDate,ImmutableMap<FxRateId,FxRate>>
load(Set<LocalDate> marketDataDates, ResourceLocator... resources)
Loads one or more CSV format FX rate files for a set of dates.static ImmutableMap<LocalDate,ImmutableMap<FxRateId,FxRate>>
load(Set<LocalDate> marketDataDates, Collection<ResourceLocator> resources)
Loads one or more CSV format FX rate files for a set of dates.static ImmutableMap<LocalDate,ImmutableMap<FxRateId,FxRate>>
loadAllDates(ResourceLocator... resources)
Loads one or more CSV format FX rate files.static ImmutableMap<LocalDate,ImmutableMap<FxRateId,FxRate>>
loadAllDates(Collection<ResourceLocator> resources)
Loads one or more CSV format FX rate files.static ImmutableMap<LocalDate,ImmutableMap<FxRateId,FxRate>>
parse(Predicate<LocalDate> datePredicate, Collection<CharSource> charSources)
Parses one or more CSV format FX rate files.
-
-
-
Method Detail
-
load
public static ImmutableMap<FxRateId,FxRate> load(LocalDate marketDataDate, ResourceLocator... resources)
Loads one or more CSV format FX rate files for a specific date.Only those rates that match the specified date will be loaded.
If the files contain a duplicate entry an exception will be thrown.
- Parameters:
marketDataDate
- the date to loadresources
- the CSV resources- Returns:
- the loaded FX rates, mapped by rate ID
- Throws:
IllegalArgumentException
- if the files contain a duplicate entry
-
load
public static ImmutableMap<FxRateId,FxRate> load(LocalDate marketDataDate, Collection<ResourceLocator> resources)
Loads one or more CSV format FX rate files for a specific date.Only those rates that match the specified date will be loaded.
If the files contain a duplicate entry an exception will be thrown.
- Parameters:
marketDataDate
- the date to loadresources
- the CSV resources- Returns:
- the loaded FX rates, mapped by rate ID
- Throws:
IllegalArgumentException
- if the files contain a duplicate entry
-
load
public static ImmutableMap<LocalDate,ImmutableMap<FxRateId,FxRate>> load(Set<LocalDate> marketDataDates, ResourceLocator... resources)
Loads one or more CSV format FX rate files for a set of dates.Only those rates that match one of the specified dates will be loaded.
If the files contain a duplicate entry an exception will be thrown.
- Parameters:
marketDataDates
- the set of dates to loadresources
- the CSV resources- Returns:
- the loaded FX rates, mapped by
LocalDate
and rate ID - Throws:
IllegalArgumentException
- if the files contain a duplicate entry
-
load
public static ImmutableMap<LocalDate,ImmutableMap<FxRateId,FxRate>> load(Set<LocalDate> marketDataDates, Collection<ResourceLocator> resources)
Loads one or more CSV format FX rate files for a set of dates.Only those rates that match one of the specified dates will be loaded.
If the files contain a duplicate entry an exception will be thrown.
- Parameters:
marketDataDates
- the dates to loadresources
- the CSV resources- Returns:
- the loaded FX rates, mapped by
LocalDate
and rate ID - Throws:
IllegalArgumentException
- if the files contain a duplicate entry
-
loadAllDates
public static ImmutableMap<LocalDate,ImmutableMap<FxRateId,FxRate>> loadAllDates(ResourceLocator... resources)
Loads one or more CSV format FX rate files.All dates that are found will be returned.
If the files contain a duplicate entry an exception will be thrown.
- Parameters:
resources
- the CSV resources- Returns:
- the loaded FX rates, mapped by
LocalDate
and rate ID - Throws:
IllegalArgumentException
- if the files contain a duplicate entry
-
loadAllDates
public static ImmutableMap<LocalDate,ImmutableMap<FxRateId,FxRate>> loadAllDates(Collection<ResourceLocator> resources)
Loads one or more CSV format FX rate files.All dates that are found will be returned.
If the files contain a duplicate entry an exception will be thrown.
- Parameters:
resources
- the CSV resources- Returns:
- the loaded FX rates, mapped by
LocalDate
and rate ID - Throws:
IllegalArgumentException
- if the files contain a duplicate entry
-
parse
public static ImmutableMap<LocalDate,ImmutableMap<FxRateId,FxRate>> parse(Predicate<LocalDate> datePredicate, Collection<CharSource> charSources)
Parses one or more CSV format FX rate files.A predicate is specified that is used to filter the dates that are returned. This could match a single date, a set of dates or all dates.
If the files contain a duplicate entry an exception will be thrown.
- Parameters:
datePredicate
- the predicate used to select the datescharSources
- the CSV character sources- Returns:
- the loaded FX rates, mapped by
LocalDate
and rate ID - Throws:
IllegalArgumentException
- if the files contain a duplicate entry
-
-