2025-05-06 15:24:36 +08:00
|
|
|
import pandas as pd
|
|
|
|
|
from trend_detector_macd import TrendDetectorMACD
|
|
|
|
|
from trend_detector_simple import TrendDetectorSimple
|
|
|
|
|
from cycle_detector import CycleDetector
|
|
|
|
|
|
|
|
|
|
# Load data from CSV file instead of database
|
|
|
|
|
data = pd.read_csv('data/btcusd_1-day_data.csv')
|
2025-05-06 16:20:43 +08:00
|
|
|
|
2025-05-06 15:24:36 +08:00
|
|
|
# Convert datetime column to datetime type
|
2025-05-06 16:20:43 +08:00
|
|
|
start_date = pd.to_datetime('2025-04-01')
|
|
|
|
|
stop_date = pd.to_datetime('2025-05-06')
|
|
|
|
|
|
|
|
|
|
daily_data = data[(pd.to_datetime(data['datetime']) >= start_date) &
|
|
|
|
|
(pd.to_datetime(data['datetime']) < stop_date)]
|
2025-05-06 15:24:36 +08:00
|
|
|
print(f"Number of data points: {len(daily_data)}")
|
|
|
|
|
|
|
|
|
|
trend_detector = TrendDetectorSimple(daily_data, verbose=True)
|
2025-05-08 16:23:25 +08:00
|
|
|
trends, analysis_results = trend_detector.detect_trends()
|
|
|
|
|
trend_detector.plot_trends(trends, analysis_results)
|
2025-05-06 15:24:36 +08:00
|
|
|
|
|
|
|
|
#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)')
|