• Tidak ada hasil yang ditemukan

STOCK MARKET DATA EXAMPLE

Dalam dokumen COMPUTATIONAL FINANCE - untag-smd.ac.id (Halaman 75-79)

//SYS21///INTEGRAS/ELS/PAGINATION/ELSEVIER UK/CMF/3B2/FINALS_21-11-03/CH006.3D60– [54–63/10]

21.11.2003 3:26PM

<xsl:choose>

<xsl:when test¼‘‘$return &lt; 0.10’’>

<td bgcolor¼‘‘pink’’ align¼‘‘center’’><xsl:value-of select¼‘‘$price’’/>

</td>

</xsl:when>

<xsl:when test¼‘‘$return &gt; 0.20’’>

<td bgcolor¼‘‘yellow’’ align¼‘‘center’’>

<font color¼‘‘red’’>*<xsl:value-of select¼‘‘$price’’/>*</font>

</td>

</xsl:when>

<xsl:otherwise>

<td bgcolor¼‘‘yellow’’ align¼‘‘center’’><xsl:value-of select¼‘‘$price’’/>

</td>

</xsl:otherwise>

</xsl:choose>

Here if the variablereturnis less than 0.1 then the background colour of the cell is set to pink to indicate a bad share, but if value ofreturnis greater than 0.2 then the background colour of the cell is set to yellow and red stars are output to indicate that this is a good share. If the value ofreturnis between 0.1 and 0.2 then the code contained in the<xsl:otherwise>clause is executed and the background colour is just set to yellow.

It is also possible to create procedures in XSL, for instance:

<xsl:template name¼‘‘OUTPUT_ELEMENT’’>

<xsl:param name¼‘‘share’’/>

<xsl:param name¼‘‘price’’/>

<xsl:param name¼‘‘return’’/>

<xsl:choose>

<xsl:when test¼‘‘$return &lt; 0.10’’>

<td bgcolor¼‘‘pink’’ align¼‘‘center’’><xsl: value-of select¼‘‘$price’’/>

</td>

<xsl:otherwise>

<td bgcolor¼‘‘yellow’’ align¼‘‘center’’><xsl:value-of select¼‘‘$price’’/>

</td>

</xsl:otherwise>

</xsl:choose>

</xsl:template>

defines an XSL procedure called OUTPUT_ELEMENT with parameters share, price, andreturn. It can be called using the following syntax:

<xsl:call-template name¼‘‘OUTPUT_ELEMENT’’>

<xsl:with-param name¼‘‘share’’ select¼‘‘$v1’’/>

<xsl:with-param name¼‘‘price’’ select¼‘‘$v2’’/>

<xsl:with-param name¼‘‘return’’ select¼‘‘$v3’’/>

</xsl:call-template>

where, for instance, the parameterpriceis given the value of the XSL variable v2; the variablesv1,v2, andv3are assumed to have been set earlier in the code.

//SYS21///INTEGRAS/ELS/PAGINATION/ELSEVIER UK/CMF/3B2/FINALS_21-11-03/CH006.3D61– [54–63/10]

21.11.2003 3:26PM

The XML file used here is called stockmarket_data.xml and has been men- tioned earlier in Sections 6.2 to 6.4. This file contains the daily prices and annual returns for nine shares. We assume that the data has been processed by a numerical optimizer which has computed an optimal (Markowitz minimum risk/maximum return) portfolio of these shares, and that the results of these computations have been written to the XML file. As shown in Code excerpt 6.2, the portfolio analysis results are stored between the XML tags<PORTFOLIO_ANALYSIS>and<\PORTFOLIO_ANALYSIS>.

Here we will use two different XSL files to visualize the XML file either as data in tabular form (Figure 6.2) or as a report file (Figure 6.3), in which summary information concerning the optimal portfolio is shown.

The XSL stylesheet used to create the report view of the XML data file is shown below in Code excerpt 6.4. All the stock market data is matched using the XSL state- ment<xsl:template match=‘‘stock_xdr:DATA_ REC’’>, and (because we are only interested summary information) produces no output. By contrast the XSL command <xsl:template match= ‘‘stock_xdr:PORTFOLIO_ANALYSIS’’>

matches the portfolio analysis results and creates the HTML output seen in Figure 6.3.

<xsl:stylesheet version¼‘‘1.0’’ xmlns:xsl¼‘‘http://www.w3.org/1999/XSL/Transform ’ xmlns:stock_xdr¼‘‘x-schema:stockmarket_data.xdr’’>

<xsl:template match¼‘‘/’’>

<HTML>

