[Candlesticks-commits] r25 - in pkg: . R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Jan 13 16:17:08 CET 2013


Author: wotuzu17
Date: 2013-01-13 16:17:08 +0100 (Sun, 13 Jan 2013)
New Revision: 25

Added:
   pkg/R/CandleAverage.R
   pkg/man/CandleAverage.Rd
Modified:
   pkg/DESCRIPTION
   pkg/NAMESPACE
Log:
added CandleAverage functions (OHLC_Average, HLC_Average, HL_Average)

Modified: pkg/DESCRIPTION
===================================================================
--- pkg/DESCRIPTION	2012-08-17 08:15:36 UTC (rev 24)
+++ pkg/DESCRIPTION	2013-01-13 15:17:08 UTC (rev 25)
@@ -1,8 +1,8 @@
 Package: candlesticks
 Type: Package
 Title: Candlestick Pattern Recognition
-Version: 0.1-18
-Date: 2012-08-17
+Version: 0.1-19
+Date: 2013-01-13
 Author: Andreas Voellenklee
 Maintainer: Andreas Voellenklee <wotuzu17 at gmail.com>
 Depends: R (>= 2.13), xts (>= 0.8-2), quantmod (>= 0.3-17), TTR (>= 0.21-0)

Modified: pkg/NAMESPACE
===================================================================
--- pkg/NAMESPACE	2012-08-17 08:15:36 UTC (rev 24)
+++ pkg/NAMESPACE	2013-01-13 15:17:08 UTC (rev 25)
@@ -44,4 +44,7 @@
 export(is.HL)
 export(is.OC)
 export(nextCandlePosition)
-
+# candle average functions
+export(OHLC_Average)
+export(HLC_Average)
+export(HL_Average)

Added: pkg/R/CandleAverage.R
===================================================================
--- pkg/R/CandleAverage.R	                        (rev 0)
+++ pkg/R/CandleAverage.R	2013-01-13 15:17:08 UTC (rev 25)
@@ -0,0 +1,26 @@
+OHLC_Average <- function(TS) {
+  if (!is.OHLC(TS)) {
+    stop("Price series must contain Open, High, Low and Close.")
+  }
+  Av <- as.xts(apply(cbind(Op(TS), Hi(TS), Lo(TS), Cl(TS)), 1, mean))
+  colnames(Av) <- c("OHLC_Average")
+  return (reclass(Av, TS))
+}
+
+HLC_Average <- function(TS) {
+  if (!is.HLC(TS)) {
+    stop("Price series must contain High, Low and Close.")
+  }
+  Av <- as.xts(apply(cbind(Hi(TS), Lo(TS), Cl(TS)), 1, mean))
+  colnames(Av) <- c("HLC_Average")
+  return (reclass(Av, TS))
+}
+
+HL_Average <- function(TS) {
+  if (!is.HL(TS)) {
+    stop("Price series must contain High and Low.")
+  }  
+  Av <- as.xts(apply(cbind(Hi(TS), Lo(TS)), 1, mean))
+  colnames(Av) <- c("HL_Average")
+  return (reclass(Av, TS))
+}
\ No newline at end of file

Added: pkg/man/CandleAverage.Rd
===================================================================
--- pkg/man/CandleAverage.Rd	                        (rev 0)
+++ pkg/man/CandleAverage.Rd	2013-01-13 15:17:08 UTC (rev 25)
@@ -0,0 +1,41 @@
+\name{CandleAverage}
+\alias{OHLC_Average}
+\alias{HLC_Average}
+\alias{HL_Average}
+\title{Mean value of OHLC prices}
+\description{Calculates the average value of different price levels within a price bar.}
+\usage{
+  OHLC_Average(TS)
+  OHL_Average(TS)
+  HL_Average(TS)
+}
+\arguments{
+  \item{TS}{xts Time Series containing Open and Close Prices}
+}
+\details{
+The calculation of the average of the high, low, and close, is as follows:\cr
+OHLC Average = (Open + High + Low + Close) / 4\cr
+HLC Average = (High + Low + Close) / 3\cr
+HL Average = (High + Low) / 2\cr
+}
+\value{
+  A xts object containing the corresponding column:
+  \item{OHLC_Average}{}
+  \item{HLC_Average}{}
+  \item{HL_Average}{}
+}
+\note{
+}
+\seealso{
+}
+\examples{
+\dontrun{
+# calculate average prices for a daily OHLC price series
+getSymbols('YHOO', adjust=TRUE)
+head(cbind(OHLC_Average(YHOO), 
+      HLC_Average(YHOO), 
+      HL_Average(YHOO)))
+}
+}
+\author{Andreas Voellenklee}
+\keyword{}



More information about the Candlesticks-commits mailing list