nautilus_analysis/
lib.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//! Portfolio analysis and performance metrics for [PoseiTrader](http://poseitrader.io).
17//!
18//! The *analysis* crate provides a comprehensive suite of portfolio analysis tools and performance
19//! statistics for evaluating trading strategies and portfolios. This includes return-based metrics,
20//! PnL-based statistics, and risk measurements commonly used in quantitative finance:
21//!
22//! - Portfolio analyzer for tracking account states and positions.
23//! - Extensive collection of performance statistics and risk metrics.
24//! - Flexible statistic calculation framework supporting different data sources.
25//! - Support for multi-currency portfolios and unrealized PnL calculations.
26//!
27//! # Platform
28//!
29//! [PoseiTrader](http://poseitrader.io) is an open-source, high-performance, production-grade
30//! algorithmic trading platform, providing quantitative traders with the ability to backtest
31//! portfolios of automated trading strategies on historical data with an event-driven engine,
32//! and also deploy those same strategies live, with no code changes.
33//!
34//! PoseiTrader's design, architecture, and implementation philosophy prioritizes software correctness and safety at the
35//! highest level, with the aim of supporting mission-critical, trading system backtesting and live deployment workloads.
36//!
37//! # Feature flags
38//!
39//! This crate provides feature flags to control source code inclusion during compilation,
40//! depending on the intended use case, i.e. whether to provide Python bindings
41//! for the [posei_trader](https://pypi.org/project/posei_trader) Python package,
42//! or as part of a Rust only build.
43//!
44//! - `python`: Enables Python bindings from [PyO3](https://pyo3.rs).
45
46#![warn(rustc::all)]
47#![deny(unsafe_code)]
48#![deny(nonstandard_style)]
49#![deny(missing_debug_implementations)]
50#![deny(clippy::missing_errors_doc)]
51#![deny(clippy::missing_panics_doc)]
52#![deny(rustdoc::broken_intra_doc_links)]
53
54pub mod analyzer;
55pub mod statistic;
56pub mod statistics;
57
58#[cfg(feature = "python")]
59pub mod python;
60
61use std::collections::BTreeMap;
62
63use nautilus_core::UnixNanos;
64
65/// Type alias for time-indexed returns data used in portfolio analysis.
66///
67/// Maps timestamps to return values for time-series analysis of portfolio performance.
68pub type Returns = BTreeMap<UnixNanos, f64>;