CREATE DATABASE millistream;
\c millistream

CREATE TABLE corporateactions
(
  "insref" numeric(20) NOT NULL,
  "type" smallint NOT NULL,
  "subtype" smallint,
  "dividend" double precision,
  "netdividend" double precision,
  "adjustmentfactor" double precision,
  "numberofshares" numeric(20),
  "numberofprefshares" numeric(20),
  "numberofsharesdelta" numeric(20),
  "newshares" double precision,
  "oldshares" double precision,
  "subscriptionprice" double precision,
  "redemptionprice" double precision,
  "period" character varying(19),
  "fiscalperiod" character varying(19),
  "nominalvalue" double precision,
  "recorddate" date,
  "paymentdate" date,
  "announcementdate" date,
  "tid" double precision,
  "closeprice" double precision,
  "issuecurrency" character varying(4),
  "tradecurrency" character varying(4),
  "freetextcomment1" character varying(255),
  "freetextcomment2" character varying(255),
  "freetextcomment3" character varying(255),
  "freetextcomment4" character varying(255),
  "freetextcomment5" character varying(255),
  "underlyingid" character varying(255),
  "symbol" character varying(255),
  "name" character varying(255),
  "isin" character(12),
  "boardlot" integer,
  "marketplace" numeric(20),
  "list" character varying(255),
  "votingpowerprc" double precision,
  "capitalprc" double precision,
  "mcap" double precision,
  "eventlink" character(36),
  "eventlinklanguages" character varying(255),
  "eventstatus" smallint,
  "shareclass" character varying(4),
  "lastmodified" timestamp without time zone,
  "date" date NOT NULL, 
  "time" time without time zone NOT NULL,
  CONSTRAINT corporateactions_pkey PRIMARY KEY ("insref","date","time")
);

CREATE INDEX idx_corporateactionsindex1 ON corporateactions ("insref","type","date");
CREATE INDEX idx_corporateactionsindex2 ON corporateactions ("insref","type","subtype","date");

CREATE TABLE instruments
(
  "insref" numeric(20) NOT NULL,
  "name" character varying(255),
  "symbol" character varying(50),
  "isin" character(12),
  "boardlot" integer,
  "instrumenttype" smallint,
  "instrumentsubtype" smallint,
  "instrumentclass" smallint,
  "instrumentsubclass" character varying(30),
  "instrumentsubsubclass" character varying(120),
  "derivativeindicator" smallint,
  "exercisetype" smallint,
  "issuecurrency" character varying(4),
  "tradecurrency" character varying(4),
  "basecurrency" character varying(4),
  "quotecurrency" character varying(4),
  "issuedate" date,
  "strikedate" date,
  "strikeprice" double precision,
  "marketplace" numeric(20),
  "primarymarketplace" numeric(20),
  "submarket" numeric(20),
  "company" numeric(20),
  "fundppmcode" integer,
  "fundpmicode" character varying(11),
  "fundcompany" numeric(20),
  "country" character(2),
  "freetextcomment" character varying(255),
  "numberofshares" numeric(20),
  "numberofprefshares" numeric(20),
  "nominalvalue" double precision,
  "mic" character(5),
  "operatingmic" character(5),
  "sector" numeric(20),
  "tradestate" smallint,
  "tradestateactions" smallint,
  "chairman" character varying(60),
  "ceo" character varying(255),
  "website" character varying(255),
  "orgnum" character varying(11),
  "orgnum_no" numeric(9),
  "cvr" integer,
  "y_tunnus" character varying(9),
  "kennitala" numeric(10),
  "cik" numeric(10),
  "shortdescription" character varying(512),
  "description" text,
  "genderceo" character(1),
  "genderchairman" character(1),
  "birthyearceo" smallint,
  "birthyearchairman" smallint,
  "address" character varying(255),
  "postalcode" character varying(255),
  "city" character varying(50),
  "telephone" character varying(40),
  "fax" character varying(40),
  "email" character varying(255),
  "importantevents" text,
  "contractsize" double precision,
  "baseratio" double precision,
  "sourceid" character varying(32),
  "issuer" character varying(255),
  "issuername" character varying(255),
  "ongoingcharge" double precision,
  "fundyearlymgmtfee" double precision,
  "fundppmfee" double precision,
  "fundleverage" double precision,
  "funddirection" character varying(5),
  "fundbenchmark" character varying(255),
  "fundbenchmarkinsref" numeric(20),
  "fundppmtype" character varying(255),
  "fundrisk" smallint,
  "prospectus" text,
  "geofocusregion" character varying(20),
  "geofocuscountry" character varying(20),
  "openinterest" double precision,
  "geniumid" integer,
  "cusip" character varying(9),
  "wkn" character varying(6),
  "ucits" smallint,
  "inceptiondate" date,
  "barrierprice" double precision,
  "ceoadmissiondate" date,
  "chairmanadmissiondate" date,
  "coupondate" date,
  "couponrate" double precision,
  "couponfrequency" smallint,
  "fundmcap" double precision,
  "fundminadditionalamount" double precision,
  "fundminstartamount" double precision,
  "fundminsubscriptionamount" double precision,
  "fundperformancefee" double precision,
  "purchasefee" double precision,
  "salesfee" double precision,
  "totalfee" double precision,
  "morningstarrating" smallint,
  "tradedthroughdate" date,
  "dividendtype" smallint,
  "dividendfrequency" smallint,
  "pricingfrequency" smallint,
  "eusipa" integer,
  "convertfromdate" date,
  "converttodate" date,
  "conversionprice" double precision,
  "specialcondition" integer,
  "settlementtype" smallint,
  "votingpower" double precision,
  "cap" double precision,
  "pricetype" smallint,
  "volumedimension" smallint,
  "quotingtype" smallint,
  "asiantailstart" date,
  "asiantailend" date,
  "logotype" text,
  "ticktable" numeric(20),
  "contractvalue" double precision,
  "financinglevel" double precision,
  "unitlinkcompany" character varying(255),
  "participationrate" double precision,
  "issueprice" double precision,
  "fiinstitutenumber" numeric(20),
  "kiid" text,
  "cfi" character(6),
  "maxlevel" double precision,
  "outstandingamount" double precision,
  "interestrate" double precision,
  "marketmaker" character varying(255),
  "marketopendays" integer,
  "marketopen" time without time zone,
  "marketclose" time without time zone,
  "marketearlyclose" time without time zone,
  "legalstructure" character varying(255),
  "productcode" character varying(20),
  "latestyearendreport" character varying(4),
  "csr" double precision,
  "activeshare" double precision,
  "trackingerror" double precision,
  "figi" character varying(12),
  "figicomposite" character varying(12),
  "figishareclass" character varying(12),
  "figisecuritytype" character varying(40),
  "daycountconvention" smallint,
  "expirationtype" smallint,
  "tenor" character varying(5),
  "swingfactor" double precision,
  "swingfactorsub" double precision,
  "swingmethod" smallint,
  "clearing" character varying(255),
  "applicablenav" character varying(10),
  "fundcutofftime" character varying(20),
  "shareclass" character varying(4),
  "lastmodified" timestamp without time zone,
  "time" time without time zone,
  "date" date,
  CONSTRAINT instruments_pk PRIMARY KEY ("insref")
);

