Spaces:
Sleeping
Sleeping
QAway-to
commited on
Commit
·
f4f3f95
1
Parent(s):
b52d86a
without k_metrics
Browse files- analyzer.py +24 -0
- app.py +26 -25
analyzer.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
def fetch_metrics(portfolio_id: str) -> dict | None:
|
| 2 |
+
try:
|
| 3 |
+
url = f"https://api.tradelink.pro/portfolio/get?portfolioId={portfolio_id}&extended=1&declaration=1&step=day&lang=en&incViews=1"
|
| 4 |
+
response = requests.get(url)
|
| 5 |
+
response.raise_for_status()
|
| 6 |
+
extended = response.json().get("data", {}).get("extended", {})
|
| 7 |
+
keys = [
|
| 8 |
+
# 🔹 Доходность и риск
|
| 9 |
+
"alphaRatio", "betaRatio", "cagr", "sharpe", "sortino", "volatility",
|
| 10 |
+
"kSortino", "kCalmar", "kSharpe",
|
| 11 |
+
|
| 12 |
+
# 🔹 Просадки
|
| 13 |
+
"maxDD", "mddDuration", "maxBalance",
|
| 14 |
+
|
| 15 |
+
# 🔹 Поведение стратегии
|
| 16 |
+
"losingDays", "winningDays", "selfProfitRate",
|
| 17 |
+
|
| 18 |
+
# 🔹 Актуальные показатели доходности
|
| 19 |
+
"lastWeekNetProfit", "lastMonthNetProfit", "lastQuarterGrowth", "lastYearNetGrowth"
|
| 20 |
+
]
|
| 21 |
+
|
| 22 |
+
return {k: extended[k] for k in keys if isinstance(extended.get(k), (int, float))}
|
| 23 |
+
except:
|
| 24 |
+
return None
|
app.py
CHANGED
|
@@ -2,6 +2,7 @@ import gradio as gr
|
|
| 2 |
import requests
|
| 3 |
import re
|
| 4 |
import os
|
|
|
|
| 5 |
from openai import OpenAI
|
| 6 |
|
| 7 |
|
|
@@ -60,31 +61,31 @@ def extract_portfolio_id(text: str) -> str | None:
|
|
| 60 |
)
|
| 61 |
return match.group(0) if match else None
|
| 62 |
|
| 63 |
-
# Получение метрик
|
| 64 |
-
def fetch_metrics(portfolio_id: str) -> dict | None:
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
|
| 89 |
# # Анализ одного портфеля
|
| 90 |
# def analyze_portfolio_streaming(text: str):
|
|
|
|
| 2 |
import requests
|
| 3 |
import re
|
| 4 |
import os
|
| 5 |
+
from analyzer import fetch_metrics
|
| 6 |
from openai import OpenAI
|
| 7 |
|
| 8 |
|
|
|
|
| 61 |
)
|
| 62 |
return match.group(0) if match else None
|
| 63 |
|
| 64 |
+
# # Получение метрик
|
| 65 |
+
# def fetch_metrics(portfolio_id: str) -> dict | None:
|
| 66 |
+
# try:
|
| 67 |
+
# url = f"https://api.tradelink.pro/portfolio/get?portfolioId={portfolio_id}&extended=1&declaration=1&step=day&lang=en&incViews=1"
|
| 68 |
+
# response = requests.get(url)
|
| 69 |
+
# response.raise_for_status()
|
| 70 |
+
# extended = response.json().get("data", {}).get("extended", {})
|
| 71 |
+
# keys = [
|
| 72 |
+
# # 🔹 Доходность и риск
|
| 73 |
+
# "alphaRatio", "betaRatio", "cagr", "sharpe", "sortino", "volatility",
|
| 74 |
+
# "kSortino", "kCalmar", "kSharpe",
|
| 75 |
+
#
|
| 76 |
+
# # 🔹 Просадки
|
| 77 |
+
# "maxDD", "mddDuration", "maxBalance",
|
| 78 |
+
#
|
| 79 |
+
# # 🔹 Поведение стратегии
|
| 80 |
+
# "losingDays", "winningDays", "selfProfitRate",
|
| 81 |
+
#
|
| 82 |
+
# # 🔹 Актуальные показатели доходности
|
| 83 |
+
# "lastWeekNetProfit", "lastMonthNetProfit", "lastQuarterGrowth", "lastYearNetGrowth"
|
| 84 |
+
# ]
|
| 85 |
+
#
|
| 86 |
+
# return {k: extended[k] for k in keys if isinstance(extended.get(k), (int, float))}
|
| 87 |
+
# except:
|
| 88 |
+
# return None
|
| 89 |
|
| 90 |
# # Анализ одного портфеля
|
| 91 |
# def analyze_portfolio_streaming(text: str):
|