Spaces:
Sleeping
Sleeping
import json | |
import os | |
# Load YOLO detection data (from the given file) | |
yolo_file_path = '/media/gjin/New Volume/BACKTEST_DATA/black_edition_rolling_window_20_candlestick_5/json_data_folder/LINK_USDT_2024-12-02/LINK_USDT_17-27-55.json' | |
with open(yolo_file_path, 'r') as f: | |
yolo_data = json.load(f) | |
# Load Zscore signal data (from the given file) | |
zscore_file_path = '/home/gjin/Documents/zscore/signalsLINK.json' | |
with open(zscore_file_path, 'r') as f: | |
zscore_data = json.load(f) | |
# Define a function to update the YOLO trend based on zscore detection | |
def update_trend_with_zscore(yolo_data, zscore_data): | |
for yolo_entry in yolo_data: | |
symbol = yolo_entry['symbol'] | |
date_and_time = yolo_entry['date_and_time'] | |
# Normalize the symbol from zscore data (remove slash to match YOLO format) | |
normalized_symbol = symbol.replace('/', '') # Example: "ADA/USDT" becomes "ADAUSDT" | |
# Match the YOLO entry with the zscore entry by symbol and timestamp | |
zscore_entry = next((item for item in zscore_data if item['symbol'].replace('/', '') == normalized_symbol and item['date_and_time'] == date_and_time), None) | |
if zscore_entry: | |
# If zscore detection is True and trend is "no trend", keep it as "no trend" | |
if zscore_entry['detection'] == 'True': | |
# Do not modify the trend if already set | |
if yolo_entry['trend'] == "no trend": | |
# Only set zscore detection flag if trend is "no trend" | |
yolo_entry['zscore_detection'] = True | |
else: | |
# Keep existing trend, just add zscore detection flag | |
if 'zscore_detection' not in yolo_entry: | |
yolo_entry['zscore_detection'] = True | |
else: | |
# If zscore detection is False, set the trend to "no trend based on zscore detection" | |
yolo_entry['trend'] = "no trend based on zscore detection" | |
if 'zscore_detection' in yolo_entry: | |
del yolo_entry['zscore_detection'] | |
else: | |
print(f"No zscore data found for {symbol} at {date_and_time}") | |
# Apply the function to update the YOLO data | |
update_trend_with_zscore(yolo_data, zscore_data) | |
# Define the output file path where the updated YOLO data will be saved | |
output_file_path = '/home/gjin/Documents/zscore/YOLO_WITH_ZSCORE/LINK_USDT_19-09-41_updated.json' | |
# Ensure the directory exists | |
os.makedirs(os.path.dirname(output_file_path), exist_ok=True) | |
# Save the updated YOLO data to the output file | |
with open(output_file_path, 'w') as f: | |
json.dump(yolo_data, f, indent=4) | |
print(f"Updated YOLO data has been saved to {output_file_path}") | |