Data from instrument variable
retrieves Data
= instget(InstSet
,Name,Value
)Data
from an 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)
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'
InstSet
— Instrument variableInstrument 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
Specify optional
comma-separated pairs of Name,Value
arguments. Name
is
the argument name and Value
is the corresponding value.
Name
must appear inside quotes. You can specify several name and value
pair arguments in any order as
Name1,Value1,...,NameN,ValueN
.
Data =
instget(ExampleInst,'FieldName','Price')
'FieldName'
— Name of each data field for instrument 'Index'
— Number of instrumentsNumber 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
'Type'
— Number of typesNumber 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
You have a modified version of this example. Do you want to open this example with your edits?