Type | Read/write | Author | Availability |
Write | Finbourne | Provided with LUSID |
Providing you have sufficient access control permissions, the Lusid.Portfolio.Writer
provider enables you to write a Luminesce SQL query that either creates, updates or deletes one or more LUSID portfolios.
Note: By default,
Lusid.Portfolio.Writer
cannot add properties to portfolios. To do this, you must first configureLusid.Portfolio.Writer
to 'inline' properties. See how to do this.
You must construct a valid table of data to write, one portfolio per record. Lusid.Portfolio.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; that is, create a portfolio if it does not exist, and update it if it does. This is the default operation if you omit
WriteAction
. You must specify thePortfolioType
field to declare either a transaction, derived transaction or reference portfolio.Insert (create) a portfolio. This operation fails if the portfolio already exists.
Update a portfolio. Note it is only possible to change the
DisplayName
andDescription
fields, or add or change properties. This operation fails if the portfolio does not already exist.Delete a portfolio.
See also: Lusid.Portfolio
Basic usage
@table_of_data = <select-statement>;
select * from Lusid.Portfolio.Writer where toWrite = @table_of_data;
Query parameters
Lusid.Portfolio.Writer
has parameters that help you construct a valid table of data to write.
Note: The 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.Portfolio.Writer' and FieldType = 'Parameter';
Data fields
Lusid.Portfolio.Writer
lists the fields you can populate in your table of data to write.
Depending on the operation you want to perform and the type of portfolio, the following fields are mandatory to include in the table of data:
Operation | Mandatory fields in table of data to write for all portfolios | Mandatory fields for transaction portfolios | Mandatory fields for derived transaction portfolios | Mandatory fields for reference portfolios |
Upsert, Insert |
|
|
|
|
Update |
|
|
|
|
Delete |
|
|
|
|
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.Portfolio.Writer' and FieldType = 'Column';
Write errors
We recommend examining the results of every write query using one or more of the WriteError
, WriteErrorCode
and WriteErrorDetail
fields.
For each record in the table of data to write, Lusid.Portfolio.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.
For example, the query:
@table_of_data = select 'Finbourne-Examples' as PortfolioScope, 'UK-Benchmark' as PortfolioCode, 'UK Benchmark Index' as DisplayName, #2020-01-01# as Created;
select WriteErrorCode, WriteError, WriteErrorDetail from Lusid.Portfolio.Writer where toWrite = @table_of_data;
...fails because a PortfolioType
is not specified.
Examples
Note: For more example Luminesce SQL queries, visit our Github repo.
Example 1: Create a transaction portfolio
If you omit the WriteAction
field, an upsert operation is performed.
@table_of_data = select 'Transaction' as PortfolioType, 'Finbourne-Examples' as PortfolioScope, 'FR-Equities' as PortfolioCode,
'French Equities' as DisplayName, 'Portfolio containing French equities' as Description, #2020-01-01# as Created, 'EUR' as BaseCurrency, '' as SubHoldingKeys;
select * from Lusid.Portfolio.Writer where ToWrite = @table_of_data;
Example 2: Create a derived transaction portfolio with a sub-holding key
@table_of_data = select 'DerivedTransaction' as PortfolioType, 'Finbourne-Examples' as PortfolioScope, 'Derived-UK-Equities' as PortfolioCode,
'Finbourne-Examples' as ParentPortfolioScope, 'UK-Equities' as ParentPortfolioCode, 'Derived UK Equities' as DisplayName,
'Derived portfolio containing UK equities' as Description, #2020-01-01# as Created, 'Transaction/Vendor/Strategy' as SubHoldingKeys;
select * from Lusid.Portfolio.Writer where ToWrite = @table_of_data;
Example 3: Create a reference portfolio with particular instrument scopes
@table_of_data = select 'Reference' as PortfolioType, 'Finbourne-Examples' as PortfolioScope, 'UK-Benchmark' as PortfolioCode, 'UK Benchmark' as DisplayName,
'Benchmark for UK equities' as Description, #2020-01-01# as Created, 'reference-instruments-1,reference-instruments-2' as InstrumentScopes;
select * from Lusid.Portfolio.Writer where ToWrite = @table_of_data;
Example 4: Update the name, description and a property on a transaction portfolio
Note that to update properties for portfolios, Lusid.Portfolio.Writer
must have been configured to 'inline' the chosen properties (in this case PortfolioManager
) into the standard set of portfolio fields.
@table_of_data = select 'Transaction' as PortfolioType, 'Finbourne-Examples' as PortfolioScope, 'FR-Equities' as PortfolioCode,
'Equities from France' as DisplayName, 'Portfolio containing equities from France' as Description, 'Rene Duclerc' as PortfolioManager, 'Update' as WriteAction;
select * from Lusid.Portfolio.Writer where ToWrite = @table_of_data;
Example 5: Delete a transaction portfolio
@table_of_data = select 'Transaction' as PortfolioType, 'Finbourne-Examples' as PortfolioScope, 'FR-Equities' as PortfolioCode, 'Delete' as WriteAction;
select * from Lusid.Portfolio.Writer where ToWrite = @table_of_data;