I think there should be another parameter for that in paramgrid. After all, too low…
- User
I think there should be another parameter for that in param_grid. After all, too low values will result in lower winrate while too high values will result in missing some of the profitable trades.import numpy as np import pandas as pd import vectorbt as vbt import ccxt from datetime import datetime, timedelta from numba import njit, prange import warnings from concurrent.futures import ThreadPoolExecutor from functools import partial import time from threading import Lock import matplotlib.pyplot as plt import seaborn as sns import os from itertools import product
warnings.filterwarnings('ignore')
@njit def calculate_volume_profile(prices, volumes, bucket_count): """Calculate volume profile metrics using Numba optimization.""" if len(prices) == 0 or len(volumes) == 0: return np.zeros(bucket_count), np.zeros(bucket_count)
min_price = np.min(prices) max_price = np.max(prices) # Prevent division by zero if min_price == max_price: price_range = 1.0 else: price_range = max_price - min_price bucket_size = price_range / bucket_count volume_profile = np.zeros(bucket_count) price_buckets = np.zeros(bucket_count) for i in range(len(prices)): if bucket_size > 0: bucket_idx = int((prices[i] - min_price) / bucket_size) if 0 <= bucket_idx < bucket_count: volume_profile[bucket_idx] += volumes[i] price_buckets[bucket_idx] = min_price + (bucket_idx + 0.5) * bucket_size return volume_profile, price_buckets@njit def identify_volume_nodes(volume_profile, price_buckets, threshold, min_distance): """Identify high volume nodes using Numba optimization with absolute distance.""" if len(volume_profile) == 0 or len(price_buckets) == 0: return np.zeros((0, 2), dtype=np.float64)
total_volume = np.sum(volume_profile) if total_volume == 0: return np.zeros((0, 2), dtype=np.float64) normalized_volume = volume_profile / total_volume # Pre-allocate maximum possible nodes max_nodes = len(volume_profile) temp_nodes = np.zeros((max_nodes, 2), dtype=np.float64) node_count = 0 # Find peaks more leniently for i in range(1, len(volume_profile) - 1): is_peak = normalized_volume[i] > threshold # Check if it's a local maximum or close to being one if is_peak: if (normalized_volume[i] >= normalized_volume[i - 1] * 0.95 and normalized_volume[i] >= normalized_volume[i + 1] * 0.95): temp_nodes[node_count, 0] = price_buckets[i] temp_nodes[node_count, 1] = normalized_volume[i] node_count += 1 if node_count == 0: return np.zeros((0, 2), dtype=np.float64) # Create array with actual nodes nodes = temp_nodes[:node_count] # Sort nodes by price sorted_indices = np.argsort(nodes[:, 0]) nodes = nodes[sorted_indices] # Filter nodes by absolute minimum distance filtered_nodes = np.zeros((node_count, 2), dtype=np.float64) filtered_count = 0 filtered_nodes[filtered_count] = nodes[0] filtered_count += 1 for i in range(1, node_count): absolute_distance = np.abs(nodes[i, 0] - filtered_nodes[filtered_count - 1, 0]) if absolute_distance > min_distance: filtered_nodes[filtered_count] = nodes[i] filtered_count += 1 return filtered_nodes[:filtered_count] - Assistant