File backtest.py
has 742 lines of code (exceeds 250 allowed). Consider refactoring. Open
from datetime import datetime
from typing import Callable, Literal, Optional, Union, Tuple
import pandas as pd
import numpy as np
from tqdm import tqdm
Function __ohlc_backtest_one_position_type
has a Cognitive Complexity of 43 (exceeds 5 allowed). Consider refactoring. Open
def __ohlc_backtest_one_position_type(
ohlcv_df: pd.DataFrame,
entry_function: Callable[[pd.Series, pd.Series], bool],
exit_function: Callable[[pd.Series, pd.Series, int], bool],
position_type: Literal["long", "short"],
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function __price_backtest_one_position_type
has a Cognitive Complexity of 42 (exceeds 5 allowed). Consider refactoring. Open
def __price_backtest_one_position_type(
price_df: pd.DataFrame,
entry_function: Callable[[pd.Series, pd.Series], bool],
exit_function: Callable[[pd.Series, pd.Series, int], bool],
position_type: Literal["long", "short"],
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Consider simplifying this complex logical expression. Open
if position_opened is False and entry_function(row, previous_row) is True:
position_opened = True
current_trade["entry_date"] = index
current_trade["entry_price"] = row.Close
current_trade["entry_reason"] = "Entry position triggered"
Consider simplifying this complex logical expression. Open
if position_opened is False and entry_function(row, previous_row) is True:
position_opened = True
current_trade["entry_date"] = index
current_trade["entry_price"] = row["Price"]
current_trade["entry_reason"] = "Entry position triggered"
Function price_short_only_backtester
has 14 arguments (exceeds 4 allowed). Consider refactoring. Open
def price_short_only_backtester(
Function price_long_only_backtester
has 14 arguments (exceeds 4 allowed). Consider refactoring. Open
def price_long_only_backtester(
Function ohlc_long_only_backtester
has 13 arguments (exceeds 4 allowed). Consider refactoring. Open
def ohlc_long_only_backtester(
Function ohlc_short_only_backtester
has 13 arguments (exceeds 4 allowed). Consider refactoring. Open
def ohlc_short_only_backtester(
Function price_short_only_backtester
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def price_short_only_backtester(
df: pd.DataFrame,
price_column: str,
short_entry_function: Callable[[pd.Series, pd.Series], bool],
short_exit_function: Callable[[pd.Series, pd.Series, int], bool],
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function ohlc_long_only_backtester
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def ohlc_long_only_backtester(
df: pd.DataFrame,
long_entry_function: Callable[[pd.Series, pd.Series], bool],
long_exit_function: Callable[[pd.Series, pd.Series, int], bool],
timeframe: Timeframe,
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function price_long_only_backtester
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def price_long_only_backtester(
df: pd.DataFrame,
price_column: str,
long_entry_function: Callable[[pd.Series, pd.Series], bool],
long_exit_function: Callable[[pd.Series, pd.Series, int], bool],
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function ohlc_short_only_backtester
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def ohlc_short_only_backtester(
df: pd.DataFrame,
short_entry_function: Callable[[pd.Series, pd.Series], bool],
short_exit_function: Callable[[pd.Series, pd.Series, int], bool],
timeframe: Timeframe,
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function price_long_only_backtester
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
def price_long_only_backtester(
df: pd.DataFrame,
price_column: str,
long_entry_function: Callable[[pd.Series, pd.Series], bool],
long_exit_function: Callable[[pd.Series, pd.Series, int], bool],
Function price_short_only_backtester
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
def price_short_only_backtester(
df: pd.DataFrame,
price_column: str,
short_entry_function: Callable[[pd.Series, pd.Series], bool],
short_exit_function: Callable[[pd.Series, pd.Series, int], bool],
Function ohlc_short_only_backtester
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
def ohlc_short_only_backtester(
df: pd.DataFrame,
short_entry_function: Callable[[pd.Series, pd.Series], bool],
short_exit_function: Callable[[pd.Series, pd.Series, int], bool],
timeframe: Timeframe,
Function ohlc_long_only_backtester
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
def ohlc_long_only_backtester(
df: pd.DataFrame,
long_entry_function: Callable[[pd.Series, pd.Series], bool],
long_exit_function: Callable[[pd.Series, pd.Series, int], bool],
timeframe: Timeframe,
Function __ohlc_backtest_one_position_type
has 8 arguments (exceeds 4 allowed). Consider refactoring. Open
def __ohlc_backtest_one_position_type(
Function __price_backtest_one_position_type
has 8 arguments (exceeds 4 allowed). Consider refactoring. Open
def __price_backtest_one_position_type(
Avoid too many return
statements within this function. Open
return ohlcv_df
Avoid too many return
statements within this function. Open
return ohlcv_df
Avoid too many return
statements within this function. Open
return price_df
Avoid too many return
statements within this function. Open
return price_df