Views:
TypeRead/writeAuthorAvailability
Data providerWriteFinbourneProvided with LUSID

The Lusid.Portfolio.Return.Writer provider enables you to write a Luminesce SQL query that either adds simple performance returns to a portfolio in LUSID, modifies existing returns, or deletes returns.

Note: The LUSID user running the query must have sufficient access control permissions to both use the provider and administer returns 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 return per record. Lusid.Portfolio.Return.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 perform either of the following operations:

  • Add new returns or modify existing ones. If a record in your table of data to write contains a return with the same EffectiveAt datetime as one that already exists in LUSID, then the existing return is updated. If not, a new return is added.
  • Delete returns between a date range. Note your table of data to write must contain the special WriteAction field with a value of Delete.

See also: Lusid.Portfolio.ReturnLusid.Portfolio.AggregatedReturn

Basic usage

@table_of_data = <select-statement>;
select * from Lusid.Portfolio.Return.Writer where ToWrite = @table_of_data;

Query parameters

Lusid.Portfolio.Return.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 data to 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.Return.Writer' and FieldType = 'Parameter';

Data fields

Lusid.Portfolio.Return.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:

OperationMandatory fields in table of data to write
Add new or modify existing returnsPortfolioScope, PortfolioCode, ReturnScope, ReturnCode, EffectiveAt, RateOfReturn, Period
Delete returnsPortfolioScope, PortfolioCode, ReturnScope, ReturnCode, Period, FromEffectiveAt, UntilEffectiveAt, 'Delete' as WriteAction

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.Return.Writer' and FieldType = 'Column';

Write errors

We recommend examining the results of every write query using one or more of the WriteErrorWriteErrorCode and WriteErrorDetail fields.

For each record in the table of data to write, Lusid.Portfolio.Return.Writer returns an error code. If a return is successfully added, modified or deleted, 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-Equities' as PortfolioCode, 'Production' as ReturnScope, 'Performance' as ReturnCode;
select WriteErrorCode, WriteError, WriteErrorDetail from Lusid.Portfolio.Return.Writer where ToWrite = @table_of_data;


...fails because adding a new return must include values for the EffectiveAt, RateOfReturn and Period fields.

Examples

Note: For more example Luminesce SQL queries, visit our Github repo.

Example 1: Add a new daily return to a particular portfolio

A new return is added providing a return with an identical EffectiveAt datetime does not already exist in LUSID.

Note that the Period field takes a value of either Daily or Monthly.

@@today = select DateTime('now');

@dailyReturn = select 'Finbourne-Examples' as PortfolioScope, 'UK-Equities' as PortfolioCode, 'Production' as ReturnScope, 'Performance' as ReturnCode,
'Daily' as Period, @@today as EffectiveAt, 120.0 as ClosingMarketValue, 0.1 as RateOfReturn;

select * from Lusid.Portfolio.Return.Writer where ToWrite = @dailyReturn;

Example 2: Delete all returns from the last week

Including 'Delete' as WriteAction in the table of data to write ensures a query performs a delete operation.

@@today = select Date('now');
@@oneWeekAgo = select Date('now', '-7 days');

@deleteReturns = select 'Finbourne-Examples' as PortfolioScope, 'UK-Equities' as PortfolioCode, 'Production' as ReturnScope, 'Performance' as ReturnCode,
'Daily' as Period, @@oneWeekAgo as FromEffectiveAt, @@today as UntilEffectiveAt, 'Delete' as WriteAction;

select * from Lusid.Portfolio.Return.Writer where ToWrite = @deleteReturns;