Stock Market Anlaysis(DOW JONES) using X++

As a commodities trader, I’ve never lost my fascination for the markets. This job will download
historical trading data from Yahoo Finance for any valid specified date range
and issue symbol, including indexes such as the Dow Industrials Average (that’s
"^DJI" with Yahoo).

 URL
Used :

http://finance.yahoo.com/q/hp?s=IBM&a=00&b=2&c=2004&d=04&e=8&f=2005&g=d&z=66&y=66

   * s – ticker symbol( MSFT – Microsoft,
IBM etc)
   * a – start month
   * b – start day
   * c – start year
   * d – end month
   * e – end day
   * f – end year
   * g – resolution (e.g. ‘d’ is daily,
‘w’ is weekly, ‘m’ is monthly)
   * y is the offset (cursor) from the
start date
   * z is the number of results to return
starting at the cursor (66
     maximum, apparently)

 Here is the Job:

 static void StockMarket_Analysis(Args _args)

{

   
System.Net.WebClient web = new System.Net.WebClient();

   
TextBuffer           txtBuffer =
new TextBuffer();

   
str                        result;

   
container           
recordContainer, fieldContainer;

   
str                  stockContent;

    int                  i;

   
FileName       nameOfTheFile;

   
str                  tmpContent;

    str
urlQuery         =
@"http://ichart.finance.yahoo.com/table.csv?s=MSFT&a=00&b=2&c=2007&d=04&e=8&f=2008&g=d&ignore=.csv";

   
CCHTMLString         htmlString;

   
CCHTMLString formHTML(Container hmtlContainer, int tmp = 0)

    {

       
CCHTMLString html;

       
int h;

       
str start_td_th;

       
str end_td_th;

       
str value;

        ;

        if
(tmp == 1)

        {

           
start_td_th = @"<th align = ‘center’>";

           
end_td_th = @'</th>’;

        }

       
else

        {

           
start_td_th = @"<td align = ‘center’>";

           
end_td_th = @'</td>’;

        }

       
html += ‘<tr>’;

       
for (h = 1; h <= conlen(hmtlContainer); h++)

        {

           
if (h == 6 && isInteger(conpeek(hmtlContainer, h)))

               
value = 
int2str(conpeek(hmtlContainer, h));

           
else

               
value =  conpeek(hmtlContainer,
h);

           
html += start_td_th + value + end_td_th;

         }

       
html += ‘</tr>’;

       
return html;

    }

    ;

    result
= web.DownloadString(urlQuery);

    result
= strreplace(result,"\r", "");

   
recordContainer = str2con(result,’\n’);

   
htmlString += @'<html><body><Marquee><b>Stock
Market Alert … <IMG
SRC="http://www.wharton-pec.org/conf2006/images/DowJones_Logo.jpg&quot;
HEIGHT=40 WIDTH=82

                   
</b></Marquee><CENTER><table border="1"
CELLSPACING="5" CELLPADDING="5" BGCOLOR="lightblue"
WIDTH="80%>’;

     for (i
= 1; i <= conlen(recordContainer); i++)

    {

       
tmpContent = conpeek(recordContainer, i);

       
fieldContainer = str2con(tmpContent,’,’);

        if
(i == 1)

           
stockContent += formHtml(fieldContainer, 1);

       
else

           
stockContent += formHtml(fieldContainer);

    }

   
htmlString += stockContent +
‘</table></CENTER></body></html>’;

   
txtBuffer.setText(htmlString);

   
nameOfTheFile = winApi::getTempPath() + ‘StockMarket.html’;

    txtBuffer.toFile(nameOfTheFile);

   
infolog.urlLookup(nameOfTheFile);

}

The screen shot of the output is attached below.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: