cyberosa
commited on
Commit
·
dc11fb3
1
Parent(s):
17e1ac3
Adding description and better explanations
Browse files- app.py +14 -4
- notebooks/closed_markets.ipynb +22 -37
- tabs/trader_plots.py +29 -1
app.py
CHANGED
@@ -17,6 +17,7 @@ from tabs.trader_plots import (
|
|
17 |
trader_metric_choices,
|
18 |
get_metrics_text,
|
19 |
plot_winning_metric_per_trader,
|
|
|
20 |
)
|
21 |
|
22 |
from tabs.market_plots import plot_kl_div_per_market
|
@@ -189,20 +190,29 @@ with demo:
|
|
189 |
with gr.TabItem("📉Closed Markets Kullback–Leibler divergence"):
|
190 |
with gr.Row():
|
191 |
gr.Markdown(
|
192 |
-
"# Weekly
|
193 |
)
|
194 |
with gr.Row():
|
195 |
gr.Markdown(
|
196 |
-
"
|
197 |
)
|
198 |
with gr.Row():
|
199 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
200 |
kl_div_plot = plot_kl_div_per_market(closed_markets=closed_markets)
|
201 |
with gr.Column(scale=1):
|
202 |
-
|
|
|
203 |
with gr.TabItem("🎖️Weekly winning trades % per trader"):
|
204 |
with gr.Row():
|
205 |
gr.Markdown("# Winning trades percentage from weekly trades by trader")
|
|
|
|
|
206 |
with gr.Row():
|
207 |
winning_metric = plot_winning_metric_per_trader(weekly_winning_metrics)
|
208 |
|
|
|
17 |
trader_metric_choices,
|
18 |
get_metrics_text,
|
19 |
plot_winning_metric_per_trader,
|
20 |
+
get_interpretation_text,
|
21 |
)
|
22 |
|
23 |
from tabs.market_plots import plot_kl_div_per_market
|
|
|
190 |
with gr.TabItem("📉Closed Markets Kullback–Leibler divergence"):
|
191 |
with gr.Row():
|
192 |
gr.Markdown(
|
193 |
+
"# Weekly Market Prediction Accuracy for Closed Markets (Kullback-Leibler Divergence)"
|
194 |
)
|
195 |
with gr.Row():
|
196 |
gr.Markdown(
|
197 |
+
"The accuracy is measured as the difference between the distribution of the final outcome P = [prob(yes), prob(no)] and the final liquidity distribution of the market for the yes and no responses."
|
198 |
)
|
199 |
with gr.Row():
|
200 |
+
gr.Markdown(
|
201 |
+
"There are some edge cases in the Kullback-Leibler divergence formula that can lead to extreme or infinite values, particularly when the predicted probabilities are very different from the actual outcome. To handle these cases, we capped the maximum divergence value at 20. A high divergence value (close to or at 20) indicates markets where the predicted probabilities were significantly different from the real-world outcome, potentially even opposite to what actually occurred."
|
202 |
+
)
|
203 |
+
with gr.Row():
|
204 |
+
metrics_text = get_metrics_text()
|
205 |
+
with gr.Row():
|
206 |
+
with gr.Column(scale=2):
|
207 |
kl_div_plot = plot_kl_div_per_market(closed_markets=closed_markets)
|
208 |
with gr.Column(scale=1):
|
209 |
+
interpretation_text = get_interpretation_text()
|
210 |
+
|
211 |
with gr.TabItem("🎖️Weekly winning trades % per trader"):
|
212 |
with gr.Row():
|
213 |
gr.Markdown("# Winning trades percentage from weekly trades by trader")
|
214 |
+
with gr.Row():
|
215 |
+
metrics_text = get_metrics_text()
|
216 |
with gr.Row():
|
217 |
winning_metric = plot_winning_metric_per_trader(weekly_winning_metrics)
|
218 |
|
notebooks/closed_markets.ipynb
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
-
"execution_count":
|
6 |
"metadata": {},
|
7 |
"outputs": [],
|
8 |
"source": [
|
@@ -923,40 +923,6 @@
|
|
923 |
" return kl_divergence"
|
924 |
]
|
925 |
},
|
926 |
-
{
|
927 |
-
"cell_type": "code",
|
928 |
-
"execution_count": null,
|
929 |
-
"metadata": {},
|
930 |
-
"outputs": [],
|
931 |
-
"source": []
|
932 |
-
},
|
933 |
-
{
|
934 |
-
"cell_type": "code",
|
935 |
-
"execution_count": null,
|
936 |
-
"metadata": {},
|
937 |
-
"outputs": [],
|
938 |
-
"source": []
|
939 |
-
},
|
940 |
-
{
|
941 |
-
"cell_type": "code",
|
942 |
-
"execution_count": 36,
|
943 |
-
"metadata": {},
|
944 |
-
"outputs": [
|
945 |
-
{
|
946 |
-
"data": {
|
947 |
-
"text/plain": [
|
948 |
-
"719"
|
949 |
-
]
|
950 |
-
},
|
951 |
-
"execution_count": 36,
|
952 |
-
"metadata": {},
|
953 |
-
"output_type": "execute_result"
|
954 |
-
}
|
955 |
-
],
|
956 |
-
"source": [
|
957 |
-
"len(trade_markets)"
|
958 |
-
]
|
959 |
-
},
|
960 |
{
|
961 |
"cell_type": "code",
|
962 |
"execution_count": 37,
|
@@ -1013,7 +979,7 @@
|
|
1013 |
},
|
1014 |
{
|
1015 |
"cell_type": "code",
|
1016 |
-
"execution_count":
|
1017 |
"metadata": {},
|
1018 |
"outputs": [],
|
1019 |
"source": [
|
@@ -1808,7 +1774,7 @@
|
|
1808 |
},
|
1809 |
{
|
1810 |
"cell_type": "code",
|
1811 |
-
"execution_count":
|
1812 |
"metadata": {},
|
1813 |
"outputs": [],
|
1814 |
"source": [
|
@@ -1950,6 +1916,25 @@
|
|
1950 |
"print(kl_divergence(P,Q))"
|
1951 |
]
|
1952 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1953 |
{
|
1954 |
"cell_type": "code",
|
1955 |
"execution_count": 44,
|
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
+
"execution_count": 2,
|
6 |
"metadata": {},
|
7 |
"outputs": [],
|
8 |
"source": [
|
|
|
923 |
" return kl_divergence"
|
924 |
]
|
925 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
926 |
{
|
927 |
"cell_type": "code",
|
928 |
"execution_count": 37,
|
|
|
979 |
},
|
980 |
{
|
981 |
"cell_type": "code",
|
982 |
+
"execution_count": 3,
|
983 |
"metadata": {},
|
984 |
"outputs": [],
|
985 |
"source": [
|
|
|
1774 |
},
|
1775 |
{
|
1776 |
"cell_type": "code",
|
1777 |
+
"execution_count": 4,
|
1778 |
"metadata": {},
|
1779 |
"outputs": [],
|
1780 |
"source": [
|
|
|
1916 |
"print(kl_divergence(P,Q))"
|
1917 |
]
|
1918 |
},
|
1919 |
+
{
|
1920 |
+
"cell_type": "code",
|
1921 |
+
"execution_count": 7,
|
1922 |
+
"metadata": {},
|
1923 |
+
"outputs": [
|
1924 |
+
{
|
1925 |
+
"name": "stdout",
|
1926 |
+
"output_type": "stream",
|
1927 |
+
"text": [
|
1928 |
+
"13.815510557964274\n"
|
1929 |
+
]
|
1930 |
+
}
|
1931 |
+
],
|
1932 |
+
"source": [
|
1933 |
+
"Q = np.array([1e-6, 0.999999])#or [0.99, 0.01]\n",
|
1934 |
+
"P = np.array([1.0, 0.0])\n",
|
1935 |
+
"print(kl_divergence(P,Q))"
|
1936 |
+
]
|
1937 |
+
},
|
1938 |
{
|
1939 |
"cell_type": "code",
|
1940 |
"execution_count": 44,
|
tabs/trader_plots.py
CHANGED
@@ -14,7 +14,7 @@ default_trader_metric = "ROI"
|
|
14 |
|
15 |
def get_metrics_text() -> gr.Markdown:
|
16 |
metric_text = """
|
17 |
-
##
|
18 |
These metrics are computed weekly. The statistical measures are:
|
19 |
* min, max, 25th(q1), 50th(median) and 75th(q2) percentiles
|
20 |
* the upper and lower fences to delimit possible outliers
|
@@ -24,6 +24,34 @@ def get_metrics_text() -> gr.Markdown:
|
|
24 |
return gr.Markdown(metric_text)
|
25 |
|
26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
def plot_trader_metrics_by_market_creator(
|
28 |
metric_name: str, traders_df: pd.DataFrame
|
29 |
) -> gr.Plot:
|
|
|
14 |
|
15 |
def get_metrics_text() -> gr.Markdown:
|
16 |
metric_text = """
|
17 |
+
## Metrics at the graph
|
18 |
These metrics are computed weekly. The statistical measures are:
|
19 |
* min, max, 25th(q1), 50th(median) and 75th(q2) percentiles
|
20 |
* the upper and lower fences to delimit possible outliers
|
|
|
24 |
return gr.Markdown(metric_text)
|
25 |
|
26 |
|
27 |
+
def get_interpretation_text() -> gr.Markdown:
|
28 |
+
interpretation_text = """
|
29 |
+
## Interpreting KL-divergence values
|
30 |
+
### Moderate divergence:
|
31 |
+
* Y ≈ 0.9163
|
32 |
+
* Wrong market prediction closing at [0.4, 0.6] or [0.6, 0.4]
|
33 |
+
* Y ≈ 1.2040
|
34 |
+
* Wrong market prediction closing at [0.3, 0.7] or [0.7, 0.3]
|
35 |
+
* Y ≈ 1.6093
|
36 |
+
* Wrong market prediction closing at [0.2, 0.8] or [0.8, 0.2]
|
37 |
+
* Y ≈ 2.3026
|
38 |
+
* Wrong market prediction closing at [0.1, 0.9] or [0.9, 0.1]
|
39 |
+
|
40 |
+
### High divergence:
|
41 |
+
* Y ≈ 4.6052
|
42 |
+
* Very wrong prediction closing at [0.01, 0.99] or [0.99, 0.01]
|
43 |
+
* Y ≈ 6.9078
|
44 |
+
* Extremely wrong prediction closing at [0.001, 0.999] or [0.999, 0.001]
|
45 |
+
|
46 |
+
### Edge cases:
|
47 |
+
* Y ≈ 13.8155
|
48 |
+
* Near-certain wrong prediction closing at [1e-6, 0.999999] or [0.999999, 1e-6]
|
49 |
+
* Y = 20 (capped)
|
50 |
+
* Represents cases where the market prediction was essentially opposite to the outcome.
|
51 |
+
"""
|
52 |
+
return gr.Markdown(interpretation_text)
|
53 |
+
|
54 |
+
|
55 |
def plot_trader_metrics_by_market_creator(
|
56 |
metric_name: str, traders_df: pd.DataFrame
|
57 |
) -> gr.Plot:
|