pub struct BatchParams {
pub num_stocks: usize,
pub total_time: usize,
pub cur_time: usize,
pub length: usize,
}Expand description
Parameters for batch computation of factor values over time series data.
BatchParams defines the dimensions and time window for batch factor computation.
It specifies how many stocks to process, the total time series length, and which
subset of time points to compute.
§Data Layout
KunQuant expects data in time-series format where:
- Rows represent time points (e.g., trading days)
- Columns represent stocks
- Data is stored in row-major order:
[t0_s0, t0_s1, ..., t0_sN, t1_s0, ...]
§SIMD Requirements
For optimal performance, num_stocks must be a multiple of 8 to enable
SIMD (Single Instruction, Multiple Data) vectorization.
Fields§
§num_stocks: usizeNumber of stocks to process (must be multiple of 8 for SIMD optimization)
total_time: usizeTotal number of time points in the input data arrays
cur_time: usizeStarting time index for computation (0-based)
length: usizeNumber of consecutive time points to compute
Implementations§
Source§impl BatchParams
impl BatchParams
Sourcepub fn new(
num_stocks: usize,
total_time: usize,
cur_time: usize,
length: usize,
) -> Result<Self>
pub fn new( num_stocks: usize, total_time: usize, cur_time: usize, length: usize, ) -> Result<Self>
Creates new batch computation parameters with validation.
This constructor validates that the stock count meets SIMD requirements and that the time window parameters are consistent.
§Arguments
num_stocks- Number of stocks to process (must be multiple of 8)total_time- Total number of time points in input datacur_time- Starting time index for computation (0-based)length- Number of consecutive time points to compute
§Returns
Returns Ok(BatchParams) on success, or an error if:
num_stocksis not a multiple of 8cur_time + length > total_time(time window exceeds data bounds)- Any parameter is invalid
§Examples
use kunquant_rs::BatchParams;
// Process 16 stocks over 100 time points, computing all points
let params = BatchParams::new(16, 100, 0, 100)?;
// Process 8 stocks, compute only the last 20 time points
let params = BatchParams::new(8, 252, 232, 20)?;
// This would fail - stock count not multiple of 8
// let invalid = BatchParams::new(10, 100, 0, 100)?; // Error!§Performance Notes
- Larger
num_stocksvalues (multiples of 8) enable better SIMD utilization - Smaller
lengthvalues reduce memory usage and computation time cur_timeandlengthallow processing data in chunks for memory efficiency
Sourcepub fn full_range(num_stocks: usize, total_time: usize) -> Result<Self>
pub fn full_range(num_stocks: usize, total_time: usize) -> Result<Self>
Creates parameters for computing the entire time range.
This is a convenience method that creates batch parameters to process
all time points in the dataset, equivalent to calling
BatchParams::new(num_stocks, total_time, 0, total_time).
§Arguments
num_stocks- Number of stocks to process (must be multiple of 8)total_time- Total number of time points in the data
§Returns
Returns Ok(BatchParams) configured to process the entire time range,
or an error if num_stocks is not a multiple of 8.
§Examples
use kunquant_rs::BatchParams;
// Process all 252 trading days for 16 stocks
let params = BatchParams::full_range(16, 252)?;
// Equivalent to:
// let params = BatchParams::new(16, 252, 0, 252)?;§Use Cases
- Historical backtesting over complete datasets
- Factor computation for entire time series
- Initial factor validation and testing
- Scenarios where memory constraints are not a concern
Trait Implementations§
Source§impl Clone for BatchParams
impl Clone for BatchParams
Source§fn clone(&self) -> BatchParams
fn clone(&self) -> BatchParams
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more