Type | Read/write | Author | Availability |
Write | Finbourne | Provided with LUSID |
Providing you have sufficient access control permissions, the Lusid.Portfolio.Holding.Writer
provider enables you to write a Luminesce SQL query that either sets, adjusts or cancels holdings adjustments in a LUSID transaction portfolio.
Note: By default,
Lusid.Portfolio.Holding.Writer
cannot add properties to holdings. To do this, you must first configureLusid.Portfolio.Holding.Writer
to 'inline' properties. See how to do this.
You must construct a valid table of data to write, one holding per record. Lusid.Portfolio.Holding.Writer
lists the fields (columns) available to populate with values for each record, and has parameters to help you construct a valid table.
Your query can use the WriteAction
field to perform one of the following operations:
Set holdings in a portfolio. Note that any existing holdings in the portfolio not included in the table of data to write are removed (reduced to zero).
Adjust holdings. No changes are made to existing holdings in the portfolio not included in the table of data to write.
Cancel holding adjustments (that is, undo) either of the above operations performed on a particular date.
Note that records with the same sub-holding keys that resolve to the same instrument are treated as tax lots, and all fields in these records must have matching values.
See also: Lusid.Portfolio.Holding
Basic usage
@table_of_data = <select-statement>;
select * from Lusid.Portfolio.Holding.Writer where ToWrite = @table_of_data;
Query parameters
Lusid.Portfolio.Holding.Writer
has parameters to 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.Holding.Writer' and FieldType = 'Parameter';
Data fields
Lusid.Portfolio.Holding.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 your table of data:
Operation | Specify using... | Mandatory fields for all operations | Mandatory fields for this operation |
Set holdings |
|
|
|
Adjust holdings |
| ||
Cancel adjustments (set or adjust) |
| n/a |
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.Holding.Writer' and FieldType = 'Column';
Note the following:
CostPrice
is the price per unit.CostAmount
andCostCurrency
are the total cost (price * units) in the transaction currencyCostAmountPortfolioCurrency
is the total cost in the portfolio base currency.
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.Holding.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, 'Cancel' as WriteAction;
select WriteErrorCode, WriteError, WriteErrorDetail from Lusid.Portfolio.Holding.Writer where ToWrite = @table_of_data;
...fails because there is no value for PortfolioCode
.
Examples
Note: For more example Luminesce SQL queries, visit our Github repo.
Example 1: Adjust a GBP cash holding
@table_of_data = select
'Finbourne-Examples' as PortfolioScope,
'UK-Equities' as PortfolioCode,
#2022-04-21# as EffectiveAt,
'CCY_GBP' as LusidInstrumentId,
100000 as Units,
'Adjust' as WriteAction
;
select * from Lusid.Portfolio.Holding.Writer where toWrite = @table_of_data;
Example 2: Set an equity holding, overwriting all other holdings
Note that 'Set' as WriteAction
does not perform an upsert operation but rather replaces the entire contents of the transaction portfolio with the new dataset. Any existing holdings not included in the new dataset are removed (reduced to zero).
Note also that, in this example, Strategy
is a transaction property that:
Has been defined as a sub-holding key for the portfolio.
Has been 'inlined' into the standard set of data fields for the provider by prior configuration of
Lusid.Portfolio.Holding.Writer
.
@@today = select Date('now');
@table_of_data = select
'Finbourne-Examples' as PortfolioScope,
'UK-Equities' as PortfolioCode,
@@today as EffectiveAt,
'BBG00WGHTKZ0' as Figi,
100 as Units,
12.3 as CostPrice,
'USD' as CostCurrency,
#2022-04-19# as PurchaseDate,
#2022-04-21# as SettleDate,
'QuantitativeSignal' as Strategy,
'Set' as WriteAction
;
select * from Lusid.Portfolio.Holding.Writer where toWrite = @table_of_data;
Example 3: Cancel adjustments made on a particular date
@table_of_data = select
'Finbourne-Examples' as PortfolioScope,
'UK-Equities' as PortfolioCode,
#2022-04-26# as EffectiveAt,
'Cancel' as WriteAction
;
select * from Lusid.Portfolio.Holding.Writer where toWrite = @table_of_data;