Analysis

The analysis subpackage groups components relating to trading performance statistics and analysis.

Portfolio Analyzer

class PortfolioAnalyzer

Bases: object

Provides a portfolio performance analyzer for tracking and generating performance metrics and statistics.

register_statistic ( statistic : nautilus_trader.analysis.statistic.PortfolioStatistic ) None

Register the given statistic with the analyzer.

Parameters

statistic ( PortfolioStatistic ) – The statistic to register.

deregister_statistic ( statistic : nautilus_trader.analysis.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

Return the analyzed currencies.

Returns

list[Currency]

statistic ( name : str ) Optional [ nautilus_trader.analysis.statistic.PortfolioStatistic ]

Return the statistic with the given name (if found).

Returns

PortfolioStatistic or None

returns ( ) pandas.core.series.Series

Return raw the returns data.

Returns

pd.Series

calculate_statistics ( account : nautilus_trader.accounting.accounts.base.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 ( dict [ PositionId , 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 : nautilus_trader.model.identifiers.PositionId , realized_pnl : nautilus_trader.model.objects.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.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 : Optional [ nautilus_trader.model.currency.Currency ] = None ) Optional [ pandas.core.series.Series ]

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 : Optional [ nautilus_trader.model.currency.Currency ] = None ) float

Return the total PnL for the portfolio.

For multi-currency portfolios, specify the currency for the result.

Parameters

currency ( Currency , optional ) – The currency for the result.

Returns

float

Raises
  • ValueError – If currency is None when analyzing multi-currency portfolios.

  • ValueError – If currency is not contained in the tracked account balances.

total_pnl_percentage ( currency : Optional [ nautilus_trader.model.currency.Currency ] = None ) float

Return the percentage change of the total PnL for the portfolio.

For multi-currency accounts, specify the currency for the result.

Parameters

currency ( Currency , optional ) – The currency for the result.

Returns

float

Raises
  • ValueError – If currency is None when analyzing multi-currency portfolios.

  • ValueError – If currency is not contained in the tracked account balances.

get_performance_stats_pnls ( currency : Optional [ nautilus_trader.model.currency.Currency ] = None ) Dict [ str , float ]

Return the PnL performance statistics.

Money objects are converted to floats.

Parameters

currency ( Currency ) – The currency for the performance.

Returns

dict[str, Any]

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 : Optional [ nautilus_trader.model.currency.Currency ] = None ) List [ str ]

Return the performance statistics from the last backtest run formatted for printing in the backtest run footer.

Parameters

currency ( Currency ) – The currency for the performance.

Returns

list[str]

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]

Report Provider

class ReportProvider

Bases: object

Provides various portfolio analysis reports.

static generate_orders_report ( orders : List [ nautilus_trader.model.orders.base.Order ] ) pandas.core.frame.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 ] ) pandas.core.frame.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 ] ) pandas.core.frame.DataFrame

Generate a positions report.

Parameters

positions ( list [ Position ] ) – The positions for the report.

Returns

pd.DataFrame

static generate_account_report ( account : nautilus_trader.accounting.accounts.base.Account ) pandas.core.frame.DataFrame

Generate an account report for the given optional time range.

Parameters

account ( Account ) – The account for the report.

Returns

pd.DataFrame

Portfolio Statistic

class PortfolioStatistic

Bases: object

The abstract 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

https://www.python.org/dev/peps/pep-3155/

property name : str

Return the name for the statistic.

Returns

str

calculate_from_returns ( returns : pandas.core.series.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_realized_pnls ( realized_pnls : pandas.core.series.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 ] ) Optional [ Any ]

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 ] ) 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.

Expectancy

class Expectancy

Bases: nautilus_trader.analysis.statistic.PortfolioStatistic

Calculates the expectancy from a realized PnLs series.