CREATE TABLE listmappings
(
  "list" numeric(20) NOT NULL,
  "insref" numeric(20) NOT NULL,
  CONSTRAINT listmappings_pk PRIMARY KEY ("list","insref")
);
CREATE INDEX idx_listmappings ON listmappings ("insref");

CREATE TABLE news
(
  "newsref" numeric(20) NOT NULL,
  "headline" character varying(255) NOT NULL,
  "text" text,
  "newstype" smallint,
  "subject" smallint,
  "regulatory" smallint,
  "language" character(2),
  "newsid" character(36) NOT NULL,
  "replaces" character(36),
  "originalcode" character varying(255),
  "rank" smallint,
  "impact" smallint,
  "package" numeric(20),
  "lastmodified" timestamp without time zone,
  "time" time without time zone NOT NULL,
  "date" date NOT NULL,
  CONSTRAINT news_pk PRIMARY KEY ("newsid")
);

CREATE INDEX idx_news ON news ("newsref","date");

CREATE TABLE orderbooks
(
  "insref" numeric(20) NOT NULL,
  "price" double precision NOT NULL,
  "quantity" double precision,
  "side" character(1) NOT NULL,
  "numorders" smallint,
  "counterparties" character varying(255),
  "mmo" smallint,
  "time" time without time zone NOT NULL,
  "date" date NOT NULL,
  CONSTRAINT orderbook_pk PRIMARY KEY ("insref","price","side")
);

CREATE TABLE mbo
(
  "insref" numeric(20) NOT NULL,
  "id" numeric(20) NOT NULL,
  "id_source" character varying(255),
  "side" smallint,
  "priority" numeric(20),
  "price" double precision,
  "quantity" double precision,
  "participant" character varying(255),
  "mmo" smallint,
  "time" time without time zone NOT NULL,
  "date" date NOT NULL,
  CONSTRAINT mbo_pk PRIMARY KEY ("insref","id")
);

CREATE TABLE pricehistory
(
  "insref" numeric(20) NOT NULL,
  "type" smallint,
  "closebidprice" double precision,
  "closeaskprice" double precision,
  "closetradeprice" double precision,
  "closeprice" double precision,
  "closedayhighprice" double precision,
  "closedaylowprice" double precision,
  "closequantity" numeric(20,0),
  "closeinternalquantity" numeric(20,0),
  "closeoffbookquantity" numeric(20,0),
  "closedarkquantity" numeric(20,0),
  "closeturnover" numeric(38,7),
  "closeinternalturnover" numeric(38,7),
  "closeoffbookturnover" numeric(38,7),
  "closedarkturnover" numeric(38,7),
  "openprice" double precision,
  "numtrades" numeric(20),
  "openyield" double precision,
  "closebidyield" double precision,
  "closeaskyield" double precision,
  "closeyield" double precision,
  "closedayhighyield" double precision,
  "closedaylowyield" double precision,
  "closenav" double precision,
  "closetis" double precision,
  "closevwap" double precision,
  "mcap" numeric(38,7),
  "settlementprice" double precision,
  "lastmodified" timestamp without time zone,
  "time" time without time zone NOT NULL,
  "date" date NOT NULL,
  CONSTRAINT pricehistory_pk PRIMARY KEY ("insref", "date")
);

CREATE TABLE adjustedpricehistory
(
  "insref" numeric(20) NOT NULL,
  "type" smallint,
  "closebidprice" double precision,
  "closeaskprice" double precision,
  "closetradeprice" double precision,
  "closeprice" double precision,
  "closedayhighprice" double precision,
  "closedaylowprice" double precision,
  "closequantity" numeric(20,0),
  "closeinternalquantity" numeric(20,0),
  "closeoffbookquantity" numeric(20,0),
  "closedarkquantity" numeric(20,0),
  "closeturnover" numeric(38,7),
  "closeinternalturnover" numeric(38,7),
  "closeoffbookturnover" numeric(38,7),
  "closedarkturnover" numeric(38,7),
  "openprice" double precision,
  "numtrades" numeric(20),
  "openyield" double precision,
  "closebidyield" double precision,
  "closeaskyield" double precision,
  "closeyield" double precision,
  "closedayhighyield" double precision,
  "closedaylowyield" double precision,
  "closenav" double precision,
  "closetis" double precision,
  "closevwap" double precision,
  "settlementprice" double precision,
  "mcap" numeric(38,7),
  "lastmodified" timestamp without time zone,
  "time" time without time zone NOT NULL,
  "date" date NOT NULL,
  CONSTRAINT adjustedpricehistory_pk PRIMARY KEY ("insref", "date")
);

CREATE TABLE quotes
(
  "insref" numeric(20) NOT NULL,
  "bidprice" double precision,
  "bidquantity" double precision,
  "askprice" double precision,
  "askquantity" double precision,
  "lastprice" double precision,
  "dayhighprice" double precision,
  "daylowprice" double precision,
  "quantity" numeric(20,0),
  "internalquantity" numeric(20,0),
  "offbookquantity" numeric(20,0),
  "darkquantity" numeric(20,0),
  "turnover" numeric(38,7),
  "internalturnover" numeric(38,7),
  "offbookturnover" numeric(38,7),
  "darkturnover" numeric(38,7),
  "numtrades" numeric(20,0),
  "openprice" double precision,
  "bidyield" double precision,
  "askyield" double precision,
  "lastyield" double precision,
  "openyield" double precision,
  "dayhighyield" double precision,
  "daylowyield" double precision,
  "nav" double precision,
  "tis" double precision,
  "unchangedpaid" integer,
  "pluspaid" integer,
  "minuspaid" integer,
  "vwap" double precision,
  "duration" double precision,
  "settlementprice" double precision,
  "time" time without time zone,
  "date" date,
  CONSTRAINT quotes_pk PRIMARY KEY ("insref")
);

