#traits #polars #analysis #datatype #tevec #financial-analysis #vec

tea-dtype

A library to provide datatype and useful traits for datatype

16 releases

0.4.5 Nov 18, 2024
0.4.4 Sep 13, 2024
0.4.0 Aug 31, 2024
0.3.3 Aug 21, 2024
0.2.5 Jul 24, 2024

#225 in Finance

Download history 350/week @ 2024-08-17 49/week @ 2024-08-24 316/week @ 2024-08-31 473/week @ 2024-09-07 132/week @ 2024-09-14 36/week @ 2024-09-21 56/week @ 2024-09-28 7/week @ 2024-10-05 7/week @ 2024-10-12 7/week @ 2024-10-19 4/week @ 2024-10-26 10/week @ 2024-11-02 148/week @ 2024-11-16 38/week @ 2024-11-23 27/week @ 2024-11-30

214 downloads per month
Used in 6 crates (3 directly)

MIT license

79KB
2K SLoC

Tevec

Build Crates.io Version

Introduction

Tevec is a powerful Rust crate designed for financial quantitative analysis, supporting multiple backends including Vec, VecDeque, Ndarray, and Polars. The crate leverages Rust's trait system to provide a flexible and extensible framework for future backend integrations.

Tevec's functionality is categorized into three main types:

  • Rolling functions
  • Mapping functions
  • Aggregation functions

Installation

To include Tevec in your project, add the following line to your Cargo.toml:

tevec = "0.4"

Basic Usage

First, import the common trait names to call the corresponding methods. use tevec::prelude::*

Aggregation Functions

Most aggregation functions are implemented for structs that satisfy the IntoIterator + Sized traits.

use tevec::prelude::*;
let data = vec![1, 2, 3, 4, 5];
data.titer().mean();  // not consume data, return Some(3)
data.mean();  // consume data, return Some(3)
let data = vec![1., f64::NAN, 3.];
data.titer().vmean();  // valid mean, this will ignore nan, return 2.
// valid function can also be used for Option<T> dtype
let data = vec![Some(1), None, Some(3)];
data.vmean(); // return 2.

Using titer returns an Iterator that satisfies TrustedLen, allowing for further method calls. The titer method comes from the Titer trait, which has been implemented for all backends.

Rolling Functions

use tevec::prelude::*;
let data = vec![1, 2, 3, 4, 5];
let mean: Vec<f64> = data.ts_mean(3, Some(1)); // params: window, min_periods
#[cfg(feature = "ndarray")]
{   
    use tevec::export::ndarray::Array1;  // reexported from ndarray crate
    let mean2: Array1<f32> = data.ts_vmean(4, None); // rolling_mean function ignore none values
}

Mapping Functions

use tevec::prelude::*;
let v = vec![1., 2., 3., 4., 5.];
let shift_v: Vec<_> = v.titer().vshift(2, None).collect_trusted_vec1();
let shfit_abs_v: Vec<_> = v.titer().abs().vshift(2, None).collect_trusted_vec1();

Some mapping functions return an Iterator, allowing for chained calls without reallocating memory, and only collecting the iterator when needed.

Feature Flags

pl: For Polars backend

ndarray: For Ndarray backend

vecdeque: For VecDeque backend

agg: Aggregate Functions

map: Mapping Functions

rolling: Rolling Functions

stat: Statistic Functions

time: DateTime and TimeDelta structs

Contributing

Contributions to Tevec are welcome! Here's how you can contribute:

  1. Fork the repository
  2. Create a new branch for your feature or bug fix
  3. Make your changes and write tests if applicable
  4. Run make format to ensure your code follows the project's style guidelines
  5. Run make test to make sure all tests pass
  6. Submit a pull request with a clear description of your changes

Please make sure to update tests as appropriate and adhere to the existing coding style.

License

This project is licensed under the MIT License.

Dependencies

~0.1–11MB
~118K SLoC