| 128 | } |
| 129 | |
| 130 | fn resample_prices(prices: &DMatrix<f64>, step: usize) -> DMatrix<f64> { |
| 131 | if step <= 1 { |
| 132 | return prices.clone_owned(); |
| 133 | } |
| 134 | let mut flat = Vec::new(); |
| 135 | let mut out_rows = 0; |
| 136 | for r in (step - 1..prices.nrows()).step_by(step) { |
| 137 | for c in 0..prices.ncols() { |
| 138 | flat.push(prices[(r, c)]); |
| 139 | } |
| 140 | out_rows += 1; |
| 141 | } |
| 142 | if out_rows == 0 { |
| 143 | prices.clone_owned() |
| 144 | } else { |
| 145 | DMatrix::from_vec(out_rows, prices.ncols(), flat) |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | fn returns_from_prices(prices: &DMatrix<f64>) -> Result<DMatrix<f64>, HrpError> { |
| 150 | if prices.nrows() < 2 { |