Main Content

instget

Data from instrument variable

Description

example

Data = instget(InstSet,Name,Value) retrieves Data from an instrument variable.

Examples

collapse all

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)
Index Type   Strike Price Opt  Contracts
1     Option  95    12.2  Call     0    
2     Option 100     9.2  Call     0    
3     Option 105     6.8  Call  1000    
 
Index Type    Delivery       F     Contracts
4     Futures 01-Jul-1999    104.4 -1000    
 
Index Type   Strike Price Opt  Contracts
5     Option 105     7.4  Put  -1000    
6     Option  95     2.9  Put      0    
 
Index Type  Price Maturity       Contracts
7     TBill 99    01-Jul-1999    6        
 

Extract the price from all instruments.

P = instget(ExampleInst,'FieldName','Price')
P = 7×1

   12.2000
    9.2000
    6.8000
       NaN
    7.4000
    2.9000
   99.0000

Get all the prices and the number of contracts held.

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

   12.2000
    9.2000
    6.8000
       NaN
    7.4000
    2.9000
   99.0000

C = 7×1

           0
           0
        1000
       -1000
       -1000
           0
           6

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

V = P.*C 
V = 7×1

           0
           0
        6800
         NaN
       -7400
           0
         594

ISet = instsetfield(ExampleInst, 'FieldName', 'Value', 'Data',V); 
instdisp(ISet) 
Index Type   Strike Price Opt  Contracts Value
1     Option  95    12.2  Call     0         0
2     Option 100     9.2  Call     0         0
3     Option 105     6.8  Call  1000      6800
 
Index Type    Delivery       F     Contracts Value
4     Futures 01-Jul-1999    104.4 -1000     NaN  
 
Index Type   Strike Price Opt  Contracts Value
5     Option 105     7.4  Put  -1000     -7400
6     Option  95     2.9  Put      0         0
 
Index Type  Price Maturity       Contracts Value
7     TBill 99    01-Jul-1999    6         594  
 

Look at only the instruments that have nonzero Contracts.

Ind = find(C ~= 0)
Ind = 4×1

     3
     4
     5
     7

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'})
T = 4x7 char array
    'Option '
    'Futures'
    'Option '
    'TBill  '

O = 4x4 char array
    'Call'
    '    '
    'Put '
    '    '

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

rstring = [T, O, num2str(V(Ind))] 
rstring = 4x16 char array
    'Option Call 6800'
    'Futures      NaN'
    'Option Put -7400'
    'TBill        594'

Input Arguments

collapse all

Instrument variable containing a collection of instruments, specified as InstSet structure. Instruments are classified by type; each type can have different data fields. The stored data field is a row vector or character vector for each instrument.

Data Types: struct

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: Data = instget(ExampleInst,'FieldName','Price')

Name of each data field for an instrument, specified as the comma-separated pair consisting of 'FieldName' and an NFIELDS-by-1 cell array of character vectors. FieldName entries can also be either Type or Index; these return type strings and index numbers respectively.

Data Types: char | cell

Number of instruments, specified as the comma-separated pair consisting of 'Index' and an NINST-by-1 vector of positions of instruments to work on. If Type is also entered, instruments referenced must be one of the types and contained in Index.

Data Types: double

Number of types, specified as the comma-separated pair consisting of 'Type' and a NTYPES-by-1 cell array of character vectors restricting instruments worked on to match one of Type types.

Data Types: char | cell

Output Arguments

collapse all

Data content, returned as an NINST-by-M array of data contents for the first field in FieldName. Each row corresponds to a separate instrument in the specified Index. Unavailable data is returned as NaN or as spaces.

Version History

Introduced before R2006a