Skip to main content

TimeSeries

Struct TimeSeries 

Source
pub struct TimeSeries {
    pub name: String,
    pub timestamps: Vec<i64>,
    pub values: ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>,
    pub frequency: Option<Frequency>,
    pub metadata: HashMap<String, String>,
}
Expand description

Time series data structure

Fields§

§name: String

Series name

§timestamps: Vec<i64>

Time index (Unix timestamps in seconds)

§values: ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>

Values

§frequency: Option<Frequency>

Frequency (if regular)

§metadata: HashMap<String, String>

Metadata

Implementations§

Source§

impl TimeSeries

Source

pub fn new( name: impl Into<String>, timestamps: Vec<i64>, values: ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, frequency: Option<Frequency>, ) -> Result<TimeSeries, Error>

Create a new time series from arrays

Source

pub fn from_dataframe( df: &DataFrame, value_col: &str, date_col: &str, ) -> Result<TimeSeries, Error>

Create from DataFrame with date and value columns

Source

pub fn regular( name: impl Into<String>, values: ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, frequency: Frequency, ) -> TimeSeries

Create a regular time series with integer index

Source

pub fn len(&self) -> usize

Get series length

Source

pub fn is_empty(&self) -> bool

Check if series is empty

Source

pub fn name(&self) -> &str

Get series name

Source

pub fn values(&self) -> &ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>

Get values

Source

pub fn timestamps(&self) -> &[i64]

Get timestamps

Source

pub fn frequency(&self) -> Option<Frequency>

Get frequency

Source

pub fn set_metadata(&mut self, key: impl Into<String>, value: impl Into<String>)

Set metadata

Source

pub fn get_metadata(&self, key: &str) -> Option<&String>

Get metadata

Source

pub fn start_time(&self) -> Option<i64>

Get start time

Source

pub fn end_time(&self) -> Option<i64>

Get end time

Source

pub fn stats(&self) -> TimeSeriesStats

Compute basic statistics

Source

pub fn diff(&self, lag: usize, order: usize) -> Result<TimeSeries, Error>

Differencing: y_t - y_{t-d}

Source

pub fn log(&self, offset: f64) -> TimeSeries

Log transformation (with offset to handle zeros/negatives)

Source

pub fn boxcox(&self, lambda: f64) -> TimeSeries

Box-Cox transformation

Source

pub fn slice( &self, start: Option<i64>, end: Option<i64>, ) -> Result<TimeSeries, Error>

Slice time series

Source

pub fn fillna(&self, method: FillMethod) -> TimeSeries

Fill missing values (NaN) using specified method

Source

pub fn detect_outliers(&self, threshold: f64) -> Vec<usize>

Detect outliers using IQR method

Source

pub fn to_dataframe(&self) -> DataFrame

Convert to DataFrame

Trait Implementations§

Source§

impl ARIMAExt for TimeSeries

Source§

fn arima(&self, p: usize, d: usize, q: usize) -> Result<ARIMAResults, Error>

Fit ARIMA model
Source§

impl Clone for TimeSeries

Source§

fn clone(&self) -> TimeSeries

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TimeSeries

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl DecompositionExt for TimeSeries

Source§

fn decompose_ma( &self, method: DecompositionMethod, period: usize, ) -> Result<DecompositionResults, Error>

Moving average decomposition
Source§

fn decompose_stl(&self, period: usize) -> Result<DecompositionResults, Error>

STL decomposition
Source§

fn hp_filter(&self, lambda: f64) -> Result<(TimeSeries, TimeSeries), Error>

Hodrick-Prescott filter
Source§

fn x12_adjust(&self, period: usize) -> Result<TimeSeries, Error>

X-12-ARIMA seasonal adjustment
Source§

impl<'de> Deserialize<'de> for TimeSeries

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<TimeSeries, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl GARCHExt for TimeSeries

Source§

fn garch(&self, p: usize, q: usize) -> Result<GARCHResults, Error>

Fit GARCH model
Source§

fn arch(&self, q: usize) -> Result<GARCHResults, Error>

Fit ARCH model
Source§

impl Serialize for TimeSeries

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ByRef<T> for T

Source§

fn by_ref(&self) -> &T

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DistributionExt for T
where T: ?Sized,

Source§

fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> T
where Self: Distribution<T>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,