| Financial Derivatives Toolbox™ | ![]() |
[Data_1, Data_2,...,Data_n] = instget(InstSet,
'FieldName',
FieldList, 'Index', IndexSet, 'Type',
TypeList)
InstSet | Variable containing a collection of instruments. Instruments are classified by type; each type can have different data fields. The stored data field is a row vector or string for each instrument. |
FieldList | (Optional) String or number of fields (NFIELDS)-by-1 cell array of strings listing the name of each data field to match with data values. FieldList entries can also be either 'Type' or 'Index'; these return type strings and index numbers respectively. The default is all fields available for the returned set of instruments. |
(Optional) Number of instruments (NINST)-by-1 vector of positions of instruments to work on. If TypeList is also entered, instruments referenced must be one of TypeList types and contained in IndexSet. The default is all indices available in the instrument variable. | |
(Optional) String or number of types (NTYPES)-by-1 cell array of strings restricting instruments to match one of TypeList types. The default is all types in the instrument variable. |
Argument value pairs can be entered in any order. The InstSet variable must be the first argument.
[Data_1, Data_2,...,Data_n] = instget(InstSet, 'FieldName', FieldList, 'Index', IndexSet, 'Type', TypeList) retrieves data arrays from an instrument variable.
Data_1 is an NINST-by-M array of data contents for the first field in FieldList. Each row corresponds to a separate instrument in IndexSet. Unavailable data is returned as NaN or as spaces.
Data_n is an NINST-by-M array of data contents for the last field in FieldList.
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 =
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 =
12.2000
9.2000
6.8000
Nan
7.4000
2.9000
99.0000
C =
0
0
1000
-1000
-1000
0
6
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) 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 =
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 =
Option
Futures
Option
TBill
O =
Call
Put
Create a string report of holdings Type, Opt, and Value.
rstring = [T, O, num2str(V(Ind))] rstring = Option Call 6800 Futures NaN Option Put -7400 TBill 594
instaddfield, instdisp, instgetcell
![]() | instfloor | instgetcell | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |