Martingale42/nautilus-dev / skills/nt-signals
nt-signals
UnverifiedUse when working with indicators, signal generation, bar aggregation, custom data types, analysis statistics, or tearsheets in NautilusTrader.
templates/portfolio_statistic.py
View on GitHub# -------------------------------------------------------------------------------------------------
# NautilusTrader PortfolioStatistic Template
#
# Subclass PortfolioStatistic to define custom analysis metrics.
# Statistics are automatically computed by PortfolioAnalyzer after backtests/live runs.
#
# Return values MUST be JSON-serializable (float, int, str, bool, None).
# -------------------------------------------------------------------------------------------------
from typing import Any
import pandas as pd
from nautilus_trader.analysis.statistic import PortfolioStatistic
class MyPortfolioStatistic(PortfolioStatistic):
"""
TODO: Describe what this statistic calculates.
Returns
-------
float or None
TODO: Describe the return value.
"""
def calculate_from_returns(self, returns: pd.Series) -> Any | None:
"""
Calculate statistic from a time series of returns.
Parameters
----------
returns : pd.Series
Time series of returns.
Returns
-------
Any or None
The calculated statistic value, or None if insufficient data.
"""
if not self._check_valid_returns(returns):
return None
# TODO: Implement calculation
# Use self._downsample_to_daily_bins(returns) for annualized metrics
result = returns.mean()
return float(result)
def calculate_from_realized_pnls(self, realized_pnls: pd.Series) -> Any | None:
"""
Calculate statistic from realized P&L values.
Parameters
----------
realized_pnls : pd.Series
Time series of realized P&L values.
Returns
-------
Any or None
The calculated statistic value, or None if insufficient data.
"""
if realized_pnls is None or realized_pnls.empty:
return None
# TODO: Implement calculation
result = realized_pnls.sum()
return float(result)
# Registration:
#
# Add to BacktestEngine or PortfolioAnalyzer:
# engine.add_statistic(MyPortfolioStatistic())
#
# Or via config:
# from nautilus_trader.config import BacktestRunConfig
# config = BacktestRunConfig(
# ...
# statistics=[MyPortfolioStatistic()],
# )
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack." | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |