This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Customized Components

    Note:   These examples require the Datafeed Toolbox™ software.

Fetching Securities Data and Displaying It in a Table

This example shows how to create a component that fetches securities data and displays it in a report as a table.

  1. In the class folder named CStockTicker, insert a component named Equity Values.

  2. Give the component one property value of Ticker, and specify its attributes.

    1. In the Options pane of the Report Explorer, double-click New_String_Property.

    2. For Property name, specify a valid MATLAB® variable name.

    3. Specify the property's data type.

    4. Specify the property's default value.

      Because this example fetches ticker values for the security Google, set the Default value to 'GOOG'. (The single quotation marks are required to specify a character vector value for this field.)

      Your specified settings appear in the Code Preview pane.

  3. To build the new component, click the Build button in the Report Explorer. The Equity Values component now appears in the Options pane in the middle of the Report Explorer.

  4. Edit the component's execute.m file to retrieve stock market data and display it in a table in the generated report.

    1. In the @CStockTicker folder, open execute.m.

    2. Enter the following text into execute.m.

      function out=execute(thisComp,parentDoc,varargin)
      stockQuote = fetch(GOOG, thisComp.Ticker);
      stockQuote.Date = datestr(stockQuote.Date,1);
      stockQuote.Time = datestr(stockQuote.Time,13);
      out = execute(rptgen.cfr_table(...
           'Source', stockQuote,...
           'numHeaderRows', 0,...
           'TableTitle', 'Stock Market Pricing Data'),...
  5. Append the security symbol, goog, to the component name. Enter the following text into getOutlineString.m.

    function olstring=getOutlineString(thisComp)
    olstring = [getName(thisComp),' - ',thisComp.Ticker];

    The component name now appears as Equity Values — goog.

  6. Modify the getdialogschema.m file to change the appearance of the Properties pane. Enter the following text into this file to display the last quoted price for the security in the Properties pane.

    function dlgStruct = getdialogschema(thisComp, name)
        currQuote = fetch(yahoo, thisComp.Ticker);
        quoteStr = sprintf('Last value: %g', currQuote.Last);
        quoteStr = sprintf('Warning: ... 
        "%s" is not a valid symbol.', thisComp.Ticker);
    dlgStruct = thisComp.dlgMain(name,...
            'RowSpan',[1 1],'ColSpan',[1 1]);
            'RowSpan',[2 2],'ColSpan',[1 1]);
          'LayoutGrid',[3 2],...
          'RowStretch',[0 0 1],...
          'ColStretch',[0 1]));

    The Properties pane for the component, Equity Values, now looks as follows.

  7. Click File > Report to generate the report. The following output appears in the report.

Displaying Securities Data in Two Tables

This example, which shows how to use multiple properties within a component, expands upon Fetching Securities Data and Displaying It in a Table.

  1. Create a report setup file and save it as stockreport.rpt. Add two Equity Values components to the setup file.

  2. Edit the entry in the New market property field to change the ticker property of the second component to '^GSPC' (S&P 500 index).

  3. Run the report.

    The report displays two tables of data, one for Google® and another for the S&P 500 index.

Was this topic helpful?