| Title: | Recognising Visual Charting Patterns in Time Series Data |
|---|---|
| Description: | Generating visual charting patterns and noise, smoothing to find a signal in noisy time series and enabling users to apply their findings to real life data. Compatibility updates by Renova. |
| Authors: | Stephan Maier [aut, cre] |
| Maintainer: | Stephan Maier <[email protected]> |
| License: | GPL-3 |
| Version: | 1.0.1.9001 |
| Built: | 2026-11-15 20:40:37 UTC |
| Source: | https://github.com/renova-r/rpatrec |
The file stockmarket.RData contains the daily closing prices of the DAX30, Dow Jones Industrials and the Nikkei 225, from January 2000 until December 2016.
datadata
An object of class data.frame with 4417 rows and 3 columns.
This function lets you generate any pattern you specify in the parameters. For known definitions, either check the examples or the vignettes. This is mainly used to test either your own or this smoothing and recognition function.
generator(start = 0, dlength = 100, tot.spread = 100, presig = 0, postsig = 0, plength = 0, parts = c(15, 25, 50, 75, 85), sprd = c(50, 25, 100, 25, 50))generator(start = 0, dlength = 100, tot.spread = 100, presig = 0, postsig = 0, plength = 0, parts = c(15, 25, 50, 75, 85), sprd = c(50, 25, 100, 25, 50))
start |
Starting value |
dlength |
Integer. Length of the signal part of the time series |
tot.spread |
Integer. Difference between the lowest and highest value of the time series |
presig |
Integer. Length of the pre-signal part of the time series |
postsig |
Integer. Length of the post-signal part of the time series |
plength |
No longer needed, kept for compatability. Set to 0. |
parts |
Vector of Integers. Must be the same length as |
sprd |
Vector of Integers. Must be the same length as |
For an overview of the package capabilities, click here rpatrec
Time series with (optional) pre- or post signal, and the specified pattern.
## Not run: #create a standard HS pattern: generator() # #create a shifted head and shoulders pattern generator(sprd = c(20,10,90,40,60)) # #create a Double Tops pattern generator(plength=3,parts=c(25,50,75),sprd=c(80,40,80)) # #create a Rectangle Tops pattern generator(plength=5,parts=c(20,40,50,60,80),sprd=c(80,40,80,40,80)) # #create a single peak, 10 data points, max is approximately 10 generator(0,10,10,0,0,0,50,100) ## End(Not run)## Not run: #create a standard HS pattern: generator() # #create a shifted head and shoulders pattern generator(sprd = c(20,10,90,40,60)) # #create a Double Tops pattern generator(plength=3,parts=c(25,50,75),sprd=c(80,40,80)) # #create a Rectangle Tops pattern generator(plength=5,parts=c(20,40,50,60,80),sprd=c(80,40,80,40,80)) # #create a single peak, 10 data points, max is approximately 10 generator(0,10,10,0,0,0,50,100) ## End(Not run)
Use this function to either check for the inbuilt financial markets pattern or to use your own recognition function as described in the readme.
interpret(window, useriq = FALSE, ...)interpret(window, useriq = FALSE, ...)
window |
Time Series Data |
useriq |
User-built recognition function. Set to |
... |
Parameters passed on to either the inbuilt or external recognition function. Check iq for the parameters of the internal function. |
For an overview of the package capabilities, click here rpatrec.
A list containing the following:
All extrema found in the sample, 0 for minima and 1 for maxima
Value of these extrema (y-coordinate)
Position of these extrema (x-coordinate)
A list containing the extrema that form part of the pattern labelled by either the custom or iq function.
Can be either:
(Head and Shoulders)
(Inverse Head and Shoulders)
Can be either:
(Broadening Top)
(Broadening Bottom)
(Triangle Top)
(Triangle Bottom)
Can be either:
(Rectangle Top)
(Rectangle Bottom)
Can be either:
(Double Top)
(Double Bottom)
TRUE if any pattern is found, FALSE otherwise
## Not run: #Generate HS patterns a <- generator() #switch off recognition for all patterns other than HS interpret(window = a, useriq=FALSE, hsiq=TRUE, btpiq=FALSE, rtpiq=FALSE, dtpiq=FALSE) ## End(Not run)## Not run: #Generate HS patterns a <- generator() #switch off recognition for all patterns other than HS interpret(window = a, useriq=FALSE, hsiq=TRUE, btpiq=FALSE, rtpiq=FALSE, dtpiq=FALSE) ## End(Not run)
Do not call individually. Switch recognition on/off for certain patterns, use the arguments in the interpret or slicer function.
iq(ext, exvals, expos, hsiq = TRUE, btpiq = TRUE, rtpiq = TRUE, dtpiq = TRUE)iq(ext, exvals, expos, hsiq = TRUE, btpiq = TRUE, rtpiq = TRUE, dtpiq = TRUE)
ext |
Extrema |
exvals |
Values of the extrema |
expos |
Position of the extrema |
hsiq |
Logical. Recognise (inverse) Head and Shoulders pattern |
btpiq |
Logical. Recognise Triangle and/or Broadening tops and bottoms pattern |
rtpiq |
Logical. Recognise Rectangle tops and bottoms pattern |
dtpiq |
Logical. Recognise Double tops and bottoms pattern |
For an overview of the package capabilities, click here rpatrec.
Perform kernel regression in line with Lo et al. (2000). Either specify a bandwidth or let it be determined automatically.
kernel(input, bandwidth = "auto")kernel(input, bandwidth = "auto")
input |
Vector of Time Series Data |
bandwidth |
|
For an overview of the package capabilities, click here rpatrec.
Vector containing smoothed time series data, prints the bandwidth used.
## Not run: #create a standard HS pattern: a <- generator() #add noise to this patterns b <- noise(a,'white',10) #smooth to regain the signal c <- kernel(b,2) ## End(Not run)## Not run: #create a standard HS pattern: a <- generator() #add noise to this patterns b <- noise(a,'white',10) #smooth to regain the signal c <- kernel(b,2) ## End(Not run)
Use local regression to fit a global non-parametric model to the data. If the span is smaller than 1 the regression is truly local, if it is larger than 1 all data points in the sample are taken into account
loess.rpatrec(input, span = 0.75, ...)loess.rpatrec(input, span = 0.75, ...)
input |
Time series data passed to be smoothed |
span |
The main smoothing parameter. |
... |
Optional: Other arguments passed to loess |
For an overview of the package capabilities, click here rpatrec. This function is purely included to provide the standard interface coherent with other smoothers to the user.
Smoothed time series data only, no additional output.
## Not run: #create a standard HS pattern: a <- generator() #add noise to this patterns b <- noise(a,'white',10) #smooth to regain the signal c <- loess.rpatrec(b) ## End(Not run)## Not run: #create a standard HS pattern: a <- generator() #add noise to this patterns b <- noise(a,'white',10) #smooth to regain the signal c <- loess.rpatrec(b) ## End(Not run)
Use this function to compute any of these three moving average methods. These are the simplest smoothers available in the package so it may be a good idea to start initial testing with this function.
mav(input, len = 10, method)mav(input, len = 10, method)
input |
Time series data to use for computation |
len |
An integer to determine the number of datapoints used for computation |
method |
String. Determines the method of computation.
Permissible values are |
For an overview of the package capabilities, click here rpatrec.
Vector containing the smoothed time series data of length of input less length of len
## Not run: #create a standard HS pattern: a <- generator() #add noise to this patterns b <- noise(a,'white',10) #smooth to regain the signal c <- kernel(b,2) ## End(Not run) ##simply test the smoother mav(1:10,5,'exponential')## Not run: #create a standard HS pattern: a <- generator() #add noise to this patterns b <- noise(a,'white',10) #smooth to regain the signal c <- kernel(b,2) ## End(Not run) ##simply test the smoother mav(1:10,5,'exponential')
This function lets you add artificial noise to time series, normally to patterns generated by generator. Use different types and strengths of noise to test smoothers.
noise(input, type, final_level)noise(input, type, final_level)
input |
Time series to which noise will be added |
type |
String. Defines what type of noise to be added. Acceptable values are:
|
final_level |
Number or |
For an overview of the package capabilities, click here rpatrec
Time series with added noise.
## Not run: #Generate a HS patterns a <- generator() #now add white noise with a standdard deviation of 10 b <- noise(a,'white',10) plot(b) ## End(Not run)## Not run: #Generate a HS patterns a <- generator() #now add white noise with a standdard deviation of 10 b <- noise(a,'white',10) plot(b) ## End(Not run)
Generating visual charting patterns and noise, smoothing to find a signal in noisy time series and enabling users to apply their findings to real life data.
Generate your own Patterns
Generate artificial Noise
Prepare real sample data for use with the package
Moving Average/Median
Kernel Regression
Savitzky-Golay Filter
Smoothing Splines
LOESS
Recognise different Patterns in time series data
Recognise multiple Patterns in time series data
Test smoothing algorithms with generated data
Stock Market Indices - Daily Closing Prices
This function removes bank holidays and other days for which only NA or repeated data is available.
Designed to work with Datastream data.
sample.pre(input)sample.pre(input)
input |
Vector with time series data |
For an overview of the package capabilities, click here rpatrec.
Returns a vector conataining time series data ready for further use.
Use this function to smooth your time series data using local polynomial regression, as first pouplarised by Savitzky and Golay (1964).
savgolay(input, width = 4, degree = 2)savgolay(input, width = 4, degree = 2)
input |
Input Vector with Time Series Data |
width |
Width of the filter (to each side of the centre) |
degree |
Highest degree polynomial |
For an overview of the package capabilities, click here rpatrec. See the report for detailed references
Vector containing smoothed time series data.
savgolay(input=c(1,6,2,46,23,1,2,13,23,35,23,-2,3,23)) ## Not run: #create a standard HS pattern: a <- generator() #add noise to this patterns b <- noise(a,'white',10) #smooth to regain the signal c <- savgolay(b,8,2) ## End(Not run)savgolay(input=c(1,6,2,46,23,1,2,13,23,35,23,-2,3,23)) ## Not run: #create a standard HS pattern: a <- generator() #add noise to this patterns b <- noise(a,'white',10) #smooth to regain the signal c <- savgolay(b,8,2) ## End(Not run)
Break time series data into smaller 'windows' and pass them to the interpret function. The results are summarised in the output. For details, run interpret on specific windows only.
slicer(data, length, step = 1, useriq = FALSE, ...)slicer(data, length, step = 1, useriq = FALSE, ...)
data |
Time series Data |
length |
Length of the 'windows' |
step |
Number of Data Points between windows |
useriq |
User-built recognition function. Set to |
... |
Parameters passed on to either the inbuilt or external recognition function. Check iq for the parameters. |
For an overview of the package capabilities, click here rpatrec
A list containing:
A vector for every window analysed showing 0 if no pattern and 1 if at least 1 pattern has been found.
A vector with the starting index of those windows where a pattern has been found.
## Not run: #Generate 2 HS patterns a <- c(generator(),generator()) #recognise both HS patterns #set window size to 100, step size to 100 #switch off recognition for all patterns other than HS slicer(data = a, length = 100, step = 100, hsiq=TRUE, btpiq=FALSE, rtpiq=FALSE, dtpiq=FALSE) ## End(Not run)## Not run: #Generate 2 HS patterns a <- c(generator(),generator()) #recognise both HS patterns #set window size to 100, step size to 100 #switch off recognition for all patterns other than HS slicer(data = a, length = 100, step = 100, hsiq=TRUE, btpiq=FALSE, rtpiq=FALSE, dtpiq=FALSE) ## End(Not run)
This function provides smoothing capabilities using the cubic B-spline
splines(input, spar = 0.5, ...)splines(input, spar = 0.5, ...)
input |
Time series data passed to be smoothed |
spar |
Smoothing Parameter, value should be between 0 and 1. |
... |
Optional: Other arguments passed to smooth.spline |
For an overview of the package capabilities, click here rpatrec. This function is purely included to provide the standard interface coherent with other smoothers to the user.
Smoothed time series data only, no additional output.
## Not run: #create a standard HS pattern: a <- generator() #add noise to this patterns b <- noise(a,'white',10) #smooth to regain the signal c <- splines(b) ## End(Not run)## Not run: #create a standard HS pattern: a <- generator() #add noise to this patterns b <- noise(a,'white',10) #smooth to regain the signal c <- splines(b) ## End(Not run)
Use this function to find out about the rate of successful recognition of a simple HS pattern for any smoothing function of your choice. Speciffy the noise and other testing conditions.
test.smoother(n = 1, m = 5, incr = 1, max = 20, smoother, pattern = TRUE, ntype = "white", ...)test.smoother(n = 1, m = 5, incr = 1, max = 20, smoother, pattern = TRUE, ntype = "white", ...)
n |
number of runs |
m |
number of runs per level of noise |
incr |
value by which the error is increased in each turn |
max |
max number of times the error is increased |
smoother |
Function with pre-defined inputs, so that only the parameter |
pattern |
Check whether pattern was recognised. If |
ntype |
Noise type. See |
... |
other parameters the smoother requires |
For an overview of the package capabilities, click here rpatrec. Note that this function may be extremely computationally demanding.
Vector of recognition rates for specified levels of noise
## Not run: #Test the kernel regression smoother a <- test.smoother(n=5,m=10,incr=0.5,max=50,smoother = kernel,bandwidth=1) #Plot the result plot(a,type='l') ## End(Not run)## Not run: #Test the kernel regression smoother a <- test.smoother(n=5,m=10,incr=0.5,max=50,smoother = kernel,bandwidth=1) #Plot the result plot(a,type='l') ## End(Not run)