CREATE TABLE quotesex
(
  "insref" numeric(20) NOT NULL,
  "bidprice" double precision,
  "bidquantity" double precision,
  "askprice" double precision,
  "askquantity" double precision,
  "lastprice" double precision,
  "dayhighprice" double precision,
  "daylowprice" double precision,
  "quantity" numeric(20,0),
  "turnover" numeric(38,7),
  "numtrades" numeric(20,0),
  "time" time without time zone,
  "date" date,
  CONSTRAINT quotesex_pk PRIMARY KEY ("insref")
);

CREATE TABLE stats
(
  "name" character varying(255) NOT NULL,
  "value" character varying(255) NOT NULL,
  CONSTRAINT stats_pk PRIMARY KEY ("name")
);

CREATE TABLE trades
(
  "insref" numeric(20) NOT NULL,
  "tradeprice" double precision,
  "tradeyield" double precision,
  "tradequantity" double precision,
  "tradereference" character varying(255) NOT NULL,
  "tradecode" integer NOT NULL,
  "mmt" character(14),
  "tradetype" character varying(10),
  "buyer" character varying(64),
  "seller" character varying(64),
  "executedside" character(1),
  "canceltime" time without time zone,
  "agreementtime" time without time zone,
  "agreementdate" date,
  "executionvenue" character varying(255),
  "currency" character varying(4),
  "time" time without time zone NOT NULL,
  "date" date NOT NULL,
  CONSTRAINT trades_pk PRIMARY KEY ("insref","date","tradereference")
);

CREATE TABLE fundamentals (
  "insref" numeric(20) NOT NULL,
  "sales" double precision,
  "ebit" double precision,
  "ebita" double precision,
  "ebitda" double precision,
  "financialincome" double precision,
  "financialcost" double precision,
  "ptp" double precision,
  "np" double precision,
  "eps" double precision,
  "eps_ttm" double precision,
  "eps_last" double precision,
  "dilutedeps" double precision,
  "netfinancialincome" double precision,
  "equityratio" double precision,
  "numberofshares" double precision,
  "operatingcashflow" double precision,
  "gp" double precision,
  "intangibleasset" double precision,
  "goodwill" double precision,
  "fixedasset" double precision,
  "financialasset" double precision,
  "noncurrentasset" double precision,
  "inventory" double precision,
  "othercurrentasset" double precision,
  "accountsreceivable" double precision,
  "otherreceivables" double precision,
  "shortterminv" double precision,
  "cce" double precision,
  "currentassets" double precision,
  "totalassets" double precision,
  "shequity" double precision,
  "minorityinterest" double precision,
  "provisions" double precision,
  "ltliabilities" double precision,
  "curliabilities" double precision,
  "totsheqliabilities" double precision,
  "nibl" double precision,
  "ibl" double precision,
  "cashflowbwc" double precision,
  "cashflowawc" double precision,
  "cashflowia" double precision,
  "cashflowfa" double precision,
  "cashflowtotal" double precision,
  "interestincome" double precision,
  "otherfinancialincome" double precision,
  "interestexpense" double precision,
  "otherfinancialexpense" double precision,
  "minorityinterestres" double precision,
  "accountspayable" double precision,
  "eventlink" character(36),
  "eventlinklanguages" character varying(255),
  "numemployees" double precision,
  "dividend" double precision,
  "incomepropman" double precision,
  "period" character varying(7) NOT NULL,
  "fiscalperiod" character(19),
  "currency" character(3) NOT NULL,
  "adjustmentfactor" double precision,
  "source" character(15) NOT NULL default 'Millistream',
  "date" date NOT NULL,
  "announcementdate" date,
  "dy" double precision,
  "per_ttm" double precision,
  "per_last" double precision,
  "psr_ttm" double precision,
  "psr_last" double precision,
  "pbr" double precision,
  "pcf_ttm" double precision,
  "pcf_last" double precision,
  "sps_ttm" double precision,
  "sps_last" double precision,
  "bvps" double precision,
  "cfps_ttm" double precision,
  "cfps_last" double precision,
  "roe_ttm" double precision,
  "roe_last" double precision,
  "roa_ttm" double precision,
  "roa_last" double precision,
  "gm" double precision,
  "gm_ttm" double precision,
  "om" double precision,
  "om_ttm" double precision,
  "pm" double precision,
  "pm_ttm" double precision,
  "der" double precision,
  "nd_ebitda_ttm" double precision,
  "nd_ebitda_last" double precision,
  "dpr" double precision,
  "roic_ttm" double precision,
  "roic_last" double precision,
  "peg_ttm" double precision,
  "peg_last" double precision,
  "closeprice" double precision,
  "lastmodified" timestamp without time zone,
  CONSTRAINT fundamentals_pk PRIMARY KEY ("insref","period","currency","source")
);
CREATE INDEX idx_fundamentals ON fundamentals ("insref","period");

CREATE TABLE estimates (
  "insref" numeric(20) NOT NULL,
  "period" character varying(7) NOT NULL,
  "field" character varying(30) NOT NULL,
  "aspect" character varying(10) NOT NULL,
  "type" character varying(20) NOT NULL,
  "unit" character varying(255),
  "average" double precision,
  "min" double precision,
  "max" double precision,
  "count" integer,
  "currency" character(3) NOT NULL,
  "source" character(15) NOT NULL,
  "lastmodified" timestamp without time zone,
  "date" date NOT NULL,
  "time" time NOT NULL,
  CONSTRAINT estimates_pk PRIMARY KEY ("insref","period","field","aspect","type","currency","source")
);

CREATE TABLE estimateshistory (
  "insref" numeric(20) NOT NULL,
  "period" character varying(7) NOT NULL,
  "field" character varying(30) NOT NULL,
  "aspect" character varying(10) NOT NULL,
  "type" character varying(20) NOT NULL,
  "unit" character varying(255),
  "average" double precision,
  "min" double precision,
  "max" double precision,
  "count" integer,
  "currency" character(3) NOT NULL,
  "source" character(15) NOT NULL,
  "lastmodified" timestamp without time zone,
  "date" date NOT NULL,
  "time" time NOT NULL,
  CONSTRAINT estimateshistory_pk PRIMARY KEY ("insref","date","period","field","aspect","type","currency","source")
);

