solanaexpert commited on
Commit
024bb73
·
verified ·
1 Parent(s): d1b813d

Update MLCryptoForecasterAllAssetsTPSL.py

Browse files
Files changed (1) hide show
  1. MLCryptoForecasterAllAssetsTPSL.py +5 -4
MLCryptoForecasterAllAssetsTPSL.py CHANGED
@@ -9,7 +9,6 @@ from sklearn.metrics import classification_report
9
  import ta
10
 
11
  # Function to log results to both console and file
12
- # Does not insert blank lines; blank lines added explicitly after each asset block
13
  def log_results(message, filename="predictions_results.txt"):
14
  print(message)
15
  with open(filename, "a") as f:
@@ -28,7 +27,7 @@ if os.path.exists(result_file):
28
 
29
  # Initialize result file header
30
  with open(result_file, "w") as f:
31
- f.write("Asset,Accuracy,Optimal_UP_TP,Optimal_UP_SL,Optimal_DN_TP,Optimal_DN_SL\n")
32
 
33
  # Get USDT-quoted trading symbols
34
  symbols = [s['symbol'] for s in client.get_exchange_info()['symbols']
@@ -120,10 +119,12 @@ for symbol in symbols:
120
  report = classification_report(yte, ypr, zero_division=0)
121
  log_results(f"Classification report for {symbol}:\n{report}", result_file)
122
 
123
- # Predict latest trend and log it
 
 
124
  latest = model.predict(X.iloc[-1:].values)[0]
125
  trend_map = {1:'Uptrend',0:'Downtrend',-1:'Neutral'}
126
- log_results(f"Predicted next trend for {symbol}: {trend_map[latest]}", result_file)
127
 
128
  # Optimize TP/SL and log results
129
  hist_sign = model.predict(X.values)
 
9
  import ta
10
 
11
  # Function to log results to both console and file
 
12
  def log_results(message, filename="predictions_results.txt"):
13
  print(message)
14
  with open(filename, "a") as f:
 
27
 
28
  # Initialize result file header
29
  with open(result_file, "w") as f:
30
+ f.write("Asset,Time,Price,Prediction,Optimal_UP_TP,Optimal_UP_SL,Optimal_DN_TP,Optimal_DN_SL\n")
31
 
32
  # Get USDT-quoted trading symbols
33
  symbols = [s['symbol'] for s in client.get_exchange_info()['symbols']
 
119
  report = classification_report(yte, ypr, zero_division=0)
120
  log_results(f"Classification report for {symbol}:\n{report}", result_file)
121
 
122
+ # Predict latest trend and log time & price
123
+ pred_time = df.index[-1]
124
+ pred_price = df['close'].iloc[-1]
125
  latest = model.predict(X.iloc[-1:].values)[0]
126
  trend_map = {1:'Uptrend',0:'Downtrend',-1:'Neutral'}
127
+ log_results(f"Time: {pred_time}, Price: {pred_price:.2f}, Prediction: {trend_map[latest]}", result_file)
128
 
129
  # Optimize TP/SL and log results
130
  hist_sign = model.predict(X.values)