52 lines
2.1 KiB
Python
52 lines
2.1 KiB
Python
|
|
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')
|
||
|
|
# Convert datetime column to datetime type
|
||
|
|
one_month_ago = pd.to_datetime('2025-04-05')
|
||
|
|
daily_data = data[pd.to_datetime(data['datetime']) >= one_month_ago]
|
||
|
|
print(f"Number of data points: {len(daily_data)}")
|
||
|
|
|
||
|
|
trend_detector = TrendDetectorSimple(daily_data, verbose=True)
|
||
|
|
trends = trend_detector.detect_trends(width=1)
|
||
|
|
trend_detector.plot_trends(trends)
|
||
|
|
|
||
|
|
#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)')
|