CREATE TABLE performance (
  "insref" numeric(20) NOT NULL,
  "closebidprice1d" double precision,
  "closebidprice1w" double precision,
  "closeprice" double precision,
  "closeprice1d" double precision,
  "closeprice1w" double precision,
  "closeprice2w" double precision,
  "closeprice1m" double precision,
  "closeprice3m" double precision,
  "closeprice6m" double precision,
  "closeprice9m" double precision,
  "closeprice1y" double precision,
  "closeprice2y" double precision,
  "closeprice3y" double precision,
  "closeprice4y" double precision,
  "closeprice5y" double precision,
  "closeprice6y" double precision,
  "closeprice7y" double precision,
  "closeprice8y" double precision,
  "closeprice9y" double precision,
  "closeprice10y" double precision,
  "closepricewtd" double precision,
  "closepricemtd" double precision,
  "closepriceqtd" double precision,
  "closepriceytd" double precision,
  "closepricepytd" double precision,
  "closepriceld" double precision,
  "closebidyield1d" double precision,
  "closebidyield1w" double precision,
  "closeyield1d" double precision,
  "closeyield1w" double precision,
  "closeyield2w" double precision,
  "closeyield1m" double precision,
  "closeyield3m" double precision,
  "closeyield6m" double precision,
  "closeyield9m" double precision,
  "closeyield1y" double precision,
  "closeyield2y" double precision,
  "closeyield3y" double precision,
  "closeyield4y" double precision,
  "closeyield5y" double precision,
  "closeyield6y" double precision,
  "closeyield7y" double precision,
  "closeyield8y" double precision,
  "closeyield9y" double precision,
  "closeyield10y" double precision,
  "closeyieldwtd" double precision,
  "closeyieldmtd" double precision,
  "closeyieldqtd" double precision,
  "closeyieldytd" double precision,
  "closeyieldpytd" double precision,
  "closeyieldld" double precision,
  "ath" double precision,
  "atl" double precision,
  "highprice1y" double precision,
  "lowprice1y" double precision,
  "highprice3y" double precision,
  "lowprice3y" double precision,
  "highprice5y" double precision,
  "lowprice5y" double precision,
  "highprice10y" double precision,
  "lowprice10y" double precision,
  "highpriceytd" double precision,
  "lowpriceytd" double precision,
  "closepricedate" date,
  "closeprice1ddate" date,
  "athdate" date,
  "atldate" date,
  "highprice1ydate" date,
  "lowprice1ydate" date,
  "highpriceytddate" date,
  "lowpriceytddate" date,
  "athyield" double precision,
  "atlyield" double precision,
  "highyield1y" double precision,
  "lowyield1y" double precision,
  "highyieldytd" double precision,
  "lowyieldytd" double precision,
  "athyielddate" date,
  "atlyielddate" date,
  "highyield1ydate" date,
  "lowyield1ydate" date,
  "highyieldytddate" date,
  "lowyieldytddate" date,
  "diffbid1d" double precision,
  "diffbid1w" double precision,
  "diff1d" double precision,
  "diffex1d" double precision,
  "diff1w" double precision,
  "diff2w" double precision,
  "diff1m" double precision,
  "diff3m" double precision,
  "diff6m" double precision,
  "diff9m" double precision,
  "diff1y" double precision,
  "diff2y" double precision,
  "diff3y" double precision,
  "diff4y" double precision,
  "diff5y" double precision,
  "diff6y" double precision,
  "diff7y" double precision,
  "diff8y" double precision,
  "diff9y" double precision,
  "diff10y" double precision,
  "diffld" double precision,
  "diffwtd" double precision,
  "diffmtd" double precision,
  "diffqtd" double precision,
  "diffytd" double precision,
  "diffpytd" double precision,
  "diffbid1dprc" double precision,
  "diffbid1wprc" double precision,
  "diff1dprc" double precision,
  "diffex1dprc" double precision,
  "diff1wprc" double precision,
  "diff2wprc" double precision,
  "diff1mprc" double precision,
  "diff3mprc" double precision,
  "diff6mprc" double precision,
  "diff9mprc" double precision,
  "diff1yprc" double precision,
  "diff2yprc" double precision,
  "diff3yprc" double precision,
  "diff4yprc" double precision,
  "diff5yprc" double precision,
  "diff6yprc" double precision,
  "diff7yprc" double precision,
  "diff8yprc" double precision,
  "diff9yprc" double precision,
  "diff10yprc" double precision,
  "diffldprc" double precision,
  "diffwtdprc" double precision,
  "diffmtdprc" double precision,
  "diffqtdprc" double precision,
  "diffytdprc" double precision,
  "diffpytdprc" double precision,
  "diffbidyield1d" double precision,
  "diffbidyield1w" double precision,
  "diffyield1d" double precision,
  "diffyield1w" double precision,
  "diffyield2w" double precision,
  "diffyield1m" double precision,
  "diffyield3m" double precision,
  "diffyield6m" double precision,
  "diffyield9m" double precision,
  "diffyield1y" double precision,
  "diffyield2y" double precision,
  "diffyield3y" double precision,
  "diffyield4y" double precision,
  "diffyield5y" double precision,
  "diffyield6y" double precision,
  "diffyield7y" double precision,
  "diffyield8y" double precision,
  "diffyield9y" double precision,
  "diffyield10y" double precision,
  "diffyieldld" double precision,
  "diffyieldwtd" double precision,
  "diffyieldmtd" double precision,
  "diffyieldqtd" double precision,
  "diffyieldytd" double precision,
  "diffyieldpytd" double precision,
  "diffbidyield1dprc" double precision,
  "diffbidyield1wprc" double precision,
  "diffyield1dprc" double precision,
  "diffyield1wprc" double precision,
  "diffyield2wprc" double precision,
  "diffyield1mprc" double precision,
  "diffyield3mprc" double precision,
  "diffyield6mprc" double precision,
  "diffyield9mprc" double precision,
  "diffyield1yprc" double precision,
  "diffyield2yprc" double precision,
  "diffyield3yprc" double precision,
  "diffyield4yprc" double precision,
  "diffyield5yprc" double precision,
  "diffyield6yprc" double precision,
  "diffyield7yprc" double precision,
  "diffyield8yprc" double precision,
  "diffyield9yprc" double precision,
  "diffyield10yprc" double precision,
  "diffyieldldprc" double precision,
  "diffyieldwtdprc" double precision,
  "diffyieldmtdprc" double precision,
  "diffyieldqtdprc" double precision,
  "diffyieldytdprc" double precision,
  "diffyieldpytdprc" double precision,
  "annualizedreturn1y" double precision,
  "annualizedreturn2y" double precision,
  "annualizedreturn3y" double precision,
  "annualizedreturn4y" double precision,
  "annualizedreturn5y" double precision,
  "annualizedreturn10y" double precision,
  "standarddeviation3y" double precision,
  "sharperatio3y" double precision,
  "normanamount" double precision,
  "avgturnover1w" double precision,
  "avgturnover1m" double precision,
  "avgturnover3m" double precision,
  "avgturnover1y" double precision,
  "avgturnover1ytd" double precision,
  "avgturnoverytd" double precision,
  "time" time without time zone,
  "date" date,
  CONSTRAINT performance_pk PRIMARY KEY ("insref")
);

CREATE TABLE keyratios (
  "insref" numeric(20) NOT NULL,
  "dividendyield" double precision,
  "per" double precision,
  "per_ttm" double precision,
  "per_last" double precision,
  "psr" double precision,
  "psr_ttm" double precision,
  "psr_last" double precision,
  "pbr" double precision,
  "pbr_last" double precision,
  "pcf" double precision,
  "pcf_ttm" double precision,
  "pcf_last" double precision,
  "dps" double precision,
  "eps" double precision,
  "eps_ttm" double precision,
  "eps_last" double precision,
  "sps" double precision,
  "sps_ttm" double precision,
  "sps_last" double precision,
  "bvps" double precision,
  "bvps_last" double precision,
  "cfps" double precision,
  "cfps_ttm" double precision,
  "cfps_last" double precision,
  "roe" double precision,
  "roe_ttm" double precision,
  "roe_last" double precision,
  "roa" double precision,
  "roa_ttm" double precision,
  "roa_last" double precision,
  "gm" double precision,
  "gm_ttm" double precision,
  "gm_last" double precision,
  "om" double precision,
  "om_ttm" double precision,
  "om_last" double precision,
  "pm" double precision,
  "pm_ttm" double precision,
  "pm_last" double precision,
  "mcap" double precision,
  "sma20" double precision,
  "sma50" double precision,
  "sma200" double precision,
  "rsi14" double precision,
  "macd" double precision,
  "der" double precision,
  "der_last" double precision,
  "nd_ebitda" double precision,
  "nd_ebitda_ttm" double precision,
  "nd_ebitda_last" double precision,
  "dpr" double precision,
  "roic" double precision,
  "roic_ttm" double precision,
  "roic_last" double precision,
  "peg" double precision,
  "peg_ttm" double precision,
  "peg_last" double precision,
  "pre_peg" double precision,
  "pre_peg_ttm" double precision,
  "pre_peg_last" double precision,
  "time" time without time zone,
  "date" date,
  CONSTRAINT keyratios_pk PRIMARY KEY ("insref")
);

CREATE TABLE greeks (
  "insref" numeric(20) NOT NULL,
  "iv" double precision,
  "ivbid" double precision,
  "ivask" double precision,
  "delta" double precision,
  "gamma" double precision,
  "rho" double precision,
  "theta" double precision,
  "vega" double precision,
  "time" time without time zone,
  "date" date,
  CONSTRAINT greeks_pk PRIMARY KEY ("insref")
);

CREATE TABLE newscoding (
  "newsref" numeric(20) NOT NULL,
  "newsid" character(36) NOT NULL,
  "isin" character(12) NOT NULL,
  "company" numeric(20) NOT NULL,
  "date" date,
  CONSTRAINT newscoding_pk PRIMARY KEY ("newsid","newsref","isin","company")
);
CREATE INDEX idx_newscoding ON newscoding ("isin","newsid");
CREATE INDEX idx_newscoding2 ON newscoding ("company","newsid");

CREATE TABLE newstags (
  "newsref" numeric(20) NOT NULL,
  "newsid" character(36) NOT NULL,
  "tag" character(30) NOT NULL,
  "date" date NOT NULL,
  CONSTRAINT newstags_pk PRIMARY KEY ("newsid","newsref","tag")
);
CREATE INDEX idx_newstags ON newstags ("tag","newsid");

CREATE TABLE noii (
  "insref" numeric(20) NOT NULL,
  "bidprice" double precision,
  "askprice" double precision,
  "bidquantity" double precision,
  "askquantity" double precision,
  "lastprice" double precision,
  "quantity" double precision,
  "imbalance" double precision,
  "direction" smallint NULL,
  "type" smallint NULL,
  "time" time without time zone,
  "date" date,
  CONSTRAINT noii_pk PRIMARY KEY ("insref")
);

CREATE TABLE constituents (
  "insref" numeric(20) NOT NULL,
  "constituent" numeric(20) NOT NULL,
  "weight" double precision,
  "isin" character varying(12),
  "currency" character varying(4),
  CONSTRAINT constituents_pk PRIMARY KEY ("insref","constituent")
);

CREATE INDEX idx_constituents ON constituents ("constituent");

CREATE TABLE ticksize (
  "insref" numeric(20) NOT NULL,
  "threshold" double precision NOT NULL,
  "increment" double precision NOT NULL,
  CONSTRAINT ticksize_pk PRIMARY KEY ("insref","threshold")
);

CREATE TABLE l10n (
  "insref" numeric(20) NOT NULL,
  "language" character(2) NOT NULL,
  "name" character varying(255),
  "shortdescription" character varying(512),
  "description" text,
  "importantevents" text,
  "prospectus" text,
  "kiid" text,
  "priipkid" text,
  Past_Performance_Link text,
  Previous_Performance_Scenarios_Calculation_Link text,
  "sustaindescription" text,
  "sustaininvesting1" text,
  "sustaininvesting2" text,
  "sustaindivesting1" text,
  "sustaindivesting2" text,
  "sustaininfluence" text,
  "sustainmonitoring1" text,
  "sustainmonitoring2" text,
  "sustaincomment" text,
  Comprehension_Alert_Portfolio character(1),
  Intended_target_market_retail_investor_Portfolio character varying(4000),
  Investment_objective_Portfolio character varying(8000),
  Risk_narrative_Portfolio character varying(300),
  Other_materially_relevant_risk_narrative_Portfolio character varying(200),
  Type_of_underlying_Investment_Option character varying(300),
  Capital_Guarantee character(1),
  Capital_Guarantee_Level double precision,
  Capital_Guarantee_Limitations character varying(300),
  Capital_Guarantee_Early_Exit_Conditions date,
  Capital_guarantee_Portfolio character varying(2500),
  Possible_maximum_loss_Portfolio double precision,
  Description_Past_Interval_Unfavourable_Scenario character varying(300),
  Description_Past_Interval_Moderate_Scenario character varying(300),
  Description_Past_Interval_Favourable_Scenario character varying(300),
  Portfolio_Performance_Fees_Narrative character varying(300),
  Portolio_Carried_Interest_Narrative character varying(300),
  One_Off_Cost_Portfolio_Entry_Cost_Description character varying(300),
  One_Off_Cost_Portfolio_Exit_Cost_Description character varying(300),
  Ongoing_Costs_Portfolio_Management_Costs_Description character varying(150),
  Cost_Dependence_Explanation character varying(150),
  Other_comment text default NULL,
  "date" date,
  CONSTRAINT l10n_pk PRIMARY KEY ("insref","language")
);

CREATE TABLE brokers (
  "insref" numeric(20) NOT NULL,
  "symbol" character varying(255) NOT NULL,
  "name" character varying(255) NOT NULL,
  CONSTRAINT brokers_pk PRIMARY KEY ("insref","symbol")
);

CREATE TABLE ci (
  "insref" numeric(20) NOT NULL,
  "type" smallint NOT NULL,
  "subtype" smallint,
  "sequence" integer NOT NULL,
  "s1" character varying(255),
  "s2" character varying(255),
  "s3" character varying(255),
  "s4" character varying(255),
  "s5" character varying(255),
  "s6" character varying(255),
  "s7" character varying(255),
  "s8" character varying(255),
  "s9" character varying(255),
  "s10" character varying(255),
  "s11" character varying(255),
  "s12" character varying(255),
  "s13" character varying(255),
  "s14" character varying(255),
  "s15" character varying(255),
  "n1" double precision,
  "n2" double precision,
  "n3" double precision,
  "n4" double precision,
  "n5" double precision,
  "n6" double precision,
  "n7" double precision,
  "n8" double precision,
  "n9" double precision,
  "n10" double precision,
  "i1" integer,
  "i2" integer,
  "i3" integer,
  "i4" integer,
  "i5" integer,
  "i6" integer,
  "i7" integer,
  "i8" integer,
  "i9" integer,
  "i10" integer,
  "insref1" numeric(20),
  "insref2" numeric(20),
  "insref3" numeric(20),
  "insref4" numeric(20),
  "insref5" numeric(20),
  "d1" date,
  "d2" date,
  "d3" date,
  "eventlink" character(36),
  "eventlinklanguages" character varying(255),
  "eventstatus" smallint,
  "lastmodified" timestamp without time zone,
  CONSTRAINT ci_pk PRIMARY KEY ("insref","type","sequence")
);

CREATE TABLE cihistory (
  "insref" numeric(20) NOT NULL,
  "type" smallint NOT NULL,
  "subtype" smallint,
  "sequence" integer NOT NULL,
  "date" date NOT NULL,
  "s1" character varying(255),
  "s2" character varying(255),
  "s3" character varying(255),
  "s4" character varying(255),
  "s5" character varying(255),
  "s6" character varying(255),
  "s7" character varying(255),
  "s8" character varying(255),
  "s9" character varying(255),
  "s10" character varying(255),
  "s11" character varying(255),
  "s12" character varying(255),
  "s13" character varying(255),
  "s14" character varying(255),
  "s15" character varying(255),
  "n1" double precision,
  "n2" double precision,
  "n3" double precision,
  "n4" double precision,
  "n5" double precision,
  "n6" double precision,
  "n7" double precision,
  "n8" double precision,
  "n9" double precision,
  "n10" double precision,
  "i1" integer,
  "i2" integer,
  "i3" integer,
  "i4" integer,
  "i5" integer,
  "i6" integer,
  "i7" integer,
  "i8" integer,
  "i9" integer,
  "i10" integer,
  "insref1" numeric(20),
  "insref2" numeric(20),
  "insref3" numeric(20),
  "insref4" numeric(20),
  "insref5" numeric(20),
  "d1" date,
  "d2" date,
  "d3" date,
  "eventlink" character(36),
  "eventlinklanguages" character varying(255),
  "eventstatus" smallint,
  "lastmodified" timestamp without time zone,
  CONSTRAINT cihistory_pk PRIMARY KEY ("insref","type","sequence","date")
);

