Skip to content

HMath.TimeSeries.Core

Module index · Numerical conventions

Description

Timestamped finite observations. Times are caller-defined numeric units, strictly increasing, with explicit missing values. No implicit calendar, time zone, sorting, duplicate aggregation, or extrapolation occurs. Reference operations accept at most 16,384 observations; quadratic operations impose tighter bounds. A regular series is a timestamped series with a positive step.

On this page

API Purpose
Series Opaque, validated timestamps paired with optional observations.
series Preserve order and missing values; reject duplicate or nonfinite times.
regularSeries Sample times start+i*step.
observations Extract time-ordered (timestamp,Maybe value) observations from a validated Series.
seriesValues Complete-data conversion never silently drops a missing observation.
isRegular Relative spacing tolerance; fewer than three observations are regular.
Alignment Time-series timestamp join policy: Inner intersection or Outer union,with missing values explicit.
Inner Declaration and type contract below.
Outer Declaration and type contract below.
LeftAligned Declaration and type contract below.
align Exact timestamp equality.
Fill Missing-value strategy selecting forward fill,backward fill,or linear interpolation under the checked boundary rules.
ForwardFill Declaration and type contract below.
BackwardFill Declaration and type contract below.
LinearFill Declaration and type contract below.
fillMissing Directional filling leaves the unavailable leading/trailing end missing.
Resampling Series resampling policy selecting bin means,last-bin values,or linear point samples.
LinearSamples Declaration and type contract below.
BinMean Declaration and type contract below.
BinLast Declaration and type contract below.
resample Linear samples require brackets (or an exact timestamp).
Rolling Rolling-window statistic selector for mean,variance,standard deviation,minimum,or maximum.
MovingMean Declaration and type contract below.
MovingVariance Declaration and type contract below.
MovingSD Declaration and type contract below.
MovingMinimum Declaration and type contract below.
MovingMaximum Declaration and type contract below.
rolling Full trailing windows only; variance is population variance (ddof=0).
exponentialAverage Recursive EMA, initialized at the first observation; 0<alpha<=1.
weightedAverage Nonnegative chronological weights: first weight multiplies oldest sample.
cumulativeReturns Cumulative simple return relative to the first strictly positive price.
logarithmicReturns Consecutive log returns, using log prices to avoid ratio overflow.
difference Apply (1-B^lag)^order.
autocorrelation Biased covariance divided by lag-zero covariance, global sample mean.
crossCorrelation Corr(x_t,y_(t+lag)), global means and full lag-zero energy normalization.
durbinLevinson Levinson recursion for a positive definite Toeplitz covariance.
yuleWalker Biased sample autocovariances with centered data; returns mean separately.
partialAutocorrelation Given maximum lag then samples, compute ACF and Durbin-Levinson partial correlations, returning lag zero (1) followed by requested PACF lags.
finite Test whether Double is neither NaN nor infinite.
require Given predicate then message, return Right () or time-series-prefixed Left InvalidArgument.
checked Return list unchanged when every sample is finite; otherwise return Left NonFiniteResult.
validate Given minimum sample count then list, require length between that minimum and 16384 and all finite values.
average Unchecked arithmetic average using per-term division by list length; empty list returns zero by empty sum.

Documentation

Series

data Series Source #

Opaque, validated timestamps paired with optional observations.

Instances

Instances details
Show Series Source # 
Instance details

Defined in HMath.TimeSeries.Core

Eq Series Source # 
Instance details

Defined in HMath.TimeSeries.Core

Methods

(==) :: Series -> Series -> Bool #

(/=) :: Series -> Series -> Bool #

series

series :: [(Double, Maybe Double)] -> Either MathError Series Source #

Preserve order and missing values; reject duplicate or nonfinite times.

regularSeries

regularSeries :: Double -> Double -> [Maybe Double] -> Either MathError Series Source #

Sample times start+i*step. Rounded duplicate times are rejected as well.

observations

observations :: Series -> [(Double, Maybe Double)] Source #

Extract time-ordered (timestamp,Maybe value) observations from a validated Series. Missing values remain Nothing.

seriesValues

seriesValues :: Series -> Either MathError [Double] Source #

Complete-data conversion never silently drops a missing observation.

isRegular

isRegular :: Double -> Series -> Either MathError Bool Source #

Relative spacing tolerance; fewer than three observations are regular.

Alignment

data Alignment Source #

Time-series timestamp join policy: Inner intersection or Outer union,with missing values explicit.

Constructors

Inner 
Outer 
LeftAligned 

Instances

Instances details
Show Alignment Source # 
Instance details

Defined in HMath.TimeSeries.Core

Eq Alignment Source # 
Instance details

Defined in HMath.TimeSeries.Core

align

