|Data provider||Write||Finbourne||Provided with LUSID|
Lusid.PortfolioGroup.Writer provider enables you to write a Luminesce SQL query that either creates, updates or deletes portfolio groups in LUSID, and also adds and removes portfolios and sub-groups.
Note: The LUSID user running the query must have sufficient access control permissions to both use the provider and modify portfolio and portfolio group data stored in LUSID. This should automatically be the case if you are the domain owner.
You must construct a valid table of data to write, one portfolio group or portfolio per record, depending on the operation.
Lusid.PortfolioGroup.Writer lists the fields (columns) available to populate with values for each record, and has a set of parameters to help you construct a valid table.
Your query can use the
WriteAction field to perform one of the following operations:
- Upsert a portfolio group; that is, create a portfolio group if it does not exist, and update certain fields if it does. This is the default operation if you omit
- Delete a portfolio group.
- Add a portfolio or a sub-group to a portfolio group.
- Remove a portfolio or a sub-group from a portfolio group.
See also: Lusid.PortfolioGroup
@table_of_data = <select-statement>; select * from Lusid.PortfolioGroup.Writer where toWrite = @table_of_data;
Lusid.PortfolioGroup.Writer has parameters that help you construct a valid table of data to write.
toWrite parameter is mandatory and used to actually write the table of data into LUSID.
To list available parameters, their data types, default values, and an explanation for each, run the following query using a suitable tool:
select FieldName, DataType, ParamDefaultValue, Description from Sys.Field where TableName = 'Lusid.PortfolioGroup.Writer' and FieldType = 'Parameter';
Lusid.PortfolioGroup.Writer lists the fields you can populate in your table of data to write.
Depending on the operation you want to perform, the following fields are mandatory to include in the table of data:
|Operation||Specify using...||Mandatory fields||Notes|
|Update||You can only update |
To list all available fields, their data types, whether fields are considered 'main', and an explanation for each, run the following query using a suitable tool:
select FieldName, DataType, IsMain, IsPrimaryKey, SampleValues, Description from Sys.Field where TableName = 'Lusid.PortfolioGroup.Writer' and FieldType = 'Column';
We recommend examining the results of every write query using one or more of the
For each record in the table of data to write,
Lusid.PortfolioGroup.Writer returns an error code. If the operation is successful, the error code is
0. If unsuccessful, a positive error code and explanation help you discover why LUSID considers the operation invalid.
Note: For more example Luminesce SQL queries, visit our Github repo.
The examples in this section refer to the following portfolio group structure. For simplicity, all the portfolio groups and portfolios are in the same
Ibor scope; the label in each box represents the code:
Example 1: Create portfolio groups
This query creates three portfolio groups, without structure. It defaults to an upsert operation as no explicit
WriteAction is specified.
@@scope = select 'Ibor'; @portfolio_groups = values ('Global', 'Global portfolio group', 'A portfolio group representing global operations'), ('NorthAmerica', 'North American portfolio group', 'A portfolio group representing NA operations'), ('EMEA', 'EMEA portfolio group', 'A portfolio group representing NA operations'); @data_to_write = select @@scope as TopGroupScope, column1 as TopGroupCode, column2 as TopGroupName, column3 as TopGroupDescription from @portfolio_groups; select * from Lusid.PortfolioGroup.Writer where ToWrite = @data_to_write;
Example 2: Add sub-groups to group
This query adds
EMEA as sub-groups to the
Global portfolio group:
@@scope = select 'Ibor'; @sub_groups = values ('NorthAmerica'), ('EMEA'); @data_to_write = select @@scope as TopGroupScope, 'Global' as TopGroupCode, @@scope as BottomGroupScope, column1 as BottomGroupCode, 'Add' as WriteAction from @sub_groups; select * from Lusid.PortfolioGroup.Writer where ToWrite = @data_to_write;
Example 3: Add portfolios to groups
This query adds (pre-existing) portfolios to the
EMEA sub-groups, creating the structure at the top of this section.
@@scope = select 'Ibor'; @portfolios = values ('Canada', 'NorthAmerica'), ('US', 'NorthAmerica') ('UK', 'EMEA') ('France', 'EMEA') ('Spain', 'EMEA'); @data_to_write = select @@scope as TopGroupScope, column2 as TopGroupCode, @@scope as PortfolioScope, column1 as PortfolioCode, 'Add' as WriteAction from @portfolios; select * from Lusid.PortfolioGroup.Writer where ToWrite = @data_to_write;