nautilus_analysis/python/statistics/mod.rs
1// -------------------------------------------------------------------------------------------------
2// Copyright (C) 2015-2026 Nautech Systems Pty Ltd. All rights reserved.
3// https://nautechsystems.io
4//
5// Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
6// You may not use this file except in compliance with the License.
7// You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14// -------------------------------------------------------------------------------------------------
15
16//! Python bindings for trading performance statistics.
17
18pub mod alpha;
19pub mod beta_ratio;
20pub mod cagr;
21pub mod calmar_ratio;
22pub mod expectancy;
23pub mod information_ratio;
24pub mod long_ratio;
25pub mod loser_avg;
26pub mod loser_max;
27pub mod loser_min;
28pub mod max_drawdown;
29pub mod profit_factor;
30pub mod returns_avg;
31pub mod returns_avg_loss;
32pub mod returns_avg_win;
33pub mod returns_volatility;
34pub mod risk_return_ratio;
35pub mod sharpe_ratio;
36pub mod sortino_ratio;
37pub mod tracking_error;
38pub mod treynor_ratio;
39pub mod win_rate;
40pub mod winner_avg;
41pub mod winner_max;
42pub mod winner_min;
43
44use std::collections::BTreeMap;
45
46use nautilus_core::UnixNanos;
47
48fn transform_returns(raw_returns: &BTreeMap<u64, f64>) -> BTreeMap<UnixNanos, f64> {
49 raw_returns
50 .keys()
51 .map(|&k| (UnixNanos::from(k), raw_returns[&k]))
52 .collect()
53}