<head>

<title>PORTFOLIO ANALYSIS REPORT</title>

</head>

<body>

<xsl:apply-templates />

The pie chart below shows the optimal holdings for each stock in the minimum risk portfolio. <p></p>

<embed src¼‘‘report_pie.svg’’ width¼‘‘500’’ height¼‘‘5000’’ name¼‘‘SVGEmbed’’ type¼‘‘image/svg-xml’ pluginspage¼‘‘http://www.adobe.com/svg/viewer/install/’’/>

</body>

</HTML>

</xsl:template>

<xsl:template match¼‘‘stock_xdr:PORTFOLIO_ANALYSIS’’>

<h1 align¼‘‘center’’><i>PORTFOLIO ANALYSIS REPORT</i></h1>

This report gives details of the optimal (minimum risk, maximum return) portfolio that can be constructed from the

share information contained in the file

<b>stockmarket_data.xml</b>. The optimal holdings were calculated using numerical optimization.

The information is presented in the following format:

<font color¼‘‘blue’’>company name (epic code) </font>,

<font color¼‘‘green’’>annual return </font>,

<font color¼‘‘red’’>optimal portfolio holding </font>.

High performing companies are starred. <p></p>

<xsl:for-each select¼‘‘stock_xdr:PORT_ITEM’’>

<xsl:variable name¼‘‘v1’’ select¼‘‘stock_xdr: AVERAGE_RETURN’’ />

<xsl:if test¼‘‘$v1 &gt; 0.19’’> <b><font color¼‘red’’>**</font></b></xsl:if>

<font color¼‘‘blue’’><xsl:value-of select¼‘@FULL_NAME’’/><xsl:if test¼‘‘$v1 &gt; 0.19’’><b>

<font color¼‘‘red’’>**</font></b></xsl:if>(<xsl: value-of select¼‘‘@SHARE’’/>) </font>,

<font color¼‘‘green’’><xsl:value-of select¼‘stock_xdr:AVERAGE_RETURN’’/></font>,

<font color¼‘‘red’’><xsl:value-of select¼‘‘stock _xdr:OPTIMAL_HOLDING’’/></font>;

</xsl:for-each>

</xsl:template>

<xsl:template match¼‘‘stock_xdr:DATA_REC’’>

<!-- DO NOT OUTPUT ANY STOCK DATA IN THIS STYLE SHEET-->

</xsl:template>

</xsl:stylesheet>

Code excerpt 6.4 The XSL filereport_style.xslused to transform the XML file stockmarket_data.xmlinto the report view shown in Figure 6.3

XML and transformation using XSL 61

//SYS21///INTEGRAS/ELS/PAGINATION/ELSEVIER UK/CMF/3B2/FINALS_21-11-03/CH006.3D62– [54–63/10]

21.11.2003 3:26PM

Figure 6.2 The tabular view of the XML data filestockmarket_data.xmldisplayed using the Web browser Internet Explorer 6; the XSL style sheet is available on the CD ROM

Figure 6.3 The report view of XML data filestockmarket_data.xmldisplayed using the Web browser Internet Explorer 6; the XSL style sheet is given in Code excerpt 6.4

62 Using Numerical Software Components within Microsoft Windows

//SYS21///INTEGRAS/ELS/PAGINATION/ELSEVIER UK/CMF/3B2/FINALS_21-11-03/CH006.3D63– [54–63/10]

21.11.2003 3:26PM

The report view also includes a Scalable Vector Graphics (SVG) pie chart report_pie.svg to display the portfolio composition. Here the SVG graphics were viewed by installing the Adobe SVG Viewer, which can be freely downloaded fromhttp://www.adobe.com/svg/.

The XSL statement for including the SVG graphic is:

<embed src¼‘‘report_pie.svg’’ width¼‘‘500’’height¼‘‘5000’’name¼‘‘SVGEmbed’’ type¼‘‘image/svg-xml’ pluginspage¼‘‘http://www.adobe.com/svg/viewer/install/’’/>

where the image source is specified by using the srcattribute, and the size of the image is controlled viawidthandheightattributes.

XML and transformation using XSL 63

//SYS21///INTEGRAS/ELS/PAGINATION/ELSEVIER UK/CMF/3B2/FINALS_21-11-03/CH007.3D64– [64–74/11]

21.11.2003 3:29PM

Chapter 7

Epilogue

7.1 WRAPPING C WITH C++ FOR OO NUMERICS IN .NET

Dalam dokumen COMPUTATIONAL FINANCE - untag-smd.ac.id (Halaman 75-79)