nautilus_analysis/python/statistics/
mod.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2025 Posei Systems Pty Ltd. All rights reserved.
3//  https://poseitrader.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 expectancy;
19pub mod long_ratio;
20pub mod loser_avg;
21pub mod loser_max;
22pub mod loser_min;
23pub mod profit_factor;
24pub mod returns_avg;
25pub mod returns_avg_loss;
26pub mod returns_avg_win;
27pub mod returns_volatlity;
28pub mod risk_return_ratio;
29pub mod sharpe_ratio;
30pub mod sortino_ratio;
31pub mod win_rate;
32pub mod winner_avg;
33pub mod winner_max;
34pub mod winner_min;
35
36use std::collections::BTreeMap;
37
38use nautilus_core::UnixNanos;
39
40fn transform_returns(raw_returns: BTreeMap<u64, f64>) -> BTreeMap<UnixNanos, f64> {
41    raw_returns
42        .keys()
43        .map(|&k| (UnixNanos::from(k), raw_returns[&k]))
44        .collect()
45}