[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Calculating a Moving Average

Subject: Calculating a Moving Average
From: "John Reid" <John.Reid@xxxxxxxxxxxxxxx>
Date: Sun, 30 May 2004 14:06:14 +1000
calculating moving average
G'day,

I am trying to calculate a moving average based on the below XML, according to
a number of days parameter. Ie 20 day moving average, would sum the last
(starting at the end 20040528) 20 days closing price <cl> and divide by 20.

<xsl:param name="varDays" select="0" />
<xsl:variable name="varTotalMA" select="sum(day[(last() - $varDays) and
last()]/cl)" />

<xsl:variable name="varMA" select="$varTotalMA / $varDays" />

Any help appreciated

John

	<asx id="AAC" coy="AUSTRALIAN AGRICULTURAL COMPANY LIMITED."
sector="Food Beverage &amp; Tobacco" asxNo="ASX300" currHi="122" currOp="121"
currCl="120" currVol="113728" currDate="20040528">
		<day id="20040329" weekno="1">
			<op>116</op>
			<hi>116</hi>
			<lo>114</lo>
			<cl>114</cl>
			<vol>73200</vol>
		</day>
		<day id="20040330" weekno="1">
			<op>114</op>
			<hi>115</hi>
			<lo>114</lo>
			<cl>115</cl>
			<vol>73745</vol>
		</day>
		<day id="20040331" weekno="1">
			<op>115</op>
			<hi>115</hi>
			<lo>113</lo>
			<cl>113</cl>
			<vol>262756</vol>
		</day>
		<day id="20040401" weekno="1">
			<op>114</op>
			<hi>114</hi>
			<lo>113</lo>
			<cl>114</cl>
			<vol>95200</vol>
		</day>
		<day id="20040402" weekno="1">
			<op>114</op>
			<hi>114</hi>
			<lo>113</lo>
			<cl>113</cl>
			<vol>198992</vol>
		</day>
		<day id="20040405" weekno="2">
			<op>113</op>
			<hi>116</hi>
			<lo>113</lo>
			<cl>116</cl>
			<vol>643913</vol>
		</day>
		<day id="20040406" weekno="2">
			<op>116</op>
			<hi>116</hi>
			<lo>115</lo>
			<cl>116</cl>
			<vol>421525</vol>
		</day>
		<day id="20040407" weekno="2">
			<op>116</op>
			<hi>116</hi>
			<lo>115</lo>
			<cl>116</cl>
			<vol>351438</vol>
		</day>
		<day id="20040408" weekno="2">
			<op>116</op>
			<hi>116</hi>
			<lo>114</lo>
			<cl>116</cl>
			<vol>154881</vol>
		</day>
		<day id="20040409" weekno="2">
			<op>116</op>
			<hi>116</hi>
			<lo>116</lo>
			<cl>116</cl>
			<vol>0</vol>
		</day>
		<day id="20040413" weekno="3">
			<op>116</op>
			<hi>117</hi>
			<lo>115</lo>
			<cl>115</cl>
			<vol>127715</vol>
		</day>
		<day id="20040413" weekno="3">
			<op>116</op>
			<hi>117</hi>
			<lo>115</lo>
			<cl>115</cl>
			<vol>127715</vol>
		</day>
		<day id="20040414" weekno="3">
			<op>115</op>
			<hi>116</hi>
			<lo>115</lo>
			<cl>116</cl>
			<vol>133444</vol>
		</day>
		<day id="20040415" weekno="3">
			<op>114</op>
			<hi>115</hi>
			<lo>113</lo>
			<cl>114</cl>
			<vol>218466</vol>
		</day>
		<day id="20040416" weekno="3">
			<op>114</op>
			<hi>114</hi>
			<lo>113</lo>
			<cl>114</cl>
			<vol>151423</vol>
		</day>
		<day id="20040419" weekno="4">
			<op>113</op>
			<hi>114</hi>
			<lo>113</lo>
			<cl>113</cl>
			<vol>79202</vol>
		</day>
		<day id="20040420" weekno="4">
			<op>114</op>
			<hi>115</hi>
			<lo>113</lo>
			<cl>115</cl>
			<vol>151972</vol>
		</day>
		<day id="20040421" weekno="4">
			<op>114</op>
			<hi>114</hi>
			<lo>113</lo>
			<cl>113</cl>
			<vol>125633</vol>
		</day>
		<day id="20040422" weekno="4">
			<op>114</op>
			<hi>119</hi>
			<lo>113</lo>
			<cl>118</cl>
			<vol>744055</vol>
		</day>
		<day id="20040423" weekno="4">
			<op>118</op>
			<hi>119</hi>
			<lo>118</lo>
			<cl>118</cl>
			<vol>513601</vol>
		</day>
		<day id="20040426" weekno="5">
			<op>118</op>
			<hi>118</hi>
			<lo>117</lo>
			<cl>117</cl>
			<vol>198288</vol>
		</day>
		<day id="20040427" weekno="5">
			<op>118</op>
			<hi>118</hi>
			<lo>117</lo>
			<cl>117</cl>
			<vol>191337</vol>
		</day>
		<day id="20040428" weekno="5">
			<op>118</op>
			<hi>120</hi>
			<lo>118</lo>
			<cl>118</cl>
			<vol>323800</vol>
		</day>
		<day id="20040429" weekno="5">
			<op>118</op>
			<hi>119</hi>
			<lo>117</lo>
			<cl>119</cl>
			<vol>260638</vol>
		</day>
		<day id="20040430" weekno="5">
			<op>119</op>
			<hi>119</hi>
			<lo>117</lo>
			<cl>118</cl>
			<vol>163400</vol>
		</day>
		<day id="20040503" weekno="6">
			<op>119</op>
			<hi>119</hi>
			<lo>117</lo>
			<cl>118</cl>
			<vol>123565</vol>
		</day>
		<day id="20040504" weekno="6">
			<op>117</op>
			<hi>120</hi>
			<lo>117</lo>
			<cl>120</cl>
			<vol>470247</vol>
		</day>
		<day id="20040505" weekno="6">
			<op>120</op>
			<hi>124</hi>
			<lo>120</lo>
			<cl>124</cl>
			<vol>1646033</vol>
		</day>
		<day id="20040506" weekno="6">
			<op>124</op>
			<hi>124</hi>
			<lo>122</lo>
			<cl>122</cl>
			<vol>191631</vol>
		</day>
		<day id="20040507" weekno="6">
			<op>122</op>
			<hi>123</hi>
			<lo>122</lo>
			<cl>122</cl>
			<vol>179778</vol>
		</day>
		<day id="20040510" weekno="7">
			<op>122</op>
			<hi>122</hi>
			<lo>120</lo>
			<cl>121</cl>
			<vol>474624</vol>
		</day>
		<day id="20040511" weekno="7">
			<op>121</op>
			<hi>122</hi>
			<lo>121</lo>
			<cl>122</cl>
			<vol>148610</vol>
		</day>
		<day id="20040512" weekno="7">
			<op>122</op>
			<hi>123</hi>
			<lo>122</lo>
			<cl>122</cl>
			<vol>84962</vol>
		</day>
		<day id="20040513" weekno="7">
			<op>121</op>
			<hi>121</hi>
			<lo>119</lo>
			<cl>119</cl>
			<vol>153598</vol>
		</day>
		<day id="20040514" weekno="7">
			<op>119</op>
			<hi>120</hi>
			<lo>118</lo>
			<cl>120</cl>
			<vol>58598</vol>
		</day>
		<day id="20040517" weekno="8">
			<op>119</op>
			<hi>119</hi>
			<lo>118</lo>
			<cl>119</cl>
			<vol>145304</vol>
		</day>
		<day id="20040518" weekno="8">
			<op>118</op>
			<hi>120</hi>
			<lo>117</lo>
			<cl>120</cl>
			<vol>425565</vol>
		</day>
		<day id="20040519" weekno="8">
			<op>120</op>
			<hi>121</hi>
			<lo>120</lo>
			<cl>120</cl>
			<vol>91171</vol>
		</day>
		<day id="20040520" weekno="8">
			<op>121</op>
			<hi>121</hi>
			<lo>120</lo>
			<cl>121</cl>
			<vol>218439</vol>
		</day>
		<day id="20040521" weekno="8">
			<op>121</op>
			<hi>121</hi>
			<lo>120</lo>
			<cl>120</cl>
			<vol>80331</vol>
		</day>
	</asx>

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.