align :: Alignment -> Series -> Series -> Either MathError (Series, Series) Source #

Exact timestamp equality. Missing alignment positions are explicit Nothing.

Fill

data Fill Source #

Missing-value strategy selecting forward fill,backward fill,or linear interpolation under the checked boundary rules.

Instances

Instances details
Show Fill Source # 
Instance details

Defined in HMath.TimeSeries.Core

Methods

showsPrec :: Int -> Fill -> ShowS #

show :: Fill -> String #

showList :: [Fill] -> ShowS #

Eq Fill Source # 
Instance details

Defined in HMath.TimeSeries.Core

Methods

(==) :: Fill -> Fill -> Bool #

(/=) :: Fill -> Fill -> Bool #

fillMissing

fillMissing :: Fill -> Series -> Either MathError Series Source #

Directional filling leaves the unavailable leading/trailing end missing. Linear filling interpolates between finite anchors and never extrapolates.

Resampling

data Resampling Source #

Series resampling policy selecting bin means,last-bin values,or linear point samples.

Constructors

LinearSamples 
BinMean 
BinLast 

Instances

Instances details
Show Resampling Source # 
Instance details

Defined in HMath.TimeSeries.Core

Eq Resampling Source # 
Instance details

Defined in HMath.TimeSeries.Core

resample

resample :: Resampling -> Double -> Double -> Int -> Series -> Either MathError Series Source #

Linear samples require brackets (or an exact timestamp). Bins are [start+i*step,start+(i+1)*step); the final right endpoint is excluded.

Rolling

data Rolling Source #

Rolling-window statistic selector for mean,variance,standard deviation,minimum,or maximum.

Instances

Instances details
Show Rolling Source # 
Instance details

Defined in HMath.TimeSeries.Core

Eq Rolling Source # 
Instance details

Defined in HMath.TimeSeries.Core

Methods

(==) :: Rolling -> Rolling -> Bool #

(/=) :: Rolling -> Rolling -> Bool #

rolling

rolling :: Rolling -> Int -> [Double] -> Either MathError [Double] Source #

Full trailing windows only; variance is population variance (ddof=0).

exponentialAverage

exponentialAverage :: Double -> [Double] -> Either MathError [Double] Source #

Recursive EMA, initialized at the first observation; 0<alpha<=1.

weightedAverage

weightedAverage :: [Double] -> [Double] -> Either MathError [Double] Source #

Nonnegative chronological weights: first weight multiplies oldest sample.

cumulativeReturns

cumulativeReturns :: [Double] -> Either MathError [Double] Source #

Cumulative simple return relative to the first strictly positive price.

logarithmicReturns

logarithmicReturns :: [Double] -> Either MathError [Double] Source #

Consecutive log returns, using log prices to avoid ratio overflow.

difference

difference :: Int -> Int -> [Double] -> Either MathError [Double] Source #

Apply (1-B^lag)^order. Zero order preserves data; at least one output is required.

autocorrelation

autocorrelation :: Int -> [Double] -> Either MathError [Double] Source #

Biased covariance divided by lag-zero covariance, global sample mean.

crossCorrelation

crossCorrelation :: Int -> [Double] -> [Double] -> Either MathError Double Source #

Corr(x_t,y_(t+lag)), global means and full lag-zero energy normalization.

durbinLevinson

durbinLevinson :: [Double] -> Either MathError ([Double], Double, [Double]) Source #

Levinson recursion for a positive definite Toeplitz covariance. Returns AR coefficients, innovation variance, and PACF (without the lag-zero one).

yuleWalker

yuleWalker :: Int -> [Double] -> Either MathError ([Double], Double, Double) Source #

Biased sample autocovariances with centered data; returns mean separately.

partialAutocorrelation

partialAutocorrelation :: Int -> [Double] -> Either MathError [Double] Source #

Given maximum lag then samples, compute ACF and Durbin-Levinson partial correlations, returning lag zero (1) followed by requested PACF lags. Invalid lag/data or singular covariance recurrence returns Left MathError.

finite

finite :: Double -> Bool Source #

Test whether Double is neither NaN nor infinite.

require

require :: Bool -> String -> Either MathError () Source #

Given predicate then message, return Right () or time-series-prefixed Left InvalidArgument.

checked

checked :: [Double] -> Either MathError [Double] Source #

Return list unchanged when every sample is finite; otherwise return Left NonFiniteResult.

validate

validate :: Int -> [Double] -> Either MathError () Source #

Given minimum sample count then list, require length between that minimum and 16384 and all finite values. Invalid input returns Left InvalidArgument.

average

average :: [Double] -> Double Source #

Unchecked arithmetic average using per-term division by list length; empty list returns zero by empty sum. Checked statistical callers validate nonempty input first.