instget
Data from instrument variable
Description
retrieves Data
= instget(InstSet
,Name,Value
)Data
from an instrument variable.
Examples
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)
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
InstSet
— Instrument variable
structure
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')
FieldName
— Name of each data field for instrument
all fields available for returned set of instruments (default) | cell array of character vectors
Index
— Number of instruments
all indices available in instrument variable (default) | vector
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
Type
— Number of types
all types in the instrument variable (default) | character vector
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
Version History
Introduced before R2006a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)