Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add noise level metric to backtest range #262

Open
MDUYN opened this issue Jun 8, 2024 · 0 comments
Open

Add noise level metric to backtest range #262

MDUYN opened this issue Jun 8, 2024 · 0 comments

Comments

@MDUYN
Copy link
Collaborator

MDUYN commented Jun 8, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant