Data::TimeSeries - Perl extension for Manipulation of Time Series of numbers. Data::TimeSeries supports all the periods of ChronoKey.
use Data::TimeSeries; my $start =Data::TimeSeries::ChronoKey::new(Data::TimeSeries::ChronoKey::WEEK, "2004W48"); my $stop =Data::TimeSeries::ChronoKey::new(Data::TimeSeries::ChronoKey::WEEK, "2005W02"); my $timeSeries=Data::TimeSeries::new($start, $stop,Data::TimeSeries::ChronoKey::WEEK,'{3,4,5,6,7,8,9,10}'); $ts->addPoint(Data::TimeSeries::FIRST, 2); $ts->addPoint(Data::TimeSeries::LAST, 12); $ts->seriesOperate(sub {$total+=$_;}); $ts->removePoint(Data::TimeSeries::LAST); $ts->removePoint(Data::TimeSeries::FIRST); $ts->seriesOperate(sub {$total+=$_;}); $copy=$timeSeries->copy(); $ts->normalize(); my $rstart =Data::TimeSeries::ChronoKey::new(Data::TimeSeries::ChronoKey::WEEK, "2004W45"); my $rstop =Data::TimeSeries::ChronoKey::new(Data::TimeSeries::ChronoKey::WEEK, "2004W51"); $resized->resize($rstart, $rstop); $ts->stationize($station); $copy->remap(Data::TimeSeries::ChronoKey::DAY, Data::TimeSeries::SPREAD);
TimeSeries assumes you are working with numeric data where there is a value for every target period.
new
$ts = Data::TimeSeries::new($start, $end, $period, $series);
Creates and initalizes TimeSeries object. new
dies if parameters are not legal. $start - ChronoKey object. The position of the first element in the serines. $end - ChronoKey object. The position of the last element in the series. $period - A ChronoKey Period $series - An array or a string that has the following format {1,2,4}. Should be of integer or floating point numbers.
start
$ck = $ts->start(); $ts->start($ck);
The start
method is the start position accesor. It can be used to get or set the start position. Setting the start position directly is strongly discouraged. Use clip
or resize
instead.
end
$ck = $ts->end(); $ts->end($ck);
The end
method is the end position accesor. It can be used to get or set the end position. Setting the end position directly is strongly discouraged. Use clip
or resize
instead.
period
$period = $ts->period(); $ts->period($period);
The period
method is the period of the time series. It can be used to get or set the period. Setting the end period directly is strongly discouraged.
series
\@series = $ts->series(); $ts->series(\@series); $ts->series("{1,2,3}");
The series
method is the series of the time series. It can be used to get or set the series. Setting the end series directly is somewhat discouraged. If you do set it, make sure it is the same length as the one you are replacing.
getCalcLen
$length = $ts->getCalcLen();
The getCalcLen
method is used to get the number of periods from the start and end positions (inclusive). It should be the same length as the series array.
addPoint
$ts->addPoint(Data::TimeSeries::FIRST, 10.00); $ts->addPoint(Data::TimeSeries::LAST, 15.00); $ts->addPoint($ck, 12.00);
addPoint
Method allows you to add a new point to the beginning or end of a timeseries. Or you can add it somewhere within the series. The ChronoKey ($ck) must be within the existing range. The series will be stretched forward to accomodate the new point.
removePoint
$ts->removePoint(Data::TimeSeries::FIRST); $ts->removePoint(Data::TimeSeries::LAST); $ts->removePoint($ck);
The inverse of addPoint. Allows you to remove the first, last or a cnter point.
getPoint
$ts->getPoint(Data::TimeSeries::FIRST); $ts->getPoint(Data::TimeSeries::LAST); $ts->removePoint($ck);
getPoint
gets the point at the specified position.
getLength
$len=$ts->getLength();
getLength
gets the length of the time series.
shift
$ts->shift($units)
shift
shifts the time series by $units number of periods.
seasonalize
$ts->seasonalize()
normalize
$ts->normalize()
Takes the time series and makes it sum to 1.
resize
$ts->resize($start, $end)
Stretches or shrinks the time series to fit the $start and $end chronokeys. Linear Interpolation is used to build missing values.
seriesOperate
$ts->seriesOperate(sub {$_*=20;})
Runs an operation on every item in the series.
clip
$ts->clip($startCK,$endCK);
Cuts down the time series to the specified start and end positions.
copy
$ts2=$ts->copy();
Creates a copy of the time series.
Runs an operation on every item in the series.
TODO =item regression
($slope, $constant)=$ts->regression();
Runs a regression algorithm on a time series.
Data::TimeSeries allows easy manipulation of timeseries related data.
None by default.
ts(at)atlantageek.com
perl.