calculate_from_realized_pnls ( realized_pnls : pandas.core.series.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 ] ) Optional [ Any ]

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 ] ) 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_returns ( returns : pandas.core.series.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.

classmethod fully_qualified_name ( ) str

Return the fully qualified name for the PortfolioStatistic class.

Returns

str

References

https://www.python.org/dev/peps/pep-3155/

property name : str

Return the name for the statistic.

Returns

str

Long Ratio

class LongRatio ( precision : int = 2 )

Bases: nautilus_trader.analysis.statistic.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 ] ) Optional [ Any ]

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 : pandas.core.series.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_returns ( returns : pandas.core.series.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.

classmethod fully_qualified_name ( ) str

Return the fully qualified name for the PortfolioStatistic class.

Returns

str

References

https://www.python.org/dev/peps/pep-3155/

property name : str

Return the name for the statistic.

Returns

str

Average Loser

class AvgLoser

Bases: nautilus_trader.analysis.statistic.PortfolioStatistic

Calculates the average loser from a series of PnLs.

calculate_from_realized_pnls ( realized_pnls : pandas.core.series.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 ] ) Optional [ Any ]

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 ] ) 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_returns ( returns : pandas.core.series.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.

classmethod fully_qualified_name ( ) str

Return the fully qualified name for the PortfolioStatistic class.

Returns

str

References

https://www.python.org/dev/peps/pep-3155/

property name : str

Return the name for the statistic.

Returns

str

Max Loser

class MaxLoser

Bases: nautilus_trader.analysis.statistic.PortfolioStatistic

Calculates the maximum loser from a series of PnLs.

calculate_from_realized_pnls ( realized_pnls : pandas.core.series.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 ] ) Optional [ Any ]

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 ] ) 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_returns ( returns : pandas.core.series.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.

classmethod fully_qualified_name ( ) str

Return the fully qualified name for the PortfolioStatistic class.

Returns

str

References

https://www.python.org/dev/peps/pep-3155/

property name : str

Return the name for the statistic.

Returns

str

Min Loser

class MinLoser

Bases: nautilus_trader.analysis.statistic.PortfolioStatistic

Calculates the minimum loser from a series of PnLs.

calculate_from_realized_pnls ( realized_pnls : pandas.core.series.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 ] ) Optional [ Any ]

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 ] ) 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_returns ( returns : pandas.core.series.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.

classmethod fully_qualified_name ( ) str

Return the fully qualified name for the PortfolioStatistic class.

Returns

str

References

https://www.python.org/dev/peps/pep-3155/

property name : str

Return the name for the statistic.

Returns

str

Profit Factor

class ProfitFactor

Bases: nautilus_trader.analysis.statistic.PortfolioStatistic

Calculates the annualized profit factor or ratio (wins/loss).

calculate_from_returns ( returns : pandas.core.series.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 ] ) Optional [ Any ]

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 ] ) 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_realized_pnls ( realized_pnls : pandas.core.series.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.

classmethod fully_qualified_name ( ) str

Return the fully qualified name for the PortfolioStatistic class.

Returns

str

References

https://www.python.org/dev/peps/pep-3155/

property name : str

Return the name for the statistic.

Returns

str

Average (Returns)

class ReturnsAverage

Bases: nautilus_trader.analysis.statistic.PortfolioStatistic

Calculates the average return.

property name : str

Return the name for the statistic.

Returns

str

calculate_from_returns ( returns : pandas.core.series.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 ] ) Optional [ Any ]

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 ] ) 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_realized_pnls ( realized_pnls : pandas.core.series.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.

classmethod fully_qualified_name ( ) str

Return the fully qualified name for the PortfolioStatistic class.

Returns

str

References

https://www.python.org/dev/peps/pep-3155/

Average Loss (Returns)

class ReturnsAverageLoss

Bases: nautilus_trader.analysis.statistic.PortfolioStatistic

Calculates the average losing return.

property name : str

Return the name for the statistic.

Returns

str

calculate_from_returns ( returns : pandas.core.series.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 ] ) Optional [ Any ]

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 ] ) 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_realized_pnls ( realized_pnls : pandas.core.series.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.

classmethod fully_qualified_name ( ) str

Return the fully qualified name for the PortfolioStatistic class.

Returns

str

References

https://www.python.org/dev/peps/pep-3155/

Average Win (Returns)

class ReturnsAverageWin

Bases: nautilus_trader.analysis.statistic.PortfolioStatistic

Calculates the average winning return.

property name : str

Return the name for the statistic.

Returns

str

calculate_from_returns ( returns : pandas.core.series.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 ] ) Optional [ Any ]

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 ] ) 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_realized_pnls ( realized_pnls : pandas.core.series.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.

classmethod fully_qualified_name ( ) str

Return the fully qualified name for the PortfolioStatistic class.

Returns

str

References

https://www.python.org/dev/peps/pep-3155/

Returns Volatility

class ReturnsVolatility ( period : int = 252 )

Bases: nautilus_trader.analysis.statistic.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 : pandas.core.series.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 ] ) Optional [ Any ]

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 ] ) 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_realized_pnls ( realized_pnls : pandas.core.series.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.

classmethod fully_qualified_name ( ) str

Return the fully qualified name for the PortfolioStatistic class.

Returns

str

References

https://www.python.org/dev/peps/pep-3155/

Risk Return Ratio

class RiskReturnRatio

Bases: nautilus_trader.analysis.statistic.PortfolioStatistic

Calculates the return on risk ratio.

calculate_from_returns ( returns : pandas.core.series.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 ] ) Optional [ Any ]

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 ] ) 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_realized_pnls ( realized_pnls : pandas.core.series.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.

classmethod fully_qualified_name ( ) str

Return the fully qualified name for the PortfolioStatistic class.

Returns

str

References

https://www.python.org/dev/peps/pep-3155/

property name : str

Return the name for the statistic.

Returns

str

Sharpe Ratio

class SharpeRatio ( period : int = 252 )

Bases: nautilus_trader.analysis.statistic.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 : pandas.core.series.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 ] ) Optional [ Any ]

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 ] ) 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_realized_pnls ( realized_pnls : pandas.core.series.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.

classmethod fully_qualified_name ( ) str

Return the fully qualified name for the PortfolioStatistic class.

Returns

str

References

https://www.python.org/dev/peps/pep-3155/

Sortino Ratio

class SortinoRatio ( period : int = 252 )

Bases: nautilus_trader.analysis.statistic.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 : pandas.core.series.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 ] ) Optional [ Any ]

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 ] ) 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_realized_pnls ( realized_pnls : pandas.core.series.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.

classmethod fully_qualified_name ( ) str

Return the fully qualified name for the PortfolioStatistic class.

Returns

str

References

https://www.python.org/dev/peps/pep-3155/

Win Rate

class WinRate

Bases: nautilus_trader.analysis.statistic.PortfolioStatistic

Calculates the win rate from a realized PnLs series.

calculate_from_realized_pnls ( realized_pnls : pandas.core.series.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 ] ) Optional [ Any ]

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 ] ) 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_returns ( returns : pandas.core.series.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.

classmethod fully_qualified_name ( ) str

Return the fully qualified name for the PortfolioStatistic class.

Returns

str

References

https://www.python.org/dev/peps/pep-3155/

property name : str

Return the name for the statistic.

Returns

str

Average Winner

class AvgWinner

Bases: nautilus_trader.analysis.statistic.PortfolioStatistic

Calculates the average winner from a series of PnLs.

calculate_from_realized_pnls ( realized_pnls : pandas.core.series.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 ] ) Optional [ Any ]

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 ] ) 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_returns ( returns : pandas.core.series.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.

classmethod fully_qualified_name ( ) str

Return the fully qualified name for the PortfolioStatistic class.

Returns

str

References

https://www.python.org/dev/peps/pep-3155/

property name : str

Return the name for the statistic.

Returns

str

Average Max

class MaxWinner

Bases: nautilus_trader.analysis.statistic.PortfolioStatistic

Calculates the maximum winner from a series of PnLs.

calculate_from_realized_pnls ( realized_pnls : pandas.core.series.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 ] ) Optional [ Any ]

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 ] ) 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_returns ( returns : pandas.core.series.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.

classmethod fully_qualified_name ( ) str

Return the fully qualified name for the PortfolioStatistic class.

Returns

str

References

https://www.python.org/dev/peps/pep-3155/

property name : str

Return the name for the statistic.

Returns

str

Average Min

class MinWinner

Bases: nautilus_trader.analysis.statistic.PortfolioStatistic

Calculates the minimum winner from a series of PnLs.

calculate_from_realized_pnls ( realized_pnls : pandas.core.series.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 ] ) Optional [ Any ]

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 ] ) 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_returns ( returns : pandas.core.series.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.

classmethod fully_qualified_name ( ) str

Return the fully qualified name for the PortfolioStatistic class.

Returns

str

References

https://www.python.org/dev/peps/pep-3155/

property name : str

Return the name for the statistic.

Returns

str