instaddfield
Add new instruments to instrument collection
Description
adds instruments to an existing instrument set InstSetNew
= instaddfield(InstSet
,Name,Value
)InstSet
. The output
InstSetNew
is a new instrument set containing the input data.
creates an instrument variable InstSet
= instaddfield(Name,Value
)InstSet
.
Examples
Add New Instruments to Instrument Collection
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
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: InstSet =
instaddfield('Type','Option','FieldName',{'Strike','Price','Opt'},'Data',{Strike,CallP,'Call'})
FieldName
— Name of each data field for instrument
cell array of character vectors
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 field
array | cell array
Data 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 field
vector
Data 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 added
character vector
Type 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
Output Arguments
InstSetNew
— Instrument set variable containing new input data added to existing InstSet
structure
Instrument set variable containing the new input data added to an existing
InstSet
, returned as a structure.
InstSet
— New Instrument set variable containing input data
structure
New Instrument set variable containing input data, returned as a structure.
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 (한국어)