CREATE TABLE "priip" (
	insref numeric(20) NOT NULL,
	EPT_Version character varying(3),
	EPT_Producer_Name character varying(255),
	EPT_Producer_Email character varying(255),
	File_Generation_Date_And_Time timestamp without time zone,
	EPT_Data_Reporting_Narratives character(1),
	EPT_Data_Reporting_Costs character(1),
	EPT_Data_Reporting_Additional_Requirements_German_MOPs character(1),
	EPT_Additional_Information_Structured_Products character(1),
	Portfolio_Issuer_Name character varying(255),
	Portfolio_Manufacturer_Group_Name character varying(255),
	Portfolio_Manufacturer_LEI character varying(20),
	Portfolio_Manufacturer_Email character varying(255),
	Portfolio_Guarantor_Name character varying(255),
	Portfolio_Identifying_Data character varying(255),
	Type_Of_Identification_Code_For_The_Fund_Share_Or_Portfolio smallint,
	Portfolio_Name character varying(255),
	Share_Class_Currency character(3),
	Reference_Date date,
	PRIIPs_KID_Web_Address text,
	Portfolio_PRIIPS_Category smallint,
	Fund_CIC_code character(4),
	Is_An_Autocallable_Product character(1),
	EOS_portfolio character(1),
	Valuation_Frequency smallint,
	Portfolio_VEV_Reference double precision,
	IS_Flexible character(1),
	Flex_VEV_Historical double precision,
	Flex_VEV_Ref_Asset_Allocation double precision,
	IS_Risk_Limit_Relevant character(1),
	Flex_VEV_Risk_Limit double precision,
	Existing_Credit_Risk character(1),
	SRI smallint,
	IS_SRI_Adjusted character(1),
	MRM smallint,
	CRM smallint,
	Recommended_Holding_Period double precision,
	Has_A_Contractual_Maturity_Date character(1),
	Maturity_Date date,
	Liquidity_Risk character(1),
	Portfolio_return_unfavorable_scenario_1_year double precision,
	Portfolio_return_unfavorable_scenario_half_RHP double precision,
	Portfolio_return_unfavorable_scenario_RHP double precision,
	Autocall_Applied_Unfavourable_Scenario character(1),
	Autocall_Date_Unfavourable_Scenario date,
	Portfolio_return_moderate_scenario_1_year double precision,
	Portfolio_return_moderate_scenario_half_RHP double precision,
	Portfolio_return_moderate_scenario_RHP double precision,
	Autocall_Applied_Moderate_Scenario character(1),
	Autocall_Date_Moderate_Scenario date,
	Portfolio_return_favorable_scenario_1_year double precision,
	Portfolio_return_favorable_scenario_half_RHP double precision,
	Autocall_Applied_Favourable_Scenario character(1),
	Autocall_Date_Favourable_Scenario date,
	Portfolio_return double precision,
	Portfolio_return_stress_scenario_1_year double precision,
	Portfolio_return_stress_scenario_half_RHP double precision,
	Portfolio_return_stress_scenario_RHP double precision,
	Autocall_Applied_Stress_Scenario character(1),
	Autocall_Date_Stress_Scenario date,
	Portfolio_number_of_observed_return_M0 double precision,
	Portfolio_mean_observed_returns_M1 double precision,
	Portfolio_observed_Sigma double precision,
	Portfolio_observed_Skewness double precision,
	Portfolio_observed_Excess_Kurtosis double precision,
	Portfolio_observed_Stressed_Volatility double precision,
	Portfolio_Past_Performance_Disclosure_Required character(1),
	Past_Performance_Link text,
	Previous_Performance_Scenarios_Calculation_Link text,
	Past_Performance_Number_Of_Years smallint,
	Reference_Invested_Amount double precision,
	One_off_cost_Portfolio_entry_cost double precision,
	One_off_cost_Portfolio_entry_cost_Acquired double precision,
	One_off_costs_Portfolio_exit_cost_at_RHP double precision,
	One_off_costs_Portfolio_exit_cost_at_1_year double precision,
	One_off_costs_Portfolio_exit_cost_at_half_RHP double precision,
	One_off_costs_Portfolio_sliding_exit_cost_Indicator character(1),
	Ongoing_costs_Portfolio_other_costs double precision,
	Ongoing_costs_Portfolio_management_costs double precision,
	Ongoing_costs_Portfolio_transaction_costs double precision,
	Existing_performance_fees character(1),
	Incidental_costs_Portfolio_performance_fees double precision,
	Existing_carried_interest_fees character(1),
	Incidental_costs_Portfolio_carried_interest double precision,
	Reference_Language character(2),
	Comprehension_Alert_Portfolio character(1),
	Intended_target_market_retail_investor_Portfolio character varying(4000),
	Investment_objective_Portfolio character varying(8000),
	Risk_narrative_Portfolio character varying(300),
	Other_materially_relevant_risk_narrative_Portfolio character varying(200),
	Type_of_underlying_Investment_Option character varying(300),
	Capital_Guarantee character(1),
	Capital_Guarantee_Level double precision,
	Capital_Guarantee_Limitations character varying(300),
	Capital_Guarantee_Early_Exit_Conditions date,
	Capital_guarantee_Portfolio character varying(2500),
	Possible_maximum_loss_Portfolio double precision,
	Description_Past_Interval_Unfavourable_Scenario character varying(300),
	Description_Past_Interval_Moderate_Scenario character varying(300),
	Description_Past_Interval_Favourable_Scenario character varying(300),
	Was_Benchmark_Used_Performance_Calculation character(1),
 	Portfolio_Performance_Fees_Narrative character varying(300),
	Portolio_Carried_Interest_Narrative character varying(300),
	One_Off_Cost_Portfolio_Entry_Cost_Description character varying(300),
	One_Off_Cost_Portfolio_Exit_Cost_Description character varying(300),
	Ongoing_Costs_Portfolio_Management_Costs_Description character varying(150),
	Do_Costs_Depend_On_Invested_Amount character(1),
	Cost_Dependence_Explanation character varying(150),
	German_MOPs_Reference_Date date,
	Other_comment text default NULL,
	PRIIP_data_delivery character(1),
	UCITS_data_delivery character(1),
	Portfolio_UCITS_SRRI smallint,
	Portfolio_UCITS_Vol double precision,
	Ongoing_costs_Portfolio_other_costs_UCITS double precision,
	Ongoing_costs_Portfolio_transaction_costs_UCITS double precision,
	Transactions_costs_methodology character varying(255),
	Incidental_costs_Portfolio_performance_fees_UCITS double precision,
	Incidental_costs_Portfolio_carried_interest_UCITS double precision,
	UCITS_KID_Web_Address text default NULL,
	Bonds_Weight double precision,
	Annualized_Return_Volatility double precision,
	Duration_Bonds double precision,
	Existing_Capital_Preservation character(1),
	Capital_Preservation_Level double precision,
	Time_Interval_Maximum_Loss character varying(10),
	Uses_PI character(1),
	Multiplier_PI double precision,
	First_Possible_Call_Date date,
	Total_cost_1_year double precision,
	RIY_1_year double precision,
	Total_cost_half_RHP double precision,
	RIY_half_RHP double precision,
	Total_cost_RHP double precision,
	RIY_RHP double precision,
	One_off_costs_Portfolio_entry_cost_RIY double precision,
	One_off_costs_Portfolio_exit_cost_RIY double precision,
	Ongoing_costs_Portfolio_transaction_costs_RIY double precision,
	Ongoing_costs_Other_ongoing_costs_RIY double precision,
	Incidental_costs_Portfolio_performance_fees_RIY double precision,
	Incidental_costs_Portfolio_carried_interests_RIY double precision,
	lastmodified timestamp without time zone,
	CONSTRAINT priip_pk PRIMARY KEY ("insref")
);

