---
title: "Runtime Statistics"
description: "Runtime statistics show the performace of your algorithm at a single moment in time."
canonical: https://www.quantconnect.com/docs/v2/writing-algorithms/statistics/runtime-statistics
markdown: https://www.quantconnect.com/docs/v2/writing-algorithms/statistics/runtime-statistics.md
language: python
source: https://github.com/QuantConnect/Documentation/tree/master/03%20Writing%20Algorithms/39%20Statistics/02%20Runtime%20Statistics
modified: 2026-10-28
index: https://www.quantconnect.com/llms.txt
---

# Runtime Statistics

[Documentation](https://www.quantconnect.com/docs/v2.md) > [Writing Algorithms](https://www.quantconnect.com/docs/v2/writing-algorithms.md) > [Statistics](https://www.quantconnect.com/docs/v2/writing-algorithms/statistics.md) > Runtime Statistics

> Code examples are shown in Python. Append `?lang=csharp` to this URL for the C# version of this page.

## Introduction

Runtime statistics show the performace of your algorithm at a single moment in time. Some of these statistics are a function of the [risk free interest rate](https://www.quantconnect.com/docs/v2/writing-algorithms/reality-modeling/risk-free-interest-rate/key-concepts.md) and the [number of trading days per year](https://www.quantconnect.com/docs/v2/writing-algorithms/initialization.md#10-Set-Algorithm-Settings).

## Default Statistics

The following table describes the default runtime statistics:

| Statistic | Description |
| --- | --- |
| Equity | The total portfolio value if all of the holdings were sold at current market rates. Equity equals the sum of cash and the market value of all open positions. |
| Fees | The total quantity of fees paid for all the transactions during the algorithm's trading period. Total fees include brokerage commissions, exchange fees, and other transaction costs. |
| Holdings | The absolute sum of the items in the portfolio. Holdings represent the total market value of all positions, regardless of whether they are long or short. |
| Net Profit | The dollar-value return across the entire trading period. |
| PSR | The probability that the estimated Sharpe ratio of an algorithm is greater than a benchmark. |
| Return | The rate of return across the entire trading period. |
| Unrealized | The amount of profit a portfolio would capture if it liquidated all open positions and paid the fees for transacting and crossing the spread. Unrealized profit becomes realized profit when the positions are closed. |
| Volume | The total value of assets traded for all of an algorithm's transactions during the trading period. |

To see the resources of the node that runs the algorithm, see [Server Statistics](https://www.quantconnect.com/docs/v2/writing-algorithms/statistics/server-statistics.md).

## Add Statistics

To add a custom runtime statistic, call the `set_runtime_statistic` method with a `name` and `value`. The `value` argument can be a `string` or a number.

```python
self.set_runtime_statistic(name, value)
```

Don't try to set a value for any of the preceding default runtime statistics. LEAN overwrites the value that you try to set.

## Get Values

To get the value of a runtime statistic in an algorithm, index the `runtime_statistics` member of the algorithm class with the statistic name. The values of the `runtime_statistics` dictionary are strings, so you may need to cast the result to a different data type.

```python
value = self.runtime_statistics[name]
```

The following table describe other ways to get the runtime statistics of your backtests and live algorithms:

| Deployment Target | Execution Mode | Access Tools |
| --- | --- | --- |
| QuantConnect Cloud | Backtest | [Backtest results page](https://www.quantconnect.com/docs/v2/cloud-platform/backtesting/results.md#03-Runtime-Statistics) in the Algorithm Lab [Backtest results page](https://www.quantconnect.com/docs/v2/local-platform/backtesting/results.md#03-Runtime-Statistics) on Local Platform [ReadBacktest](https://www.quantconnect.com/docs/v2/research-environment/meta-analysis/backtest-analysis.md) API method [/backtests/read](https://www.quantconnect.com/docs/v2/cloud-platform/api-reference/backtest-management/read-backtest/backtest-statistics.md) endpoint |
| QuantConnect Cloud | Live Trading | [Live results page](https://www.quantconnect.com/docs/v2/cloud-platform/live-trading/results.md#03-Runtime-Statistics) in the Algorithm Lab Live results page on Local Platform [ReadLiveAlgorithm](https://www.quantconnect.com/docs/v2/research-environment/meta-analysis/live-analysis.md) API method [/live/read](https://www.quantconnect.com/docs/v2/cloud-platform/api-reference/live-management/read-live-algorithm/live-algorithm-statistics.md) endpoint |
| Local | Backtest | [Backtest results page](https://www.quantconnect.com/docs/v2/local-platform/backtesting/results.md#03-Runtime-Statistics) on Local Platform `<organizationWorkspace> / <projectName> / backtests / <unixTimestamp> / <algorithmId>.json` |
| Local | Live Trading | Live results page on Local Platform `<organizationWorkspace> / <projectName> / live / <timeStamp> / / L-<deploymentId>.json` |

## Examples

The following examples demonstrate common practices for setting runtime statistics.

### Example 1: Display Banner

The following algorithm demonstrates how to put calculated runtime statistics of interest in the top display banner in the backtest interface and plot the data for analysis.

```python
class RuntimeStatisticsAlgorithm(QCAlgorithm):
    def initialize(self) -> None:
        self.set_start_date(2024, 9, 12)
        self.set_end_date(2024, 10, 1)
        self.set_cash(1000000)

        # Request SPY data to trade.
        self.spy = self.add_equity("SPY").symbol
        # Create an EMA indicator to generate trade signals.
        self._ema = self.ema(self.spy, 20, Resolution.DAILY)
        # Warms up indicator for immediate readiness.
        self.warm_up_indicator(self.spy, self._ema, Resolution.DAILY)

    def on_data(self, slice: Slice) -> None:
        bar = slice.bars.get(self.spy)
        if bar:
            # Trend-following strategy using price and EMA.
            # If the price is above the EMA, SPY is in an uptrend, and we buy it.
            if bar.close > self._ema.current.value and not self.portfolio[self.spy].is_long:
                self.set_holdings(self.spy, 1)
            elif bar.close < self._ema.current.value and not self.portfolio[self.spy].is_short:
                self.set_holdings(self.spy, -1)

    def on_end_of_day(self, symbol: Symbol) -> None:
        # Set the 95VaR and fee-to-profit ratio to the display banner.
        var = self.statistics.total_performance.portfolio_statistics.value_at_risk_95
        self.set_runtime_statistic("95VaR", var)
        fee_to_profit = self.statistics.total_performance.trade_statistics.total_fees /\
            self.statistics.total_performance.trade_statistics.total_profit_loss \
            if self.statistics.total_performance.trade_statistics.total_profit_loss != 0 else 0
        self.set_runtime_statistic("Fee-to-Profit", fee_to_profit)

        # Plot the calculated statistics.
        self.plot("Statistics", "95VaR", var)
        self.plot("Statistics", "fee-to-profit", fee_to_profit)

    def on_end_of_algorithm(self) -> None:
        # Log the 95VaR when the algorithm stops
        value_at_risk_95 = self.runtime_statistics["95VaR"]
        self.log(f'Final {value_at_risk_95=}')
```
