InNoobWeTrust
commited on
Commit
•
2931ce4
1
Parent(s):
60beffb
Update visualization
Browse files- streamlit_app.py +22 -18
streamlit_app.py
CHANGED
@@ -31,25 +31,29 @@ def gen_charts(asset, chart_size={"width": 560, "height": 300}):
|
|
31 |
y=alt.Y("Volume:Q"),
|
32 |
color="Funds:N",
|
33 |
)
|
|
|
|
|
|
|
34 |
)
|
35 |
trading_vol_total_fig = (
|
36 |
alt.Chart(etf_volumes)
|
37 |
.transform_fold(
|
38 |
etf_volumes.drop(columns="Date").columns.to_list(), as_=["Funds", "Volume"]
|
39 |
)
|
40 |
-
.
|
41 |
.encode(
|
42 |
-
x=alt.X("Date:T", axis=alt.Axis(tickCount="day")),
|
43 |
y=alt.Y("sum(Volume):Q", title="Total Volume"),
|
44 |
-
color=alt.value("
|
45 |
-
opacity=alt.value(0.5),
|
46 |
)
|
|
|
|
|
|
|
47 |
)
|
48 |
# Combine trading volume and average trading volume
|
49 |
-
trading_vol_fig = trading_vol_total_fig
|
50 |
trading_vol_fig = trading_vol_fig.properties(
|
51 |
title=f"{asset} ETF trading volume",
|
52 |
-
**chart_size,
|
53 |
)
|
54 |
|
55 |
# Net flow individual
|
@@ -61,7 +65,7 @@ def gen_charts(asset, chart_size={"width": 560, "height": 300}):
|
|
61 |
)
|
62 |
.mark_line()
|
63 |
.encode(
|
64 |
-
x=alt.X("Date:T", axis=alt.Axis(tickCount="day"
|
65 |
y=alt.Y("Net Flow:Q"),
|
66 |
color="Funds:N",
|
67 |
)
|
@@ -71,9 +75,9 @@ def gen_charts(asset, chart_size={"width": 560, "height": 300}):
|
|
71 |
)
|
72 |
net_flow_total_fig = (
|
73 |
alt.Chart(etf_flow_total)
|
74 |
-
.
|
75 |
.encode(
|
76 |
-
x=alt.X("Date:T", axis=alt.Axis(tickCount="day")),
|
77 |
y=alt.Y("Total:Q"),
|
78 |
color=alt.condition(
|
79 |
alt.datum.Total > 0,
|
@@ -85,16 +89,16 @@ def gen_charts(asset, chart_size={"width": 560, "height": 300}):
|
|
85 |
width=chart_size['width'],
|
86 |
height=chart_size['height'] / 2,
|
87 |
)
|
88 |
-
net_flow_individual_fig =
|
89 |
net_flow_individual_fig = net_flow_individual_fig.resolve_scale(x='shared').properties(
|
90 |
title=f"{asset} ETF net flow of individual funds",
|
91 |
)
|
92 |
|
93 |
net_flow_total_fig = (
|
94 |
alt.Chart(etf_flow_total)
|
95 |
-
.
|
96 |
.encode(
|
97 |
-
x=alt.X("Date:T", axis=alt.Axis(tickCount="day")),
|
98 |
y=alt.Y("Total:Q"),
|
99 |
color=alt.condition(
|
100 |
alt.datum.Total > 0,
|
@@ -111,7 +115,7 @@ def gen_charts(asset, chart_size={"width": 560, "height": 300}):
|
|
111 |
alt.Chart(price)
|
112 |
.mark_line()
|
113 |
.encode(
|
114 |
-
x=alt.X("Date:T", axis=alt.Axis(tickCount="day"
|
115 |
y=alt.Y("Price:Q").scale(zero=False),
|
116 |
color=alt.value("crimson"),
|
117 |
)
|
@@ -120,7 +124,7 @@ def gen_charts(asset, chart_size={"width": 560, "height": 300}):
|
|
120 |
height=chart_size['height'] / 2,
|
121 |
)
|
122 |
|
123 |
-
net_flow_total_fig =
|
124 |
net_flow_total_fig = net_flow_total_fig.resolve_scale(x='shared').properties(
|
125 |
title=f"{asset} ETF net flow total vs asset price",
|
126 |
)
|
@@ -134,7 +138,7 @@ def gen_charts(asset, chart_size={"width": 560, "height": 300}):
|
|
134 |
)
|
135 |
.mark_area()
|
136 |
.encode(
|
137 |
-
x=alt.X("Date:T", axis=alt.Axis(tickCount="day")),
|
138 |
y=alt.Y("Net Flow:Q"),
|
139 |
color=alt.Color("Funds:N", scale=alt.Scale(scheme="tableau20")),
|
140 |
)
|
@@ -142,7 +146,7 @@ def gen_charts(asset, chart_size={"width": 560, "height": 300}):
|
|
142 |
width=chart_size['width'],
|
143 |
height=chart_size['height'] / 2,
|
144 |
)
|
145 |
-
cum_flow_individual_net_fig =
|
146 |
cum_flow_individual_net_fig = cum_flow_individual_net_fig.resolve_scale(x='shared').properties(
|
147 |
title=f"{asset} ETF cumulative flow of individual funds vs asset price",
|
148 |
)
|
@@ -155,7 +159,7 @@ def gen_charts(asset, chart_size={"width": 560, "height": 300}):
|
|
155 |
)
|
156 |
.mark_area()
|
157 |
.encode(
|
158 |
-
x=alt.X("Date:T", axis=alt.Axis(tickCount="day")),
|
159 |
y=alt.Y("Total:Q", impute={"value": 0}),
|
160 |
color=alt.Color(
|
161 |
"negative:N", title="Negative Flow", scale=alt.Scale(scheme="set2")
|
@@ -165,7 +169,7 @@ def gen_charts(asset, chart_size={"width": 560, "height": 300}):
|
|
165 |
width=chart_size['width'],
|
166 |
height=chart_size['height'] / 2,
|
167 |
)
|
168 |
-
cum_flow_total_fig =
|
169 |
cum_flow_total_fig = cum_flow_total_fig.resolve_scale(x='shared').properties(
|
170 |
title=f"{asset} ETF cumulative flow total vs asset price",
|
171 |
)
|
|
|
31 |
y=alt.Y("Volume:Q"),
|
32 |
color="Funds:N",
|
33 |
)
|
34 |
+
).properties(
|
35 |
+
width=chart_size['width'],
|
36 |
+
height=chart_size['height'] / 2,
|
37 |
)
|
38 |
trading_vol_total_fig = (
|
39 |
alt.Chart(etf_volumes)
|
40 |
.transform_fold(
|
41 |
etf_volumes.drop(columns="Date").columns.to_list(), as_=["Funds", "Volume"]
|
42 |
)
|
43 |
+
.mark_rule()
|
44 |
.encode(
|
45 |
+
x=alt.X("Date:T", axis=alt.Axis(tickCount="day", title='', labels=False)),
|
46 |
y=alt.Y("sum(Volume):Q", title="Total Volume"),
|
47 |
+
color=alt.value("teal"),
|
|
|
48 |
)
|
49 |
+
).properties(
|
50 |
+
width=chart_size['width'],
|
51 |
+
height=chart_size['height'] / 2,
|
52 |
)
|
53 |
# Combine trading volume and average trading volume
|
54 |
+
trading_vol_fig = trading_vol_total_fig & trading_vol_fig
|
55 |
trading_vol_fig = trading_vol_fig.properties(
|
56 |
title=f"{asset} ETF trading volume",
|
|
|
57 |
)
|
58 |
|
59 |
# Net flow individual
|
|
|
65 |
)
|
66 |
.mark_line()
|
67 |
.encode(
|
68 |
+
x=alt.X("Date:T", axis=alt.Axis(tickCount="day")),
|
69 |
y=alt.Y("Net Flow:Q"),
|
70 |
color="Funds:N",
|
71 |
)
|
|
|
75 |
)
|
76 |
net_flow_total_fig = (
|
77 |
alt.Chart(etf_flow_total)
|
78 |
+
.mark_rule()
|
79 |
.encode(
|
80 |
+
x=alt.X("Date:T", axis=alt.Axis(tickCount="day", title='', labels=False)),
|
81 |
y=alt.Y("Total:Q"),
|
82 |
color=alt.condition(
|
83 |
alt.datum.Total > 0,
|
|
|
89 |
width=chart_size['width'],
|
90 |
height=chart_size['height'] / 2,
|
91 |
)
|
92 |
+
net_flow_individual_fig = net_flow_total_fig & net_flow_individual_fig
|
93 |
net_flow_individual_fig = net_flow_individual_fig.resolve_scale(x='shared').properties(
|
94 |
title=f"{asset} ETF net flow of individual funds",
|
95 |
)
|
96 |
|
97 |
net_flow_total_fig = (
|
98 |
alt.Chart(etf_flow_total)
|
99 |
+
.mark_rule()
|
100 |
.encode(
|
101 |
+
x=alt.X("Date:T", axis=alt.Axis(tickCount="day", title='', labels=False)),
|
102 |
y=alt.Y("Total:Q"),
|
103 |
color=alt.condition(
|
104 |
alt.datum.Total > 0,
|
|
|
115 |
alt.Chart(price)
|
116 |
.mark_line()
|
117 |
.encode(
|
118 |
+
x=alt.X("Date:T", axis=alt.Axis(tickCount="day")),
|
119 |
y=alt.Y("Price:Q").scale(zero=False),
|
120 |
color=alt.value("crimson"),
|
121 |
)
|
|
|
124 |
height=chart_size['height'] / 2,
|
125 |
)
|
126 |
|
127 |
+
net_flow_total_fig = net_flow_total_fig & price_fig
|
128 |
net_flow_total_fig = net_flow_total_fig.resolve_scale(x='shared').properties(
|
129 |
title=f"{asset} ETF net flow total vs asset price",
|
130 |
)
|
|
|
138 |
)
|
139 |
.mark_area()
|
140 |
.encode(
|
141 |
+
x=alt.X("Date:T", axis=alt.Axis(tickCount="day", title='', labels=False)),
|
142 |
y=alt.Y("Net Flow:Q"),
|
143 |
color=alt.Color("Funds:N", scale=alt.Scale(scheme="tableau20")),
|
144 |
)
|
|
|
146 |
width=chart_size['width'],
|
147 |
height=chart_size['height'] / 2,
|
148 |
)
|
149 |
+
cum_flow_individual_net_fig = cum_flow_individual_net_fig & price_fig
|
150 |
cum_flow_individual_net_fig = cum_flow_individual_net_fig.resolve_scale(x='shared').properties(
|
151 |
title=f"{asset} ETF cumulative flow of individual funds vs asset price",
|
152 |
)
|
|
|
159 |
)
|
160 |
.mark_area()
|
161 |
.encode(
|
162 |
+
x=alt.X("Date:T", axis=alt.Axis(tickCount="day", title='', labels=False)),
|
163 |
y=alt.Y("Total:Q", impute={"value": 0}),
|
164 |
color=alt.Color(
|
165 |
"negative:N", title="Negative Flow", scale=alt.Scale(scheme="set2")
|
|
|
169 |
width=chart_size['width'],
|
170 |
height=chart_size['height'] / 2,
|
171 |
)
|
172 |
+
cum_flow_total_fig = cum_flow_total_fig & price_fig
|
173 |
cum_flow_total_fig = cum_flow_total_fig.resolve_scale(x='shared').properties(
|
174 |
title=f"{asset} ETF cumulative flow total vs asset price",
|
175 |
)
|