Data Handling - Technical Analysis Toolbox™
Data Handling

These data handling tools allow you to easily retrieve and organize stock information.

Contents

Functions

Examples

back to top

Functions

Function List

Function Description
stockasset Create stockasset object with historical data
stocktable Generate table to view stockasset properties
getsp500list Get S&P500 listings

back to top


stockasset

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);
MyStocks = stockasset(EndDate, StartRange, 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.
Acceptable inputs:
[2008 04 05], [2009 08 16 22 46 45.969002].
Useful method: EndDate = datevec(now).

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.
Example: StartDate = [2007 01 01]; EndDate = [2009 01 01];

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

back to top

 

Methods and properties of stockasset class objects

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]

See: Updating stockasset historical data

back to top


stocktable

Information contained in the stockasset object is easily viewed with the stocktable funciton:

Syntax

stocktable(MyStocks)

Argument Options Description
MyStocks
NA

stockasset object

See: Viewing the stockasset object

back to top


getsp500list

The most current S&P500 constituent list is retreived and parsed with this function.

Syntax

StockList = getsp500list;
StockList = getsp500list(nrand);
StockList = getsp500list(sector);
StockList = getsp500list(sector, nrand);

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 abbreviatons

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

See: Retreiving S&P500 constituent listings

back to top

Examples

Creating the stockasset class object

Suppose we wish to retrieve two years of historical data ending on May 1, 2009 for the following companies:

StockList = {'DIS', 'PG', 'JPM', 'XOM', 'JNJ', 'GE', 'MSFT', 'EXC', 'MON'};

The stockasset object is constructed:

MyStocks = stockasset([2009 05 01], '2years' , StockList)

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:

image

The resulting object 'MyStocks' is:

MyStocks = 


  1x9 stockasset

  Properties:
    Symbol
    Name
    Exchange
    StartDate
    EndDate
    Dates
    Open
    High
    Low
    Close
    Volume
    AdjCl
    ShortData


  Methods

back to top


 

Indexing the stockasset array object

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]

back to top



Updating stockasset historical data

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

back to top



Viewing the stockasset object

Continuing from above, the properties of 'MyStocks' are viewed with stocktable:

stocktable(MyStocks)

Produces the follwing table:

image

back to top



Retreiving S&P500 constituent listings

Retreive all current S&P500 listed stocks:

StockList = getsp500list;

image

Retreive 10 random S&P500 listed stocks:

StockList = getsp500list(10);

image

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

StockList = getsp500list('HC');

image

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

StockList = getsp500list('CS', 10);

image