glossary:
IRD = interest-rate derivative
IRS = interest-rate swap, a type of IRD
image: "postgres:9.6.20"
drop table if exists IRS_fixed_legs;
drop table if exists IRS_floating_legs;
drop table if exists IRS_legs;
drop table if exists IRD_swaps;
drop table if exists IRD_rates_derivative_trades;
drop table if exists trades;
CREATE TYPE buysell_ AS ENUM ('B', 'S');
CREATE TYPE upfront_inarrears_ AS ENUM ('UF', 'AR');
CREATE TABLE trades (
id SERIAL PRIMARY KEY, -- integer + AUTO_INCREMENT
trader text,
buysell buysell_,
portfolio text,
counterpart text,
insert_datetime timestamp ,
trade_date date,
expiry_date date,
state text
);
CREATE TABLE IRD_rates_derivative_trades (
ccy char(3),
notional money -- two-digit precision
) INHERITS (trades);
CREATE TABLE IRD_swaps (
id SERIAL PRIMARY KEY
-- this PK override will allow the the proper FK in table IRS_legs
) INHERITS (IRD_rates_derivative_trades);
CREATE TABLE IRS_legs (
id SERIAL PRIMARY KEY,
trade integer REFERENCES IRD_swaps(id),
startdate date,
enddate date,
upfront_inarrears upfront_inarrears_
);
CREATE TABLE IRS_fixed_legs (
fixed_rate real -- 6 decimal digits precision
) INHERITS (IRS_legs);
CREATE TABLE IRS_floating_legs (
floating_index text,
floating_index_spread real -- 6 decimal digits precision
) INHERITS (IRS_legs);
selecting entries - example:
SELECT * FROM IRD_swaps;
SELECT * FROM ONLY trades; -- i.e. not IRD_swaps
ref.
https://www.postgresql.org/docs/current/tutorial-inheritance.html
The inheritance hierarchy is actually a directed acyclic graph
https://www.postgresql.org/docs/current/datatype.html
back to Portfolio