# UnrollingAverages

UnrollingAverages is a Julia package aimed at *reversing* (or *unrolling*) moving averages of time series to get the original ones back.

UnrollingAverages currently assumes that the moving average is a simple moving average. Further relaxations and extensions may come in the future, see Future Developments section.

## Installation

Press `]`

in the Julia REPL and then

`pkg> add https://github.com/InPhyT/UnrollingAverages.jl`

## Usage

The package exports a single function called `unroll`

: it returns a `Vector`

whose elements are the possible original time series.

`unroll(moving_average::Vector{Float64}, window::Int64; initial_conditions::U = nothing, assert_natural::Bool = false) where { U <: Union{ Tuple{Vararg{Union{Int64,Float64}}},Nothing} }`

**Arguments**:

`moving_average`

: the time series representing the moving average to unroll ;`window`

: the width of the moving average ;`initial_conditions`

: the initial values of the original time series to be recovered. It may be a`Tuple`

of`window-1`

positive integer values, or`nothing`

if initial conditions are unknown. Currently it is not possible to specify values in the middle of the time series, this may be a feature to be added in the future ;`assert_natural`

default boolean argument. If true, the pipeline will try to recover a time series of natural numbers only. More then one acceptable time series (where "acceptable" means that it reproduces`moving_average`

) may be found and all will be returned.

A few remarks:

- If
`isnothing(initial_conditions)`

:`if assert_natural`

, then an internal`unroll_iterative`

method is called, which tries to exactly recover the whole time series, initial conditions included. Enter`?UnrollingAverages.unroll_iterative`

in a julia to read details ;`if !assert_natural`

, then an internal`unroll_linear_approximation`

method is called. See this StackExchange post. NB: this is an approximated method, it will generally not return the exact original time series ;

- If
`typeof(initial_conditions) <: Ntuple{window-1, <:Union{Int64,Float64}}`

, then an internal`unroll_recursive`

method is called, which exactly recovers the time series. Mathematical details about this function are reported in the documentation, and you may read more by entering`?UnrollingAverages.unroll_recursive`

.

## Future Developments

- Modify
`initial_conditions`

argument of`unroll`

so that it accepts known values throughout the series ; - Implement reversing methods for other types of moving averages .

## How to Contribute

If you wish to change or add some functionality, please file an issue. Some suggestions may be found in the Future Developments section.

## How to Cite

If you use this data in your work, please cite this repository using the following metadata:

```
@software{UnrollingAverages.jl,
author = {Pietro Monticone, Claudio Moroni},
title = {UnrollingAverages.jl},
url = {https://doi.org/10.5281/zenodo.5725302},
doi = {10.5281/zenodo.5725302},
keywords = {Time Series, Statistics, Data Analysis},
version = {v0.1.0},
year = {2021},
month = {11}
}
```