%% Retrieve Data Arrays From Instrument Variable
% Retrieve the instrument set ExampleInst from the data file InstSetExamples.mat. ExampleInst contains three types of instruments: Option, Futures, and TBill.

load InstSetExamples; 
instdisp(ExampleInst)

% Extract the price from all instruments.

P = instget(ExampleInst,'FieldName','Price')

% Get all the prices and the number of contracts held.

[P,C] = instget(ExampleInst, 'FieldName', {'Price', 'Contracts'})

% Compute a value V. Create a new variable ISet that appends V to ExampleInst.

V = P.*C 
ISet = instsetfield(ExampleInst, 'FieldName', 'Value', 'Data',V); 
instdisp(ISet) 

% Look at only the instruments that have nonzero Contracts.

Ind = find(C ~= 0)

% Get the Type and Opt parameters from those instruments. (Only options have a stored 'Opt' field.)

[T,O] = instget(ExampleInst, 'Index', Ind, 'FieldName',{'Type', 'Opt'})

% Create a report of holdings Type, Opt, and Value.

rstring = [T, O, num2str(V(Ind))] 

% Copyright 2020 The MathWorks, Inc.