Skip to content

Add noise level metric to backtest range #262

Open
@MDUYN

Description

@MDUYN

For a backtest range we would like to show the noise level for a given symbol.

Image

Where:

  • Net Price Change is the absolute difference between the price at the end of the period and the price at the beginning of the period.
  • Sum of Absolute Price Changes is the sum of the absolute differences between each consecutive day's prices within the period.
import pandas as pd

# Example DataFrame with OHLCV data
data = {
    'Date': ['2024-01-01', '2024-01-02', '2024-01-03', '2024-01-04', '2024-01-05'],
    'Open': [100, 102, 101, 103, 104],
    'High': [105, 106, 104, 107, 108],
    'Low': [99, 101, 100, 102, 103],
    'Close': [104, 105, 102, 106, 107],
    'Volume': [1000, 1100, 1200, 1300, 1400]
}
df = pd.DataFrame(data)
df['Date'] = pd.to_datetime(df['Date'])
df.set_index('Date', inplace=True)

# Calculate daily price changes
df['Daily Change'] = df['Close'].diff()

# Calculate net price change over the period
net_price_change = abs(df['Close'].iloc[-1] - df['Close'].iloc[0])

# Calculate the sum of absolute daily price changes
sum_absolute_changes = df['Daily Change'].abs().sum()

# Calculate Efficiency Ratio
efficiency_ratio = net_price_change / sum_absolute_changes
print(f'Efficiency Ratio: {efficiency_ratio}')

There should be function in the backtest report that check if there is a symbol entry in the algorithm context object. If there is it will check with this symbol if a pandas dataframe can be found with ohlcv data. if there is a efficiency ratio will be add to the backtest range for the specific symbol.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions