Devendra21 commited on
Commit
71336f7
·
verified ·
1 Parent(s): 7bf54be

Update utils/model_inference.py

Browse files
Files changed (1) hide show
  1. utils/model_inference.py +42 -36
utils/model_inference.py CHANGED
@@ -1,44 +1,50 @@
 
1
  import numpy as np
2
- from datetime import datetime, timedelta
3
- import pytz
4
-
5
- # Function to generate signals for multiple currency pairs
6
- def generate_forex_signals(trading_capital, market_risk, user_timezone):
7
- # Ensure the user timezone is valid
8
- try:
9
- user_tz = pytz.timezone(user_timezone)
10
- except pytz.UnknownTimeZoneError:
11
- raise ValueError("Invalid timezone entered. Please check the format.")
12
-
13
- # Define market risk levels and their corresponding risk percentages
14
- risk_level = {'Low': 0.01, 'Medium': 0.03, 'High': 0.05}
15
- if market_risk not in risk_level:
16
- raise ValueError("Invalid risk level. Choose from Low, Medium, or High.")
17
- risk_percentage = risk_level[market_risk]
18
-
19
- # Currency pairs to evaluate
20
- currency_pairs = ["EUR/USD", "GBP/USD", "USD/JPY"]
21
-
22
- # Generate dummy signals for each currency pair (replace this with your model's predictions)
23
- signals = []
24
  for pair in currency_pairs:
25
- entry_time = datetime.now(user_tz).strftime("%Y-%m-%d %I:%M:%S %p")
26
- exit_time = (datetime.now(user_tz) + timedelta(hours=2)).strftime("%Y-%m-%d %I:%M:%S %p")
27
- roi = np.random.uniform(5, 20) # Random ROI between 5% and 20%
28
- signal_strength = np.random.uniform(0.7, 1.0) # Random signal strength
29
- signals.append({
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  "currency_pair": pair,
31
- "entry_time": entry_time,
32
- "exit_time": exit_time,
33
- "roi": roi,
34
- "signal_strength": signal_strength
35
- })
 
 
 
36
 
37
- # Find the signal with the highest ROI
38
- best_signal = max(signals, key=lambda x: x["roi"])
39
 
40
- # Return the best signal and all signals
41
  return {
42
  "best_signal": best_signal,
43
- "all_signals": signals
44
  }
 
1
+ import datetime
2
  import numpy as np
3
+ from utils import fetch_forex_data, calculate_technical_indicators
4
+
5
+ # Function to generate forex signals
6
+ def generate_forex_signals(trading_capital, market_risk, timezone):
7
+ # Define the top 10 most popular currency pairs
8
+ currency_pairs = [
9
+ "EUR/USD", "GBP/USD", "USD/JPY", "AUD/USD", "USD/CAD",
10
+ "USD/CHF", "NZD/USD", "EUR/JPY", "GBP/JPY", "AUD/JPY"
11
+ ]
12
+
13
+ all_signals = []
14
+
 
 
 
 
 
 
 
 
 
 
15
  for pair in currency_pairs:
16
+ # Fetch historical data for the currency pair
17
+ data = fetch_forex_data(pair, timeframe="15m")
18
+
19
+ # Calculate technical indicators (e.g., RSI, MACD, Bollinger Bands)
20
+ indicators = calculate_technical_indicators(data)
21
+
22
+ # Generate trade signal
23
+ entry_time = data.index[-1]
24
+ exit_time = entry_time + datetime.timedelta(minutes=15)
25
+
26
+ roi = np.random.uniform(10, 20) # Random ROI between 10% and 20% for alpha signals
27
+ signal_strength = np.random.uniform(80, 100) # Random signal strength (80%-100%)
28
+
29
+ # Calculate Stop-Loss and Take-Profit levels based on risk
30
+ stop_loss = trading_capital * 0.01 # 1% of capital
31
+ take_profit = trading_capital * (roi / 100) # ROI percentage of capital
32
+
33
+ signal = {
34
  "currency_pair": pair,
35
+ "entry_time": entry_time.strftime("%Y-%m-%d %H:%M:%S"),
36
+ "exit_time": exit_time.strftime("%Y-%m-%d %H:%M:%S"),
37
+ "roi": round(roi, 2),
38
+ "signal_strength": round(signal_strength, 2),
39
+ "stop_loss": round(stop_loss, 2),
40
+ "take_profit": round(take_profit, 2),
41
+ }
42
+ all_signals.append(signal)
43
 
44
+ # Select the best signal (highest ROI)
45
+ best_signal = max(all_signals, key=lambda x: x["roi"])
46
 
 
47
  return {
48
  "best_signal": best_signal,
49
+ "all_signals": all_signals
50
  }