These data handling tools allow you to easily retrieve and organize stock information.
| Function | Description |
|---|---|
| stockasset | Create stockasset object with historical data |
| stocktable | Generate table to view stockasset properties |
| getsp500list | Get S&P500 listings |
The stockasset class object is a unique tool for retreiving, managing, and storing historical stock data. It is similar to a strucure class object, in that the '.' (dot ) syntax can be used to access its properties and methods. Note: All historical price and volume data is normalized for splits/dividends.
Syntax |
||
|---|---|---|
MyStocks = stockasset(EndDate, DateRange,
StockList); |
||
| Argument | Options | Description |
| EndDate |
[yyyy mm dd ...] |
EndDate format is [yyyy mm dd ...], and is consistent with the Matlab®
'datevec' function. Hours, minutes, and seconds are ignored. |
DateRange |
'#days'
'#months'
'#years'
|
Number of days months, or years.
Examples: '30days', '2months',
'1year'.
|
| StartDate |
[yyyy mm dd ...] |
Same format as EndDate. StartDate is the date at which
to begin retrieving the historical data. |
StockList |
{'ABC', 'XYZ', 'YYZ'} | StockList must be a cell array of strings of stock symbols. |
See: Creating the stockasset class object, Indexing the stockasset array object
All indicator and overlay functions are methods of stockasset class objects. The 'update' method (example) is a unique method for updating the historical data contained within the stockasset object.
The properties for stockasset class objects are listed below, where 'obj' is a stockasset object with n days of historical data. Note that in the event that certain properties cannot be retrieved, either due to network issues or their lack of availability, the field will be left empty.
| Property | Description |
|---|---|
obj.Symbol |
Symbol of stock. Example: 'XYZ' |
obj.Name |
Name of company. Example: 'XYZ Widget Company' |
obj.Exchange |
Exchange where stock is traded: NYSE, AMEX, NASDAQ, OTC... |
obj.StartDate |
First date in historical data in format 'yyyy-mm-dd' |
obj.EndDate |
Last date of historical data in format 'yyyy-mm-dd' |
obj.Dates |
Cell array of date strings in format 'yyyymmdd': {n x 1 cell} |
obj.Open |
Historical open data: [n x 1 double] |
obj.High |
Historical high data: [n x 1 double] |
obj.Low |
Historical low data: [n x 1 double] |
obj.Close |
Historical close data: [n x 1 double] |
obj.Volume |
Historical volume data: [n x 1 double] |
obj.AdjClose |
Historical adjusted close data: [n x 1 double] |
obj.ShortData |
Structure with historical short data, if available. Short data is updated every two weeks, with a maximum availabilty of one year from 'now'. |
obj.ShortData.Interest |
Historical short interest, updated every two weeks: [n x 1 double] |
obj.ShortData.Avgvol |
Historical 2 week average of volume: [n x 1 double] |
obj.ShortData.Ratio |
Historical short ratio: [n x 1 double] |
Information contained in the stockasset object is easily viewed with the stocktable funciton:
Syntax |
||
|---|---|---|
stocktable(MyStocks) |
||
| Argument | Options | Description |
| MyStocks |
NA |
stockasset object |
The most current S&P500 constituent list is retreived and parsed with this function.
Syntax |
||
|---|---|---|
StockList = getsp500list; |
||
| Argument | Options | Description |
| none |
NA |
Returns most current constituent list of the S&P500 |
nrand |
numeric integer |
Returns 'nrand' number of random stocks from the S&P 500 list. |
sector |
sector abbreviation |
Returns only those stocks from the desired sector. Abbreviations for the sectors are given below. |
Syntax Notes |
||
| If both 'nrand' an 'sector' are defined, then 'nrand' number of stocks from 'sector' will be returned. | ||
Sector
Abbreviation |
Sector Name |
|---|---|
| 'CD' |
Consumer Discretionar |
'CS' |
Consumer Staples |
'E' |
Energy |
'F' |
Financials |
'HC' |
Health Care |
'I' |
Industrials |
'IT' |
Information Technology |
'M' |
Materials |
'TS' |
Telecommunications Services |
'U' |
Utilities |
Suppose we wish to retrieve two years of historical data ending on May 1, 2009 for the following companies:
The stockasset object is constructed:
While the data is being retreived, a download status window
displays the current action, and whether the retrieval was succesful. When
complete, the status window will appear as:

The resulting object 'MyStocks' is:
MyStocks = 1x9 stockasset Properties: Symbol Name Exchange StartDate EndDate Dates Open High Low Close Volume AdjCl ShortData Methods
To access a single stock, index the stockasset array with a numeric index,
or symbol string:
MyStocks(2), or MyStocks('GE')
MyStocks('GE')
stockasset
Properties:
Symbol: 'GE'
Name: 'General Electric Company'
Exchange: 'NYSE'
StartDate: '2007-05-01'
EndDate: '2009-05-01'
Dates: {506x1 cell}
Open: [506x1 double]
High: [506x1 double]
Low: [506x1 double]
Close: [506x1 double]
Volume: [506x1 double]
AdjCl: [506x1 double]
ShortData: [1x1 struct]
Methods
For the 'ShortData' field:
MyStocks('GE').ShortData
Interest: [506x1 double]
Avgvol: [506x1 double]
Ratio: [506x1 double]
The 'update' method is used to update historical data from the 'EndDate' to 'now'. It returns the updated stockasset object. Continuing from the example above, with MyStocks(1).EndDate = '2009 05 01', suppose today is May 7, 2009, and we want to update MyStocks:
MyUpdatedStocks = MyStocks.update;
produces:
MyUpdatedStocks('GE')
stockasset
Properties:
Symbol: 'GE'
Name: 'General Electric Company'
Exchange: 'NYSE'
StartDate: '2007-05-01'
EndDate: '2009-05-07'
Dates: {510x1 cell}
Open: [510x1 double]
High: [510x1 double]
Low: [510x1 double]
Close: [510x1 double]
Volume: [510x1 double]
AdjCl: [510x1 double]
ShortData: [1x1 struct]
Methods
Continuing from above, the properties of 'MyStocks' are viewed with stocktable:
Produces the follwing table:
Retreive all current S&P500 listed stocks:

Retreive 10 random S&P500 listed stocks:

Retreive all S&P500 listed stocks in the 'Health Care' sector

Retreive 10 random S&P500 listed stocks in the 'Consumer Staples' sector:
