Add new instruments to instrument collection
adds instruments to an existing instrument set InstSetNew
= instaddfield(InSet
,Name,Value
)InstSet
. The output
InstSetNew
is a new instrument set containing the input data.
creates an instrument variable InstSet
= instaddfield(Name,Value
)InstSet
.
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
.
InstSet =
instaddfield('Type','Option','FieldName',{'Strike','Price','Opt'},'Data',{Strike,CallP,'Call'})
'FieldName'
— Name of each data field for instrument 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.
Data Types: char
| cell
'Data'
— Data contents for each fieldData contents for each field, specified as the comma-separated pair consisting of
'Data'
and an NINST
-by-M
array or NFIELDS
-by-1
cell array.
Data Types: double
| cell
'FieldClass'
— Data class of each fieldData class of each field, specified as the comma-separated pair consisting of
'FieldClass'
and an
NFIELDS
-by-1
cell array of character vectors.
Data Types: char
| cell
'Type'
— Type of instrument addedType of instrument added, specified as the comma-separated pair consisting of
'Type'
and a character vector. Instruments of different types can
have different FieldName
collections.
Data Types: char
InstSetNew
— Instrument set variable containing new input data added to existing InstSet
Instrument set variable containing the new input data added to an existing
InstSet
, returned as a structure.
InstSet
— New Instrument set variable containing input dataNew Instrument set variable containing input data, returned as a strtucture.
Build a portfolio around the following July options.
Strike = (95:5:105)'
Strike = 3×1
95
100
105
CallP = [12.2; 9.2; 6.8]
CallP = 3×1
12.2000
9.2000
6.8000
Enter three call options with data fields Strike
, Price
, and Opt
.
InstSet = instaddfield('Type','Option','FieldName',... {'Strike','Price','Opt'}, 'Data',{ Strike, CallP, 'Call'}); instdisp(InstSet)
Index Type Strike Price Opt 1 Option 95 12.2 Call 2 Option 100 9.2 Call 3 Option 105 6.8 Call
Add a futures contract and set the input parsing class.
InstSet = instaddfield(InstSet,'Type','Futures',... 'FieldName',{'Delivery','F'},'FieldClass',{'date','dble'},... 'Data' ,{'01-Jul-99',104.4 }); instdisp(InstSet)
Index Type Strike Price Opt 1 Option 95 12.2 Call 2 Option 100 9.2 Call 3 Option 105 6.8 Call Index Type Delivery F 4 Futures 01-Jul-1999 104.4
Add a put option.
FN = instfields(InstSet,'Type','Option')
FN = 3x1 cell
{'Strike'}
{'Price' }
{'Opt' }
InstSet = instaddfield(InstSet,'Type','Option',... 'FieldName',FN, 'Data',{105, 7.4, 'Put'}); instdisp(InstSet)
Index Type Strike Price Opt 1 Option 95 12.2 Call 2 Option 100 9.2 Call 3 Option 105 6.8 Call Index Type Delivery F 4 Futures 01-Jul-1999 104.4 Index Type Strike Price Opt 5 Option 105 7.4 Put
Make a placeholder for another put.
InstSet = instaddfield(InstSet,'Type','Option',... 'FieldName','Opt','Data','Put')
InstSet = struct with fields:
FinObj: 'Instruments'
IndexTable: [1x1 struct]
Type: {2x1 cell}
FieldName: {2x1 cell}
FieldClass: {2x1 cell}
FieldData: {2x1 cell}
instdisp(InstSet)
Index Type Strike Price Opt 1 Option 95 12.2 Call 2 Option 100 9.2 Call 3 Option 105 6.8 Call Index Type Delivery F 4 Futures 01-Jul-1999 104.4 Index Type Strike Price Opt 5 Option 105 7.4 Put 6 Option NaN NaN Put
Add a cash instrument.
InstSet = instaddfield(InstSet, 'Type', 'TBill',... 'FieldName','Price','Data',99)
InstSet = struct with fields:
FinObj: 'Instruments'
IndexTable: [1x1 struct]
Type: {3x1 cell}
FieldName: {3x1 cell}
FieldClass: {3x1 cell}
FieldData: {3x1 cell}
instdisp(InstSet)
Index Type Strike Price Opt 1 Option 95 12.2 Call 2 Option 100 9.2 Call 3 Option 105 6.8 Call Index Type Delivery F 4 Futures 01-Jul-1999 104.4 Index Type Strike Price Opt 5 Option 105 7.4 Put 6 Option NaN NaN Put Index Type Price 7 TBill 99
instadd
| instdisp
| instget
| instgetcell
| instsetfield
You have a modified version of this example. Do you want to open this example with your edits?