use std::collections::BTreeMap;
use pyo3::prelude::*;
use super::transform_returns;
use crate::{statistic::PortfolioStatistic, statistics::cagr::CAGR};
#[pymethods]
#[pyo3_stub_gen::derive::gen_stub_pymethods]
impl CAGR {
#[new]
#[pyo3(signature = (period=None))]
fn py_new(period: Option<usize>) -> Self {
Self::new(period)
}
#[getter]
#[pyo3(name = "name")]
fn py_name(&self) -> String {
self.name()
}
#[pyo3(name = "calculate_from_returns")]
#[allow(clippy::needless_pass_by_value)]
fn py_calculate_from_returns(&self, raw_returns: BTreeMap<u64, f64>) -> Option<f64> {
self.calculate_from_returns(&transform_returns(&raw_returns))
}
fn __repr__(&self) -> String {
format!("CAGR({})", self.name())
}
}