Timeseries Package

Algebra

abs_(x)

Absolute value of each element in series

add(x, y[, method])

Add two series or scalars

and_(*series)

Logical "and" of two or more boolean series.

ceil(x[, value])

Cap series at maximum value

divide(x, y[, method])

Divide two series or scalars

exp(x)

Exponential of series

filter_(x[, operator, value])

Removes values where comparison with the operator and value combination results in true, defaults to removing missing values from the series

filter_dates(x[, operator, dates])

Removes dates where comparison with the operator and dates combination results in true, defaults to removing missing values from the series

floor(x[, value])

Floor series at minimum value

floordiv(x, y[, method])

Floor divide two series or scalars

if_(flags, x, y)

Returns a series s.

log(x)

Natural logarithm of series

multiply(x, y[, method])

Multiply two series or scalars

not_(series)

Logical negation of a single boolean series.

or_(*series)

Logical "or" of two or more boolean series.

power(x[, y])

Raise each element in series to power

sqrt(x)

Square root of (a) each element in a series or (b) a real number

subtract(x, y[, method])

Add two series or scalars

weighted_sum(series, weights)

Calculate a weighted sum.

Analysis

diff(x[, obs])

Diff observations with given lag

first(x)

First value of series

last(x)

Last value of series (as a series)

last_value(x)

Last value of series (as a scalar)

count(x)

Count observations in series

lag(x[, obs, mode])

Lag timeseries by a number of observations or a relative date.

Backtesting

basket_series(series[, weights, costs, ...])

Calculates a basket return series.

Basket(stocks[, weights, rebal_freq])

Construct a basket of stocks

Date / Time

align(x, y[, method])

Align dates of two series or scalars

interpolate(x[, dates, method])

Interpolate over specified dates or times

value(x, date[, method])

Value at specified date or time

day(x)

Day of each value in series

weekday(x)

Weekday of each value in series

month(x)

Month of each value in series

year(x)

Year of each value in series

quarter(x)

Quarter of each value in series

date_range(x, start_date, end_date[, ...])

Create a time series from a (sub-)range of dates in an existing time series.

prepend(x)

Prepend data series

union(x)

Fill in missing dates or times of one series with another

bucketize(series, aggregate_function, period)

Bucketize a series and apply aggregate function to each bucket

Window([w, r])

Create a Window with size and ramp up to use.

Econometrics

annualize(x)

Annualize series based on sample observation frequency

beta(x, b[, w, prices])

Rolling beta of price series and benchmark

change(x)

Arithmetic series normalization

correlation(x, y[, w, type_])

Rolling correlation of two price series

excess_returns_(price_series[, currency])

Calculate excess returns

index(x[, initial])

Geometric series normalization

max_drawdown(x[, w])

Compute the maximum peak to trough drawdown over a rolling window as a ratio.

prices(series[, initial, type])

Calculate price levels from returns series

returns(series[, obs, type])

Calculate returns from price series

sharpe_ratio(series[, currency, w, ...])

Calculate Sharpe ratio

volatility(x[, w, returns_type])

Realized volatility of price series

Statistics

cov(x, y[, w])

Rolling co-variance of series over given window

exponential_std(x[, beta])

Exponentially weighted standard deviation

generate_series(length[, direction])

Generate sample timeseries

max_(x[, w])

Maximum value of series over given window

mean(x[, w])

Arithmetic mean of series over given window

median(x[, w])

Median value of series over given window

min_(x[, w])

Minimum value of series over given window

mode(x[, w])

Most common value in series over given window

percentile(x, n[, w])

Returns the nth percentile of a series.

percentiles(x[, y, w])

Rolling percentiles over given window

product(x[, w])

Rolling product of series over given window

range_(x[, w])

Range of series over given window

std(x[, w])

Rolling standard deviation of series over given window

sum_(x[, w])

Rolling sum of series over given window

var(x[, w])

Rolling variance of series over given window

winsorize(x[, limit, w])

Limit extreme values in series

zscores(x[, w])

Rolling z-scores over a given window

LinearRegression(X, y[, fit_intercept])

Fit an Ordinary least squares (OLS) linear regression model.

RollingLinearRegression(X, y, w[, fit_intercept])

Fit a rolling ordinary least squares (OLS) linear regression model.

SIRModel([beta, gamma, s, i, r, n, fit, ...])

SIR Compartmental model for transmission of infectious disease

SEIRModel([beta, gamma, sigma, s, e, i, r, ...])

SEIR Compartmental model for transmission of infectious disease

Technical Analysis

bollinger_bands(x[, w, k])

Bollinger bands with given window and width

moving_average(x[, w])

Moving average over specified window

exponential_moving_average(x[, beta])

Exponentially weighted moving average

exponential_volatility(x[, beta])

Exponentially weighted volatility

exponential_spread_volatility(x[, beta])

Exponentially weighted spread volatility

smoothed_moving_average(x[, w])

Smoothed moving average over specified window

relative_strength_index(x[, w])

Relative Strength Index

macd(x[, m, n, s])

Moving average convergence divergence (MACD).