| 64 | |
| 65 | pub fn returns_method_from_str(name: &str) -> Result<ReturnsMethod, AllocError> { |
| 66 | match name.to_lowercase().as_str() { |
| 67 | "mean" | "mean_historical" => Ok(ReturnsMethod::Mean), |
| 68 | "exponential" | "exponential_historical" => Ok(ReturnsMethod::Exponential { span: 500 }), |
| 69 | other => Err(AllocError::UnknownReturns(other.to_string())), |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | fn returns_from_prices(prices: &DMatrix<f64>) -> Result<DMatrix<f64>, AllocError> { |
| 74 | let rows = prices.nrows(); |
| 75 | let cols = prices.ncols(); |
| 76 | if rows < 2 { |
| 77 | return Err(AllocError::NoData); |
| 78 | } |
| 79 | let mut out = DMatrix::<f64>::zeros(rows - 1, cols); |
| 80 | for r in 1..rows { |