train_test_split

Defined in fynance.data

train_test_split(n, test_size, gap=0)[source]

Time-ordered train/test index split.

Parameters:
nint

Number of observations.

test_sizefloat or int

Trailing test set size. A value strictly inside (0, 1) is read as a fraction of n (e.g. 0.2 -> round(0.2 * n)); any other value – including the bounds 0.0 and 1.0 – is read as an absolute count (int(test_size)). In particular 1.0 means a single observation (count 1), not the whole series, and 0.0 means an empty test set; pass a fraction strictly between the bounds to get a proportional split.

gapint

Embargo: observations dropped between train end and test start.

Returns:
(train_idx, test_idx)tuple of numpy.ndarray

test_idx is strictly after train_idx (no leakage).