CREATE TABLE "mifid" (
	insref numeric(20) NOT NULL,
	fisn character varying(35),
	lei character(20),
	EMT_Version character(4),
	EMT_Producer_Name character varying(255),
	EMT_Producer_LEI character(20),
	EMT_Producer_Email character varying(255),
	File_Generation_Date_and_Time timestamp without time zone,
	EMT_Data_Reporting_Target_Market character(1),
	EMT_Data_Reporting_ExAnte character(1),
	EMT_Data_Reporting_ExPost character(1),
	Financial_Instrument_Identifying_Data character varying(255),
	Type_Of_Identification_Code_For_The_Financial_Instrument smallint,
	Financial_Instrument_Name character varying(255),
	Financial_Instrument_Currency character(3),
	Financial_Instrument_Performance_Fee character(1),
	Financial_Instrument_Distribution_Of_Cash character(1),
	Reporting_Date date,
	Financial_Instrument_Legal_Structure character varying(2),
	Financial_Instrument_Issuer_Name character varying(255),
	Financial_Instrument_Manufacturer_LEI character varying(20),
	Financial_Instrument_Manufacturer_Email character varying(255),
	Financial_Instrument_Manufacturer_Product_Governance_Process character(1),
	Financial_Instrument_Guarantor_Name character varying(255),
	Financial_Instrument_Type_Notional_or_Item_Based character(1),
	Product_Category_or_Nature character varying(255),
	Structured_Securities_Product_Category_or_Nature integer,
	Structured_Securities_Quotation character(1),
	Leveraged_Financial_Instrument_or_Contingent_LiabilityInstrumen character(1),
	Fund_Share_Class_Without_Retrocession character(1),
	Ex_Post_Cost_Calculation_Basis_Italy character(1),
	Target_Market_Reference_Date date,
	Investor_Type_Retail character(1),
	Investor_Type_Professional character(1),
	Investor_Type_Eligible_Counterparty character(1),
	Basic_Investor character(1),
	Informed_Investor character(1),
	Advanced_Investor character(1),
	Expert_Investor_Germany character(1),
	No_Capital_Loss character(1),
	Limited_Capital_Loss character(1),
	Limited_Capital_Loss_Level double precision,
	No_Capital_Guarantee character(1),
	Loss_Beyond_Capital character(1),
	Risk_Tolerance_PRIIPS_Methodology smallint,
	Risk_Tolerance_UCITS_Metholodology smallint,
	Risk_Tolerance_Internal_Methodology_For_Non_PRIIPS_and_NonUCITS character(1),
	Risk_Tolerance_For_Non_PRIIPS_and_Non_UCITS_Spain smallint,
	Not_For_Investors_With_The_Lowest_Risk_Tolerance_Germany character(1),
	Return_Profile_Preservation character(1),
	Return_Profile_Growth character(1),
	Return_Profile_Income character(1),
	Return_Profile_Hedging character(1),
	Option_or_Leveraged_Return_Profile character(1),
	Return_Profile_Other character(1),
	Return_Profile_Pension_Scheme_Germany character(1),
	Time_Horizon1 character(1),
	Time_Horizon2 double precision,
	Maturity_Date date,
	May_Be_Terminated_Early character(1),
	Intended_Compatible_With_Clients_Having_ESG_Preferences character(1),
	Specific_Investment_Need character(1),
	Other_Specific_Investment_Need character(1),
	Execution_Only character(1),
	Execution_With_Appropriateness_Test_Or_Non_Advised_Services character(1),
	Investment_Advice character(1),
	Portfolio_Management character(1),
	OO_Financial_Instrument_entry_cost double precision,
	Net_OO_cost_Financial_Instrument_entry_cost_non_acquired double precision,
	OO_Financial_Instrument_maximum_entry_cost_fixed_amount_Italy double precision,
	OO_Financial_Instrument_maximum_entry_cost_acquired double precision,
	OO_Financial_Instrument_maximum_exit_cost double precision,
	OO_Financial_Instrument_maximum_exit_cost_fixed_amount_Italy double precision,
	OO_Financial_Instrument_maximum_exit_cost_acquired double precision,
	OO_Financial_Instrument_Typical_exit_cost double precision,
	OO_Financial_Instrument_exit_cost_structrd_securities_prior_RHP double precision,
	Financial_Instrument_Ongoing_costs double precision,
	Financial_Instrument_Gearing_costs_ex_ante_UK double precision,
	Financial_Instrument_Management_fee double precision,
	Financial_Instrument_Distribution_fee double precision,
	Financial_Instrument_Transaction_costs_ex_ante double precision,
	Financial_Instrument_Incidental_costs_ex_ante double precision,
	Structured_Securities_Reference_Price_ex_ante double precision,
	Structured_Securities_Notional_Reference_Amount_ex_ante double precision,
	Ex_Ante_Costs_Reference_Date date,
	OO_Structured_Securities_entry_cost_ex_post double precision,
	Net_OO_cost_Structured_Securities_entry_cost_ex_post double precision,
	OO_Structured_Securities_exit_cost_ex_post double precision,
	OO_cost_Financial_Instrument_entry_cost_acquired double precision,
	Financial_Instrument_Ongoing_costs_ex_post double precision,
	Structured_Securities_Ongoing_costs_ex_post_accumulated double precision,
	Financial_Instrument_Borrowing_Costs_Ex_Post_UK double precision,
	Financial_Instrument_Management_fee_ex_post double precision,
	Financial_Instrument_Distribution_fee_ex_post double precision,
	Financial_Instrument_Transaction_costs_ex_post double precision,
	Financial_Instrument_Incidental_costs_ex_post double precision,
	Beginning_Of_Calculation_Period date,
	End_Of_Calculation_Period date,
	Structured_Securities_Reference_Price_ex_post double precision,
	Structured_Securities_Notional_Reference_Amount double precision,
	lastmodified timestamp without time zone,
	CONSTRAINT mifid_pk PRIMARY KEY ("insref")
);

CREATE TABLE "mifidhistory" (
	insref numeric(20) NOT NULL,
	Reporting_Date date,
	OO_Structured_Securities_entry_cost_ex_post double precision,
	Net_OO_cost_Structured_Securities_entry_cost_ex_post double precision,
	OO_Structured_Securities_exit_cost_ex_post double precision,
	OO_cost_Financial_Instrument_entry_cost_acquired double precision,
	Financial_Instrument_Ongoing_costs_ex_post double precision,
	Structured_Securities_Ongoing_costs_ex_post_accumulated double precision,
	Financial_Instrument_Borrowing_Costs_Ex_Post_UK double precision,
	Financial_Instrument_Management_fee_ex_post double precision,
	Financial_Instrument_Distribution_fee_ex_post double precision,
	Financial_Instrument_Transaction_costs_ex_post double precision,
	Financial_Instrument_Incidental_costs_ex_post double precision,
	Beginning_Of_Calculation_Period date,
	End_Of_Calculation_Period date,
	Structured_Securities_Reference_Price_ex_post double precision,
	Structured_Securities_Notional_Reference_Amount double precision,
	lastmodified timestamp without time zone,
	CONSTRAINT mifidhistory_pk PRIMARY KEY (insref, Reporting_Date)
);

CREATE TABLE "underlyings" (
	"insref" numeric(20) NOT NULL,
	"isin" character varying(12) NOT NULL,
	"currency" character varying(4),
	CONSTRAINT underlyings_pk PRIMARY KEY ("insref","isin")
);

CREATE INDEX idx_underlyings ON underlyings ("isin");

CREATE TABLE "sectors" (
	"insref" numeric(20) NOT NULL,
	"sector" numeric(20) NOT NULL,
	"marketplace" numeric(20) NOT NULL,
	CONSTRAINT sectors_pk PRIMARY KEY ("insref","sector")
);
CREATE INDEX idx_sectora ON sectors ("sector", "marketplace");

CREATE TABLE combolegs
(
  "insref" numeric(20) NOT NULL,
  "leg" numeric(20) NOT NULL,
  "ratio" integer,
  "side" smallint,
  CONSTRAINT combolegs_pk PRIMARY KEY ("insref","leg")
);

CREATE TABLE aggtrades
(
  "insref" numeric(20) NOT NULL,
  "openprice" double precision,
  "highprice" double precision,
  "lowprice" double precision,
  "closeprice" double precision,
  "openyield" double precision,
  "highyield" double precision,
  "lowyield" double precision,
  "closeyield" double precision,
  "quantity" double precision,
  "turnover" double precision,
  "time" timestamp without time zone NOT NULL,
  CONSTRAINT aggtrades_pk PRIMARY KEY ("insref","time")
);

