Lusid.Portfolio.Holding.Writer

Prev Next

Type

Read/write

Author

Availability

Data provider

Write

Finbourne

Provided with LUSID

The Lusid.Portfolio.Holding.Writer provider enables you to write a Luminesce SQL query that either sets, adjusts or cancels holdings in one or more portfolios.

Note: By default, Lusid.Portfolio.Holding.Writer cannot add properties to holdings. To do this, you must first configure Lusid.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. This is the default if you omit WriteAction.

  • Cancel holding adjustments (that is, undo) either of the above operations performed on a particular date. This cancels everything set or adjusted in the portfolio on that date.

  • Cancel the adjustment of one or more particular holdings on a particular date, leaving any other holdings adjusted on that date in place. This works only on a date on which holdings were adjusted, not set; see the example below.

LUSID processes each combination of portfolio and EffectiveAt in your table of data separately, in date order. This means:

  • If you set holdings on more than one date in the same query, LUSID performs a separate set on each date. Each one removes any holdings not included in the records for that date, including holdings you set on an earlier date in the same query.

  • All the records for the same portfolio and EffectiveAt must have the same WriteAction. For example, you cannot set some holdings and adjust others on the same date in the same query.

Note that records with the same sub-holding keys that resolve to the same instrument are treated as tax lots of one holding. These records must have the same CostCurrency and properties, and each must have a different combination of PurchaseDate, CostPrice and SettlementDate.

See also: Lusid.Portfolio.Holding, Lusid.Portfolio.HoldingAdjustment

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

'Set' as WriteAction

PortfolioScope, PortfolioCode,
EffectiveAt

  • If holding is a currency, the LUID (for example 'CCY_GBP' as LusidInstrumentId).

  • If any other instrument, a currency and at least one instrument identifier (for example 'USD' as CostCurrency, 'BBG00WGHTKZ0' as Figi)

Adjust holdings

'Adjust' as WriteAction (or omit WriteAction)

Cancel adjustments (set or adjust)

'Cancel' as WriteAction

N/A

Cancel the adjustment of a particular holding

'CancelAdjustment' as WriteAction

  • A currency and at least one instrument identifier, even if the holding is a currency (for example 'USD' as CostCurrency, 'CCY_USD' as LusidInstrumentId).

  • Any sub-holding keys of the holding.

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 and CostCurrency are the total cost in the transaction currency

  • CostAmountPortfolioCurrency is the total cost in the portfolio base currency.

  • PurchaseDate and SettlementDate are the original dates on which the holding (or tax lot) was acquired, if different from EffectiveAt. Make sure you use these exact field names; a field with a different name, such as SettleDate, is ignored without an error.

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. Note this means LUSID accepted the request, not necessarily that holdings changed. To check the result, query Lusid.Portfolio.HoldingAdjustment for the same portfolio and EffectiveAt.

If unsuccessful, a positive error code and explanation help you discover why LUSID considers the operation invalid.

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 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 SettlementDate,
 '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;

Example 4: Cancel the adjustment of a particular holding

In this example, you previously adjusted both a GBP and a USD cash holding on 21 April 2022, and now want to cancel only the USD adjustment. The GBP adjustment stays in place.

Identify each holding to cancel in the same way you identified it when you adjusted it, including any sub-holding keys. You can cancel several holdings at once by including one record for each.

@table_of_data = select
 'Finbourne-Examples' as PortfolioScope,
 'UK-Equities' as PortfolioCode,
 #2022-04-21# as EffectiveAt,
 'CCY_USD' as LusidInstrumentId,
 'USD' as CostCurrency,
 'CancelAdjustment' as WriteAction
;
select * from Lusid.Portfolio.Holding.Writer where toWrite = @table_of_data;

Note: CancelAdjustment has no effect on a date on which holdings were set rather than adjusted, even though the error code is 0. To change a set, cancel it using 'Cancel' as WriteAction and set the holdings again. To find out whether holdings were set or adjusted on a date, check the UnmatchedHoldingMethod field of Lusid.Portfolio.HoldingAdjustment.