-
Notifications
You must be signed in to change notification settings - Fork 14
/
5-run-reconciliation.sql
47 lines (43 loc) · 1.68 KB
/
5-run-reconciliation.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
-- ===============================================================
-- Description:
-- In this file, we run a reconciliation on three of the properties
-- ===============================================================
-- 1. Create a view of instruments with custom properties
-- Get data from LUSID
@instr_props =
select li.ClientInternal, li.DisplayName, PropertyCode, Value
from Lusid.Instrument.Property p
inner join Lusid.Instrument.SimpleInstrument li
on li.LusidInstrumentId = p.InstrumentId
where li.SimpleInstrumentType = 'Bonds'
and li.AssetClass = 'Credit'
and ((p.propertyscope = 'SourceA'
and p.propertycode in ('HoldingType', 'CountryIssue', 'GICSLevel1', 'InstrumentType'))
or
(p.propertyscope = 'SourceB'
and p.propertycode in ('holding_type', 'country_issue', 'gics_level_1', 'instrument_type'))) ;
-- Transform data using luminesce
@pivoted =
use Tools.Pivot with @instr_props
--key=PropertyCode
--aggregateColumns=Value
enduse;
-- 2. Run reconcilliation
select ClientInternal, DisplayName, case
when HoldingType = holding_type
then 'Reconciled: ' || HoldingType
else 'Break: ' || HoldingType || ' versus ' || holding_type
end as HoldingType, case
when CountryIssue = country_issue
then 'Reconciled: ' || CountryIssue
else 'Break: ' || CountryIssue || ' versus ' || country_issue
end as CountryIssue, case
when GICSLevel1 = gics_level_1
then 'Reconciled: ' || GICSLevel1
else 'Break: ' || GICSLevel1 || ' versus ' || gics_level_1
end as GICSLevel1
from @pivoted
where (
HoldingType is not null
and InstrumentType is not null
);