diff --git a/main.py b/main.py index 0e54834..7b2d4fb 100644 --- a/main.py +++ b/main.py @@ -17,40 +17,4 @@ print(f"Number of data points: {len(daily_data)}") trend_detector = TrendDetectorSimple(daily_data, verbose=True) trends, analysis_results = trend_detector.detect_trends() -trend_detector.plot_trends(trends, analysis_results, "supertrend") - -#trend_detector = TrendDetectorMACD(daily_data, True) -#trends = trend_detector.detect_trends_MACD_signal() -#trend_detector.plot_trends(trends) - -# # Cycle detection (new code) -# print("\n===== CYCLE DETECTION =====") - -# # Daily cycles -# daily_detector = CycleDetector(daily_data, timeframe='daily') -# daily_avg_cycle = daily_detector.get_average_cycle_length() -# daily_window = daily_detector.get_cycle_window() - -# print(f"Daily Timeframe: Average Cycle Length = {daily_avg_cycle:.2f} days") -# if daily_window: -# print(f"Daily Cycle Window: {daily_window[0]:.2f} to {daily_window[2]:.2f} days") - -# weekly_detector = CycleDetector(daily_data, timeframe='weekly') -# weekly_avg_cycle = weekly_detector.get_average_cycle_length() -# weekly_window = weekly_detector.get_cycle_window() - -# print(f"\nWeekly Timeframe: Average Cycle Length = {weekly_avg_cycle:.2f} weeks") -# if weekly_window: -# print(f"Weekly Cycle Window: {weekly_window[0]:.2f} to {weekly_window[2]:.2f} weeks") - -# # Detect patterns -# two_drives = daily_detector.detect_two_drives_pattern() -# v_shapes = daily_detector.detect_v_shaped_lows() - -# print(f"\nDetected {len(two_drives)} 'Two Drives' patterns in daily data") -# print(f"Detected {len(v_shapes)} 'V-Shaped' lows in daily data") - -# # Plot cycles with detected patterns -# print("\nPlotting cycles and patterns...") -# daily_detector.plot_cycles(pattern_detection=['two_drives', 'v_shape'], title_suffix='(with Two Drives Pattern)') -# weekly_detector.plot_cycles(title_suffix='(Weekly View)') \ No newline at end of file +trend_detector.plot_trends(trends, analysis_results, "supertrend") \ No newline at end of file diff --git a/trend_detector_simple.py b/trend_detector_simple.py index bf1ff60..9563bcb 100644 --- a/trend_detector_simple.py +++ b/trend_detector_simple.py @@ -90,10 +90,8 @@ class TrendDetectorSimple: # Convert data to pandas DataFrame if it's not already if not isinstance(self.data, pd.DataFrame): if isinstance(self.data, list): - self.logger.info("Converting list to DataFrame") self.data = pd.DataFrame({'close': self.data}) else: - self.logger.error("Invalid data format provided") raise ValueError("Data must be a pandas DataFrame or a list") self.logger.info(f"Initialized TrendDetectorSimple with {len(self.data)} data points") @@ -171,16 +169,12 @@ class TrendDetectorSimple: - DataFrame with columns for timestamps, prices, and trend indicators - Dictionary containing analysis results including linear regression, SMAs, and SuperTrend indicators """ - self.logger.info(f"Detecting trends") - df = self.data.copy() close_prices = df['close'].values max_peaks, _ = find_peaks(close_prices) min_peaks, _ = find_peaks(-close_prices) - self.logger.info(f"Found {len(min_peaks)} local minima and {len(max_peaks)} local maxima") - df['is_min'] = False df['is_max'] = False @@ -192,7 +186,6 @@ class TrendDetectorSimple: result = df[['datetime', 'close', 'is_min', 'is_max']].copy() # Perform linear regression on min_peaks and max_peaks - self.logger.info("Performing linear regression on min and max peaks") min_prices = df['close'].iloc[min_peaks].values max_prices = df['close'].iloc[max_peaks].values