Analysis ¶
The analysis subpackage groups components relating to trading performance statistics and analysis.
- class PortfolioAnalyzer ¶
-
Bases:
object
Provides a portfolio performance analyzer for tracking and generating performance metrics and statistics.
- register_statistic ( statistic : PortfolioStatistic ) None ¶
-
Register the given statistic with the analyzer.
- Parameters :
-
statistic ( PortfolioStatistic ) – The statistic to register.
- deregister_statistic ( statistic : PortfolioStatistic ) None ¶
-
Deregister a statistic from the analyzer.
- deregister_statistics ( ) None ¶
-
Deregister all statistics from the analyzer.
- reset ( ) None ¶
-
Reset the analyzer.
All stateful fields are reset to their initial value.
- property currencies : list [ nautilus_trader.model.currency.Currency ] ¶
-
Return the analyzed currencies.
- Returns :
-
list[Currency]
- statistic ( name : str ) nautilus_trader.analysis.statistic.PortfolioStatistic | None ¶
-
Return the statistic with the given name (if found).
- Returns :
-
PortfolioStatistic or
None
- returns ( ) Series ¶
-
Return raw the returns data.
- Returns :
-
pd.Series
- calculate_statistics ( account : Account , positions : list [ nautilus_trader.model.position.Position ] ) None ¶
-
Calculate performance metrics from the given data.
- Parameters :
-
-
account ( Account ) – The account for the calculations.
-
positions ( list [ Position ] ) – The positions for the calculations.
-
- add_positions ( positions : list [ nautilus_trader.model.position.Position ] ) None ¶
-
Add positions data to the analyzer.
- Parameters :
-
positions ( list [ Position ] ) – The positions for analysis.
- add_trade ( position_id : PositionId , realized_pnl : Money ) None ¶
-
Add trade data to the analyzer.
- Parameters :
-
-
position_id ( PositionId ) – The position ID for the trade.
-
realized_pnl ( Money ) – The realized PnL for the trade.
-
- add_return ( timestamp : datetime , value : float ) None ¶
-
Add return data to the analyzer.
- Parameters :
-
-
timestamp ( datetime ) – The timestamp for the returns entry.
-
value ( double ) – The return value to add.
-
- realized_pnls ( currency : nautilus_trader.model.currency.Currency | None = None ) pandas.core.series.Series | None ¶
-
Return the realized PnL for the portfolio.
For multi-currency portfolios, specify the currency for the result.
- Parameters :
-
currency ( Currency , optional ) – The currency for the result.
- Returns :
-
pd.Series or
None
- Raises :
-
ValueError – If currency is
None
when analyzing multi-currency portfolios.
- total_pnl ( currency : nautilus_trader.model.currency.Currency | None = None , unrealized_pnl : nautilus_trader.model.objects.Money | None = None ) float ¶
-
Return the total PnL for the portfolio.
For multi-currency portfolios, specify the currency for the result.
- Parameters :
- Returns :
-
float
- Raises :
-
-
ValueError – If currency is
None
when analyzing multi-currency portfolios. -
ValueError – If currency is not contained in the tracked account balances.
-
ValueError – If unrealized_pnl is not
None
and currency is not equal to the given currency.
-
- total_pnl_percentage ( currency : nautilus_trader.model.currency.Currency | None = None , unrealized_pnl : nautilus_trader.model.objects.Money | None = None ) float ¶
-
Return the percentage change of the total PnL for the portfolio.
For multi-currency accounts, specify the currency for the result.
- Parameters :
- Returns :
-
float
- Raises :
-
-
ValueError – If currency is
None
when analyzing multi-currency portfolios. -
ValueError – If currency is not contained in the tracked account balances.
-
ValueError – If unrealized_pnl is not
None
and currency is not equal to the given currency.
-
- get_performance_stats_pnls ( currency : nautilus_trader.model.currency.Currency | None = None , unrealized_pnl : nautilus_trader.model.objects.Money | None = None ) dict [ str , float ] ¶
-
Return the ‘PnL’ (profit and loss) performance statistics, optionally includes the unrealized PnL.
Money objects are converted to floats.
- get_performance_stats_returns ( ) dict [ str , Any ] ¶
-
Return the return performance statistics values.
- Returns :
-
dict[str, Any]
- get_performance_stats_general ( ) dict [ str , Any ] ¶
-
Return the general performance statistics.
- Returns :
-
dict[str, Any]
- get_stats_pnls_formatted ( currency : nautilus_trader.model.currency.Currency | None = None , unrealized_pnl : nautilus_trader.model.objects.Money | None = None ) list [ str ] ¶
-
Return the performance statistics from the last backtest run formatted for printing in the backtest run footer.
- get_stats_returns_formatted ( ) list [ str ] ¶
-
Return the performance statistics for returns from the last backtest run formatted for printing in the backtest run footer.
- Returns :
-
list[str]
- get_stats_general_formatted ( ) list [ str ] ¶
-
Return the performance statistics for returns from the last backtest run formatted for printing in the backtest run footer.
- Returns :
-
list[str]
- class ReportProvider ¶
-
Bases:
object
Provides various portfolio analysis reports.
- static generate_orders_report ( orders : list [ nautilus_trader.model.orders.base.Order ] ) DataFrame ¶
-
Generate an orders report.
- Parameters :
-
orders ( list [ Order ] ) – The orders for the report.
- Returns :
-
pd.DataFrame
- static generate_order_fills_report ( orders : list [ nautilus_trader.model.orders.base.Order ] ) DataFrame ¶
-
Generate an order fills report.
- Parameters :
-
orders ( list [ Order ] ) – The orders for the report.
- Returns :
-
pd.DataFrame
- static generate_positions_report ( positions : list [ nautilus_trader.model.position.Position ] ) DataFrame ¶
-
Generate a positions report.
- Parameters :
-
positions ( list [ Position ] ) – The positions for the report.
- Returns :
-
pd.DataFrame
- static generate_account_report ( account : Account ) DataFrame ¶
-
Generate an account report for the given optional time range.
- Parameters :
-
account ( Account ) – The account for the report.
- Returns :
-
pd.DataFrame
- class PortfolioStatistic ¶
-
Bases:
object
The base class for all portfolio performance statistics.
Notes
The return value should be a JSON serializable primitive.
- classmethod fully_qualified_name ( ) str ¶
-
Return the fully qualified name for the PortfolioStatistic class.
- Returns :
-
str
References
- property name : str ¶
-
Return the name for the statistic.
- Returns :
-
str
- calculate_from_returns ( returns : Series ) Any | None ¶
-
Calculate the statistic value from the given raw returns.
- Parameters :
-
returns ( pd.Series ) – The returns to use for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- calculate_from_realized_pnls ( realized_pnls : Series ) Any | None ¶
-
Calculate the statistic value from the given raw realized PnLs.
- Parameters :
-
realized_pnls ( pd.Series ) – The raw PnLs for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- calculate_from_orders ( orders : list [ nautilus_trader.model.orders.base.Order ] ) Any | None ¶
-
Calculate the statistic value from the given orders.
- Parameters :
-
orders ( list [ Order ] ) – The positions to use for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- calculate_from_positions ( positions : list [ nautilus_trader.model.position.Position ] ) Any | None ¶
-
Calculate the statistic value from the given positions.
- Parameters :
-
positions ( list [ Position ] ) – The positions to use for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- class Expectancy ¶
-
Bases:
PortfolioStatistic
Calculates the expectancy from a realized PnLs series.
- calculate_from_realized_pnls ( realized_pnls : Series ) Optional [ Any ] ¶
-
Calculate the statistic value from the given raw realized PnLs.
- Parameters :
-
realized_pnls ( pd.Series ) – The raw PnLs for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- calculate_from_orders ( orders : list [ nautilus_trader.model.orders.base.Order ] ) Any | None ¶
-
Calculate the statistic value from the given orders.
- Parameters :
-
orders ( list [ Order ] ) – The positions to use for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- calculate_from_positions ( positions : list [ nautilus_trader.model.position.Position ] ) Any | None ¶
-
Calculate the statistic value from the given positions.
- Parameters :
-
positions ( list [ Position ] ) – The positions to use for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- calculate_from_returns ( returns : Series ) Any | None ¶
-
Calculate the statistic value from the given raw returns.
- Parameters :
-
returns ( pd.Series ) – The returns to use for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- classmethod fully_qualified_name ( ) str ¶
-
Return the fully qualified name for the PortfolioStatistic class.
- Returns :
-
str
References
- property name : str ¶
-
Return the name for the statistic.
- Returns :
-
str
- class LongRatio ( precision : int = 2 ) ¶
-
Bases:
PortfolioStatistic
Calculates the ratio of long (to short) positions.
- Parameters :
-
precision ( int , default 2 ) – The decimal precision for the output.
- calculate_from_positions ( positions : list [ nautilus_trader.model.position.Position ] ) Optional [ Any ] ¶
-
Calculate the statistic value from the given positions.
- Parameters :
-
positions ( list [ Position ] ) – The positions to use for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- calculate_from_orders ( orders : list [ nautilus_trader.model.orders.base.Order ] ) Any | None ¶
-
Calculate the statistic value from the given orders.
- Parameters :
-
orders ( list [ Order ] ) – The positions to use for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- calculate_from_realized_pnls ( realized_pnls : Series ) Any | None ¶
-
Calculate the statistic value from the given raw realized PnLs.
- Parameters :
-
realized_pnls ( pd.Series ) – The raw PnLs for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- calculate_from_returns ( returns : Series ) Any | None ¶
-
Calculate the statistic value from the given raw returns.
- Parameters :
-
returns ( pd.Series ) – The returns to use for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- classmethod fully_qualified_name ( ) str ¶
-
Return the fully qualified name for the PortfolioStatistic class.
- Returns :
-
str
References
- property name : str ¶
-
Return the name for the statistic.
- Returns :
-
str
- class AvgLoser ¶
-
Bases:
PortfolioStatistic
Calculates the average loser from a series of PnLs.
- calculate_from_realized_pnls ( realized_pnls : Series ) Optional [ Any ] ¶
-
Calculate the statistic value from the given raw realized PnLs.
- Parameters :
-
realized_pnls ( pd.Series ) – The raw PnLs for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- calculate_from_orders ( orders : list [ nautilus_trader.model.orders.base.Order ] ) Any | None ¶
-
Calculate the statistic value from the given orders.
- Parameters :
-
orders ( list [ Order ] ) – The positions to use for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- calculate_from_positions ( positions : list [ nautilus_trader.model.position.Position ] ) Any | None ¶
-
Calculate the statistic value from the given positions.
- Parameters :
-
positions ( list [ Position ] ) – The positions to use for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- calculate_from_returns ( returns : Series ) Any | None ¶
-
Calculate the statistic value from the given raw returns.
- Parameters :
-
returns ( pd.Series ) – The returns to use for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- classmethod fully_qualified_name ( ) str ¶
-
Return the fully qualified name for the PortfolioStatistic class.
- Returns :
-
str
References
- property name : str ¶
-
Return the name for the statistic.
- Returns :
-
str
- class MaxLoser ¶
-
Bases:
PortfolioStatistic
Calculates the maximum loser from a series of PnLs.
- calculate_from_realized_pnls ( realized_pnls : Series ) Optional [ Any ] ¶
-
Calculate the statistic value from the given raw realized PnLs.
- Parameters :
-
realized_pnls ( pd.Series ) – The raw PnLs for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- calculate_from_orders ( orders : list [ nautilus_trader.model.orders.base.Order ] ) Any | None ¶
-
Calculate the statistic value from the given orders.
- Parameters :
-
orders ( list [ Order ] ) – The positions to use for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- calculate_from_positions ( positions : list [ nautilus_trader.model.position.Position ] ) Any | None ¶
-
Calculate the statistic value from the given positions.
- Parameters :
-
positions ( list [ Position ] ) – The positions to use for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- calculate_from_returns ( returns : Series ) Any | None ¶
-
Calculate the statistic value from the given raw returns.
- Parameters :
-
returns ( pd.Series ) – The returns to use for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- classmethod fully_qualified_name ( ) str ¶
-
Return the fully qualified name for the PortfolioStatistic class.
- Returns :
-
str
References
- property name : str ¶
-
Return the name for the statistic.
- Returns :
-
str
- class MinLoser ¶
-
Bases:
PortfolioStatistic
Calculates the minimum loser from a series of PnLs.
- calculate_from_realized_pnls ( realized_pnls : Series ) Optional [ Any ] ¶
-
Calculate the statistic value from the given raw realized PnLs.
- Parameters :
-
realized_pnls ( pd.Series ) – The raw PnLs for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- calculate_from_orders ( orders : list [ nautilus_trader.model.orders.base.Order ] ) Any | None ¶
-
Calculate the statistic value from the given orders.
- Parameters :
-
orders ( list [ Order ] ) – The positions to use for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- calculate_from_positions ( positions : list [ nautilus_trader.model.position.Position ] ) Any | None ¶
-
Calculate the statistic value from the given positions.
- Parameters :
-
positions ( list [ Position ] ) – The positions to use for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- calculate_from_returns ( returns : Series ) Any | None ¶
-
Calculate the statistic value from the given raw returns.
- Parameters :
-
returns ( pd.Series ) – The returns to use for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- classmethod fully_qualified_name ( ) str ¶
-
Return the fully qualified name for the PortfolioStatistic class.
- Returns :
-
str
References
- property name : str ¶
-
Return the name for the statistic.
- Returns :
-
str
- class ProfitFactor ¶
-
Bases:
PortfolioStatistic
Calculates the annualized profit factor or ratio (wins/loss).
- calculate_from_returns ( returns : Series ) Optional [ Any ] ¶
-
Calculate the statistic value from the given raw returns.
- Parameters :
-
returns ( pd.Series ) – The returns to use for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- calculate_from_orders ( orders : list [ nautilus_trader.model.orders.base.Order ] ) Any | None ¶
-
Calculate the statistic value from the given orders.
- Parameters :
-
orders ( list [ Order ] ) – The positions to use for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- calculate_from_positions ( positions : list [ nautilus_trader.model.position.Position ] ) Any | None ¶
-
Calculate the statistic value from the given positions.
- Parameters :
-
positions ( list [ Position ] ) – The positions to use for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- calculate_from_realized_pnls ( realized_pnls : Series ) Any | None ¶
-
Calculate the statistic value from the given raw realized PnLs.
- Parameters :
-
realized_pnls ( pd.Series ) – The raw PnLs for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- classmethod fully_qualified_name ( ) str ¶
-
Return the fully qualified name for the PortfolioStatistic class.
- Returns :
-
str
References
- property name : str ¶
-
Return the name for the statistic.
- Returns :
-
str
- class ReturnsAverage ¶
-
Bases:
PortfolioStatistic
Calculates the average return.
- property name : str ¶
-
Return the name for the statistic.
- Returns :
-
str
- calculate_from_returns ( returns : Series ) Optional [ Any ] ¶
-
Calculate the statistic value from the given raw returns.
- Parameters :
-
returns ( pd.Series ) – The returns to use for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- calculate_from_orders ( orders : list [ nautilus_trader.model.orders.base.Order ] ) Any | None ¶
-
Calculate the statistic value from the given orders.
- Parameters :
-
orders ( list [ Order ] ) – The positions to use for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- calculate_from_positions ( positions : list [ nautilus_trader.model.position.Position ] ) Any | None ¶
-
Calculate the statistic value from the given positions.
- Parameters :
-
positions ( list [ Position ] ) – The positions to use for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- calculate_from_realized_pnls ( realized_pnls : Series ) Any | None ¶
-
Calculate the statistic value from the given raw realized PnLs.
- Parameters :
-
realized_pnls ( pd.Series ) – The raw PnLs for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- classmethod fully_qualified_name ( ) str ¶
-
Return the fully qualified name for the PortfolioStatistic class.
- Returns :
-
str
References
- class ReturnsAverageLoss ¶
-
Bases:
PortfolioStatistic
Calculates the average losing return.
- property name : str ¶
-
Return the name for the statistic.
- Returns :
-
str
- calculate_from_returns ( returns : Series ) Optional [ Any ] ¶
-
Calculate the statistic value from the given raw returns.
- Parameters :
-
returns ( pd.Series ) – The returns to use for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- calculate_from_orders ( orders : list [ nautilus_trader.model.orders.base.Order ] ) Any | None ¶
-
Calculate the statistic value from the given orders.
- Parameters :
-
orders ( list [ Order ] ) – The positions to use for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- calculate_from_positions ( positions : list [ nautilus_trader.model.position.Position ] ) Any | None ¶
-
Calculate the statistic value from the given positions.
- Parameters :
-
positions ( list [ Position ] ) – The positions to use for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- calculate_from_realized_pnls ( realized_pnls : Series ) Any | None ¶
-
Calculate the statistic value from the given raw realized PnLs.
- Parameters :
-
realized_pnls ( pd.Series ) – The raw PnLs for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- classmethod fully_qualified_name ( ) str ¶
-
Return the fully qualified name for the PortfolioStatistic class.
- Returns :
-
str
References
- class ReturnsAverageWin ¶
-
Bases:
PortfolioStatistic
Calculates the average winning return.
- property name : str ¶
-
Return the name for the statistic.
- Returns :
-
str
- calculate_from_returns ( returns : Series ) Optional [ Any ] ¶
-
Calculate the statistic value from the given raw returns.
- Parameters :
-
returns ( pd.Series ) – The returns to use for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- calculate_from_orders ( orders : list [ nautilus_trader.model.orders.base.Order ] ) Any | None ¶
-
Calculate the statistic value from the given orders.
- Parameters :
-
orders ( list [ Order ] ) – The positions to use for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- calculate_from_positions ( positions : list [ nautilus_trader.model.position.Position ] ) Any | None ¶
-
Calculate the statistic value from the given positions.
- Parameters :
-
positions ( list [ Position ] ) – The positions to use for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- calculate_from_realized_pnls ( realized_pnls : Series ) Any | None ¶
-
Calculate the statistic value from the given raw realized PnLs.
- Parameters :
-
realized_pnls ( pd.Series ) – The raw PnLs for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- classmethod fully_qualified_name ( ) str ¶
-
Return the fully qualified name for the PortfolioStatistic class.
- Returns :
-
str
References
- class ReturnsVolatility ( period : int = 252 ) ¶
-
Bases:
PortfolioStatistic
Calculates the volatility of returns.
The returns will be downsampled into daily bins.
- Parameters :
-
period ( int , default 252 ) – The trading period in days.
- property name : str ¶
-
Return the name for the statistic.
- Returns :
-
str
- calculate_from_returns ( returns : Series ) Optional [ Any ] ¶
-
Calculate the statistic value from the given raw returns.
- Parameters :
-
returns ( pd.Series ) – The returns to use for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- calculate_from_orders ( orders : list [ nautilus_trader.model.orders.base.Order ] ) Any | None ¶
-
Calculate the statistic value from the given orders.
- Parameters :
-
orders ( list [ Order ] ) – The positions to use for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- calculate_from_positions ( positions : list [ nautilus_trader.model.position.Position ] ) Any | None ¶
-
Calculate the statistic value from the given positions.
- Parameters :
-
positions ( list [ Position ] ) – The positions to use for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- calculate_from_realized_pnls ( realized_pnls : Series ) Any | None ¶
-
Calculate the statistic value from the given raw realized PnLs.
- Parameters :
-
realized_pnls ( pd.Series ) – The raw PnLs for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- classmethod fully_qualified_name ( ) str ¶
-
Return the fully qualified name for the PortfolioStatistic class.
- Returns :
-
str
References
- class RiskReturnRatio ¶
-
Bases:
PortfolioStatistic
Calculates the return on risk ratio.
- calculate_from_returns ( returns : Series ) Optional [ Any ] ¶
-
Calculate the statistic value from the given raw returns.
- Parameters :
-
returns ( pd.Series ) – The returns to use for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- calculate_from_orders ( orders : list [ nautilus_trader.model.orders.base.Order ] ) Any | None ¶
-
Calculate the statistic value from the given orders.
- Parameters :
-
orders ( list [ Order ] ) – The positions to use for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- calculate_from_positions ( positions : list [ nautilus_trader.model.position.Position ] ) Any | None ¶
-
Calculate the statistic value from the given positions.
- Parameters :
-
positions ( list [ Position ] ) – The positions to use for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- calculate_from_realized_pnls ( realized_pnls : Series ) Any | None ¶
-
Calculate the statistic value from the given raw realized PnLs.
- Parameters :
-
realized_pnls ( pd.Series ) – The raw PnLs for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- classmethod fully_qualified_name ( ) str ¶
-
Return the fully qualified name for the PortfolioStatistic class.
- Returns :
-
str
References
- property name : str ¶
-
Return the name for the statistic.
- Returns :
-
str
- class SharpeRatio ( period : int = 252 ) ¶
-
Bases:
PortfolioStatistic
Calculates the Sharpe Ratio from returns.
The returns will be downsampled into daily bins.
- Parameters :
-
period ( int , default 252 ) – The trading period in days.
- property name : str ¶
-
Return the name for the statistic.
- Returns :
-
str
- calculate_from_returns ( returns : Series ) Optional [ Any ] ¶
-
Calculate the statistic value from the given raw returns.
- Parameters :
-
returns ( pd.Series ) – The returns to use for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- calculate_from_orders ( orders : list [ nautilus_trader.model.orders.base.Order ] ) Any | None ¶
-
Calculate the statistic value from the given orders.
- Parameters :
-
orders ( list [ Order ] ) – The positions to use for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- calculate_from_positions ( positions : list [ nautilus_trader.model.position.Position ] ) Any | None ¶
-
Calculate the statistic value from the given positions.
- Parameters :
-
positions ( list [ Position ] ) – The positions to use for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- calculate_from_realized_pnls ( realized_pnls : Series ) Any | None ¶
-
Calculate the statistic value from the given raw realized PnLs.
- Parameters :
-
realized_pnls ( pd.Series ) – The raw PnLs for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- classmethod fully_qualified_name ( ) str ¶
-
Return the fully qualified name for the PortfolioStatistic class.
- Returns :
-
str
References
- class SortinoRatio ( period : int = 252 ) ¶
-
Bases:
PortfolioStatistic
Calculates the annualized Sortino Ratio from returns.
The returns will be downsampled into daily bins.
- Parameters :
-
period ( int , default 252 ) – The trading period in days.
- property name : str ¶
-
Return the name for the statistic.
- Returns :
-
str
- calculate_from_returns ( returns : Series ) Optional [ Any ] ¶
-
Calculate the statistic value from the given raw returns.
- Parameters :
-
returns ( pd.Series ) – The returns to use for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- calculate_from_orders ( orders : list [ nautilus_trader.model.orders.base.Order ] ) Any | None ¶
-
Calculate the statistic value from the given orders.
- Parameters :
-
orders ( list [ Order ] ) – The positions to use for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- calculate_from_positions ( positions : list [ nautilus_trader.model.position.Position ] ) Any | None ¶
-
Calculate the statistic value from the given positions.
- Parameters :
-
positions ( list [ Position ] ) – The positions to use for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- calculate_from_realized_pnls ( realized_pnls : Series ) Any | None ¶
-
Calculate the statistic value from the given raw realized PnLs.
- Parameters :
-
realized_pnls ( pd.Series ) – The raw PnLs for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- classmethod fully_qualified_name ( ) str ¶
-
Return the fully qualified name for the PortfolioStatistic class.
- Returns :
-
str
References
- class WinRate ¶
-
Bases:
PortfolioStatistic
Calculates the win rate from a realized PnLs series.
- calculate_from_realized_pnls ( realized_pnls : Series ) Optional [ Any ] ¶
-
Calculate the statistic value from the given raw realized PnLs.
- Parameters :
-
realized_pnls ( pd.Series ) – The raw PnLs for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- calculate_from_orders ( orders : list [ nautilus_trader.model.orders.base.Order ] ) Any | None ¶
-
Calculate the statistic value from the given orders.
- Parameters :
-
orders ( list [ Order ] ) – The positions to use for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- calculate_from_positions ( positions : list [ nautilus_trader.model.position.Position ] ) Any | None ¶
-
Calculate the statistic value from the given positions.
- Parameters :
-
positions ( list [ Position ] ) – The positions to use for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- calculate_from_returns ( returns : Series ) Any | None ¶
-
Calculate the statistic value from the given raw returns.
- Parameters :
-
returns ( pd.Series ) – The returns to use for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- classmethod fully_qualified_name ( ) str ¶
-
Return the fully qualified name for the PortfolioStatistic class.
- Returns :
-
str
References
- property name : str ¶
-
Return the name for the statistic.
- Returns :
-
str
- class AvgWinner ¶
-
Bases:
PortfolioStatistic
Calculates the average winner from a series of PnLs.
- calculate_from_realized_pnls ( realized_pnls : Series ) Optional [ Any ] ¶
-
Calculate the statistic value from the given raw realized PnLs.
- Parameters :
-
realized_pnls ( pd.Series ) – The raw PnLs for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- calculate_from_orders ( orders : list [ nautilus_trader.model.orders.base.Order ] ) Any | None ¶
-
Calculate the statistic value from the given orders.
- Parameters :
-
orders ( list [ Order ] ) – The positions to use for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- calculate_from_positions ( positions : list [ nautilus_trader.model.position.Position ] ) Any | None ¶
-
Calculate the statistic value from the given positions.
- Parameters :
-
positions ( list [ Position ] ) – The positions to use for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- calculate_from_returns ( returns : Series ) Any | None ¶
-
Calculate the statistic value from the given raw returns.
- Parameters :
-
returns ( pd.Series ) – The returns to use for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- classmethod fully_qualified_name ( ) str ¶
-
Return the fully qualified name for the PortfolioStatistic class.
- Returns :
-
str
References
- property name : str ¶
-
Return the name for the statistic.
- Returns :
-
str
- class MaxWinner ¶
-
Bases:
PortfolioStatistic
Calculates the maximum winner from a series of PnLs.
- calculate_from_realized_pnls ( realized_pnls : Series ) Optional [ Any ] ¶
-
Calculate the statistic value from the given raw realized PnLs.
- Parameters :
-
realized_pnls ( pd.Series ) – The raw PnLs for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- calculate_from_orders ( orders : list [ nautilus_trader.model.orders.base.Order ] ) Any | None ¶
-
Calculate the statistic value from the given orders.
- Parameters :
-
orders ( list [ Order ] ) – The positions to use for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- calculate_from_positions ( positions : list [ nautilus_trader.model.position.Position ] ) Any | None ¶
-
Calculate the statistic value from the given positions.
- Parameters :
-
positions ( list [ Position ] ) – The positions to use for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- calculate_from_returns ( returns : Series ) Any | None ¶
-
Calculate the statistic value from the given raw returns.
- Parameters :
-
returns ( pd.Series ) – The returns to use for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- classmethod fully_qualified_name ( ) str ¶
-
Return the fully qualified name for the PortfolioStatistic class.
- Returns :
-
str
References
- property name : str ¶
-
Return the name for the statistic.
- Returns :
-
str
- class MinWinner ¶
-
Bases:
PortfolioStatistic
Calculates the minimum winner from a series of PnLs.
- calculate_from_realized_pnls ( realized_pnls : Series ) Optional [ Any ] ¶
-
Calculate the statistic value from the given raw realized PnLs.
- Parameters :
-
realized_pnls ( pd.Series ) – The raw PnLs for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- calculate_from_orders ( orders : list [ nautilus_trader.model.orders.base.Order ] ) Any | None ¶
-
Calculate the statistic value from the given orders.
- Parameters :
-
orders ( list [ Order ] ) – The positions to use for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- calculate_from_positions ( positions : list [ nautilus_trader.model.position.Position ] ) Any | None ¶
-
Calculate the statistic value from the given positions.
- Parameters :
-
positions ( list [ Position ] ) – The positions to use for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- calculate_from_returns ( returns : Series ) Any | None ¶
-
Calculate the statistic value from the given raw returns.
- Parameters :
-
returns ( pd.Series ) – The returns to use for the calculation.
- Returns :
-
Any or
None
– A JSON serializable primitive.
- classmethod fully_qualified_name ( ) str ¶
-
Return the fully qualified name for the PortfolioStatistic class.
- Returns :
-
str
References
- property name : str ¶
-
Return the name for the statistic.
- Returns :
-
str