Learn R Programming

fractalrock (version 1.1.0)

fractal: Create time series based on fractal generators

Description

The fractal function generates a time series of points using basic principles of fractal patterns. Fractal generation can be used to simulate a time series of asset prices, which has been shown to better reflect the distribution of returns than using a Gaussian random walk. Any number of points can be generated based on specifying the total count or by running over a number of epochs. The range of the data is defined by the given seed for the generation plus the available patterns.

Usage

fractal(seeds, patterns, count = NULL, epochs = NULL, ..., type = "uniform")
fractal.uniform(seed, patterns, count = NULL, epochs = NULL, origin = '1970-01-01', date.fun = as.Date, only = NULL)
fractal.random(seed, patterns, count = NULL, epochs = NULL, origin = '1970-01-01', date.fun = as.Date, only = NULL)
next.seeds(old.seed, new.seed, pattern, idx, epoch)

Arguments

seeds
A list of seed patterns to use for generating the time series
seed
The seed pattern to use for generating the time series
patterns
A single pattern or list of patterns that get randomly selected for each segment being replaced
count
The total number of points to create. Either count or epochs must be provided. Specifying count indirectly sets the number of epochs to run and truncates the data appropriately to get the specified number of points.
epochs
The total number of epochs to run. Either count or epochs must be populated. Using epochs is good for experimentation to visualize what happens at every stage of the generation.
origin
The starting date for the generated time series
date.fun
The function to use to parse dates and/or times
only
Only use the nth pattern instead of randomly choosing from patterns
...
Additional arguments to pass to underlying function
type
The type of generation to perform. Uniform descends each level in a uniform manner (meaning all segments get replaced) whereas the random generation will randomly select segments to replace during each epoch.
old.seed
(Internal) Previous seed used to generate pattern
new.seed
(Internal) Next seed used to generate pattern
pattern
(Internal) Available patterns to use
idx
(Internal) Index of current iteration
epoch
(Internal) Current epoch

Value

An xts object containing a time series of values representing asset prices

References

M. Frame, B. Mandelbrot, N. Neger. Fractal Geometry. 2009. http://classes.yale.edu/fractals/

Examples

Run this code
data(generators)
series <- fractal(sampleInitiators, sampleGenerators, count=10)

# View the results of a single iteration using the second pattern
series <- fractal(sampleInitiators, sampleGenerators, epochs=1, only=2)

Run the code above in your browser using DataLab