-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy path7-run-valuation-with-srs.sql
42 lines (35 loc) · 1.52 KB
/
7-run-valuation-with-srs.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
-- ============================================================
-- Description:
-- In this file, we run a valuation using the data which was
-- previously loaded, including valuations from SRS
-- You also need a recipe which is setup by the _data/setup.py file.
-- ============================================================
-- Select some metrics to be returned by the valuation engine
@measure =
select 'Instrument/default/Name' as MeasureName, 'Value' as Operation union
select 'Valuation/PV/Ccy' as MeasureName, 'Value' as Operation union
select 'Valuation/PV/Amount' as MeasureName, 'Sum' as Operation union
select 'UnitResult/External-MarketValue' as MeasureName, 'Sum' as Operation; -- retrieved from SRS
-- Run the valuation for a given recipe, portfolio and date
@vals =
select *
from lusid.portfolio.valuation
where PortfolioCode = 'uk-equity'
and PortfolioScope = 'ibor'
and Recipe = 'ibor/market-value'
and MeasuresToReturn = @measure
and EffectiveAt = '2020-08-24T09:00:00.000Z';
-- Pivot the values into a traditional report format
@vals_formatted =
use Tools.Pivot with @vals
--key=MeasureName
--aggregateColumns=MeasureDecimalValue,MeasureStringValue
enduse;
select
PortfolioCode as 'Portfolio',
ValuationDate as 'Val Date',
[Instrument/default/Name_MeasureStringValue] as 'InstrumentName',
[Valuation/PV/Ccy_MeasureStringValue] as 'Currency',
[Sum(Valuation/PV/Amount)_MeasureDecimalValue] as 'MarketValue',
[Sum(UnitResult/External-MarketValue)_MeasureDecimalValue] as 'External-MarketValue'
from @vals_formatted;