FXRATES

The FXRATES table contains all the FX Rates. It is an isolated table and not part of any cube facts.

FX Rates are looked up via the default implementation of IFXRates API.

Column Name Type Not Null Default Value1 Description
AS_OF_DATE DATE Y Timestamp (at close of business) for the data.
MARKET_DATA_SET STRING Y N/A String defining the market data set.
BASE_CCY STRING Y N/A The left side of the currency pair.
COUNTER_CCY STRING Y N/A The right side of the currency pair.
TERM STRING Y N/A The term of the rate.
FX_RATE DOUBLE Y 1.0 Forex rate between the two currencies.
RISK_FACTOR_ID STRING N/A Risk factor id used to compute FX risk

Unique Key

Columns
AS_OF_DATE
MARKET_DATA_SET
BASE_CCY
COUNTER_CCY
TERM

Table creation script

Snowflake

Table creation

create OR REPLACE table FXRATES(
	AS_OF_DATE DATE NOT NULL,
	MARKET_DATA_SET STRING NOT NULL DEFAULT 'N/A',
	BASE_CCY STRING NOT NULL DEFAULT 'N/A',
	COUNTER_CCY STRING NOT NULL DEFAULT 'N/A',
	TERM STRING NOT NULL DEFAULT 'N/A',
	RATE DOUBLE NOT NULL DEFAULT 1.0,
	RISK_FACTOR_ID STRING,
	primary key (AS_OF_DATE, MARKET_DATA_SET, BASE_CCY, COUNTER_CCY, TERM)
);

Table population from files (optional)

If you want to populate the table from CSV files, you can run the following scripts (this example assumes that you want to load the files FXRates.csv present in the folders 2023-09-25, 2023-09-26, 2023-09-27 and 2023-09-28):

create OR REPLACE stage MR_INPUT_RAW;

create OR REPLACE file format CSV_GZIP TYPE = CSV COMPRESSION = GZIP SKIP_HEADER = 1 comment = 'File format to import MR data';

create OR REPLACE file format CSV_FORMAT TYPE = CSV COMPRESSION = AUTO SKIP_HEADER = 1 comment = 'File format to import MR data';

PUT file://<full path to you data folder>/2023-09-25/FXRates.csv @MR_INPUT_RAW/2023-09-25; PUT file://<full path to you data folder>/2023-09-26/FXRates.csv @MR_INPUT_RAW/2023-09-26; PUT file://<full path to you data folder>/2023-09-27/FXRates.csv @MR_INPUT_RAW/2023-09-27; PUT file://<full path to you data folder>/2023-09-28/FXRates.csv @MR_INPUT_RAW/2023-09-28;

copy into FXRATES from ( select $1, ifnull($2, 'N/A'), $3, $4, ifnull($5, 'N/A'), ifnull($6, 1.0), $7 from @MR_INPUT_RAW (pattern => './FXRates..csv.gz' , FILE_FORMAT => 'CSV_GZIP'));


  1. If the default value is marked as empty, it means that the default value is 'null' for nullable fields, and that a value needs to be explicitly set for non-nullable fields.  ↩︎