Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -11,14 +11,27 @@ from Gradio_UI import GradioUI
|
|
11 |
|
12 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
13 |
@tool
|
14 |
-
def
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
20 |
"""
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
@tool
|
24 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
11 |
|
12 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
13 |
@tool
|
14 |
+
def calculate_historical_var(returns, var_level=0.95):
|
15 |
+
"""
|
16 |
+
Calculate the Value at Risk (VaR) using the historical method.
|
17 |
+
|
18 |
+
Parameters:
|
19 |
+
returns (np.array): Array of daily returns.
|
20 |
+
var_level (float): VaR level (e.g., 0.95 for 95%).
|
21 |
+
|
22 |
+
Returns:
|
23 |
+
float: VaR value.
|
24 |
"""
|
25 |
+
# Sort the returns in ascending order
|
26 |
+
sorted_returns = np.sort(returns)
|
27 |
+
|
28 |
+
# Determine the index for the VaR level
|
29 |
+
index = int((1 - var_level) * len(returns))
|
30 |
+
|
31 |
+
# Get the VaR value
|
32 |
+
var_value = sorted_returns[index]
|
33 |
+
|
34 |
+
return var_value
|
35 |
|
36 |
@tool
|
37 |
def get_current_time_in_timezone(timezone: str) -> str:
|