-
Notifications
You must be signed in to change notification settings - Fork 14
/
1-upload-instrumets.sql
64 lines (52 loc) · 2 KB
/
1-upload-instrumets.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
-- ============================================================
-- Description:
-- In this query we setup some instruments with a P/E property
-- and a Sector proprerty
-- NOTE: You'll need to have the properties setup as an instrument
-- properties in LUSID and Luminesce as follows:
-- Instrument/ibor/Sector
-- Instrument/Fundamentals/pe_ratio
-- ============================================================
@@Scope = select 'PriceEarningRatioScope';
@instruments_data =
use Drive.Excel
--file=/luminesce-examples/PEdata.xlsx
--worksheet=instrument
enduse;
-- 1. Upload values for custom instrument properties
@ids =
select inst_id as Id
from @instruments_data;
@inst_properties =
select li.LusidInstrumentId as EntityId, 'LusidInstrumentId' as EntityIdType, 'Instrument' as Domain, a.PropertyScope as PropertyScope, a.PropertyCode, a.
Value, @@Scope as EntityScope
from Lusid.Instrument li
inner join (
select 'pe_ratio' as PropertyCode, 'Fundamentals' as PropertyScope, pe_ratio as Value, inst_id as EntityId
from @instruments_data
) a
on li.ClientInternal = a.EntityId
where li.ClientInternal in @ids
union
select li.LusidInstrumentId as EntityId, 'LusidInstrumentId' as EntityIdType, 'Instrument' as Domain, a.PropertyScope as PropertyScope, a.PropertyCode, a.
Value, @@Scope as EntityScope
from Lusid.Instrument li
inner join (
select 'Sector' as PropertyCode, 'ibor' as PropertyScope, Sector as Value, inst_id as EntityId
from @instruments_data
) a
on li.ClientInternal = a.EntityId
where li.ClientInternal in @ids;
-- select * from @inst_properties
select *
from Lusid.Property.Writer
where ToWrite = @inst_properties;
-- 2. Upload instrument data to inbuilt properties
-- Transform equity data
@equity_instruments =
select inst_id as ClientInternal, name as DisplayName, ccy as DomCcy, @@Scope as Scope
from @instruments_data;
-- Write data to Lusid.Instrument.Equity. Print results of writing data to console.
select *
from Lusid.Instrument.Equity.Writer
where ToWrite = @equity_instruments;