InNoobWeTrust
commited on
Commit
·
1f4b746
1
Parent(s):
97ae727
fix: update visualizations
Browse files- requirements.txt +1 -2
- streamlit_app.py +78 -85
requirements.txt
CHANGED
@@ -1,5 +1,4 @@
|
|
1 |
streamlit
|
2 |
-
numpy
|
3 |
pandas
|
4 |
yfinance
|
5 |
-
|
|
|
1 |
streamlit
|
|
|
2 |
pandas
|
3 |
yfinance
|
4 |
+
altair
|
streamlit_app.py
CHANGED
@@ -1,12 +1,9 @@
|
|
1 |
import streamlit as st
|
2 |
|
3 |
-
import numpy as np
|
4 |
import pandas as pd
|
5 |
import yfinance as yf
|
6 |
|
7 |
-
import
|
8 |
-
import plotly.graph_objects as go
|
9 |
-
from plotly.subplots import make_subplots
|
10 |
|
11 |
|
12 |
def clean_etf_data(df):
|
@@ -141,111 +138,107 @@ if __name__ == "__main__":
|
|
141 |
|
142 |
# Section trading volume
|
143 |
st.subheader(f"{asset} ETF Trading volume")
|
144 |
-
trading_vol_fig =
|
145 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
146 |
)
|
147 |
-
st.
|
148 |
|
149 |
# Section net flow individual funds
|
150 |
st.subheader(f"{asset} ETF Net flow individual funds")
|
151 |
-
net_flow_individual_fig =
|
152 |
-
etf_flow_individual
|
153 |
-
|
154 |
-
|
155 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
156 |
)
|
157 |
-
st.
|
158 |
|
159 |
# Section net flow total vs asset price
|
160 |
st.subheader(f"{asset} ETF Net flow total vs asset price")
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
)
|
174 |
-
# Orange red bar for negative flow
|
175 |
-
net_flow_total_fig.add_trace(
|
176 |
-
go.Bar(
|
177 |
-
x=negative_flow.index,
|
178 |
-
y=negative_flow,
|
179 |
-
name="Total (negative)",
|
180 |
-
marker_color="orangered",
|
181 |
-
),
|
182 |
-
secondary_y=False,
|
183 |
)
|
184 |
# Line chart of price
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
|
|
|
|
|
|
|
|
|
|
192 |
),
|
193 |
-
|
194 |
)
|
195 |
-
net_flow_total_fig.update_layout(barmode="stack")
|
196 |
-
st.plotly_chart(net_flow_total_fig, use_container_width=True)
|
197 |
|
198 |
# Section cumulative flow individual vs asset price
|
199 |
st.subheader(f"{asset} ETF Cumulative flow of individual funds vs asset price")
|
200 |
cum_flow_individual = etf_flow_individual.cumsum()
|
201 |
-
cum_flow_individual_fig = make_subplots(specs=[[{"secondary_y": True}]])
|
202 |
# Stacking area chart of flow from individual funds
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
),
|
211 |
-
secondary_y=False,
|
212 |
)
|
213 |
-
# Line chart of price
|
214 |
-
cum_flow_individual_fig.add_trace(
|
215 |
-
go.Scatter(
|
216 |
-
x=price.index,
|
217 |
-
y=price,
|
218 |
-
name=f"{asset} Price",
|
219 |
-
mode="lines",
|
220 |
-
line=dict(color="darkgoldenrod"),
|
221 |
-
),
|
222 |
-
secondary_y=True,
|
223 |
)
|
224 |
-
st.
|
|
|
|
|
|
|
225 |
|
226 |
# Section cumulative flow total vs asset price
|
227 |
st.subheader(f"{asset} ETF Cumulative flow total vs asset price")
|
228 |
cum_flow_total = etf_flow_total.cumsum()
|
229 |
-
cum_flow_total_fig = make_subplots(specs=[[{"secondary_y": True}]])
|
230 |
# Area chart for cumulative flow
|
231 |
-
cum_flow_total_fig
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
|
|
|
|
|
|
|
|
|
|
239 |
)
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
x=price.index,
|
244 |
-
y=price,
|
245 |
-
name=f"{asset} Price",
|
246 |
-
mode="lines",
|
247 |
-
line=dict(color="darkgoldenrod"),
|
248 |
),
|
249 |
-
|
250 |
)
|
251 |
-
st.plotly_chart(cum_flow_total_fig, use_container_width=True)
|
|
|
1 |
import streamlit as st
|
2 |
|
|
|
3 |
import pandas as pd
|
4 |
import yfinance as yf
|
5 |
|
6 |
+
import altair as alt
|
|
|
|
|
7 |
|
8 |
|
9 |
def clean_etf_data(df):
|
|
|
138 |
|
139 |
# Section trading volume
|
140 |
st.subheader(f"{asset} ETF Trading volume")
|
141 |
+
trading_vol_fig = (
|
142 |
+
alt.Chart(etf_volumes.reset_index())
|
143 |
+
.transform_fold(etf_volumes.columns, as_=["Funds", "Volume"])
|
144 |
+
.mark_bar()
|
145 |
+
.encode(
|
146 |
+
x=alt.X("index:T", title="Date"),
|
147 |
+
y=alt.Y("Volume:Q", title="Volume"),
|
148 |
+
color="Funds:N",
|
149 |
+
)
|
150 |
)
|
151 |
+
st.altair_chart(trading_vol_fig, use_container_width=True)
|
152 |
|
153 |
# Section net flow individual funds
|
154 |
st.subheader(f"{asset} ETF Net flow individual funds")
|
155 |
+
net_flow_individual_fig = (
|
156 |
+
alt.Chart(etf_flow_individual.reset_index())
|
157 |
+
.transform_fold(
|
158 |
+
etf_flow_individual.columns,
|
159 |
+
as_=["Funds", "Net Flow"],
|
160 |
+
)
|
161 |
+
.mark_bar()
|
162 |
+
.encode(
|
163 |
+
x=alt.X("index:T", title="Date"),
|
164 |
+
y=alt.Y("Net Flow:Q", title="Net Flow"),
|
165 |
+
color="Funds:N",
|
166 |
+
)
|
167 |
)
|
168 |
+
st.altair_chart(net_flow_individual_fig, use_container_width=True)
|
169 |
|
170 |
# Section net flow total vs asset price
|
171 |
st.subheader(f"{asset} ETF Net flow total vs asset price")
|
172 |
+
net_flow_total_fig = (
|
173 |
+
alt.Chart(etf_flow_total.reset_index())
|
174 |
+
.mark_bar()
|
175 |
+
.encode(
|
176 |
+
x=alt.X("index:T", title="Date"),
|
177 |
+
y=alt.Y("Total:Q"),
|
178 |
+
color=alt.condition(
|
179 |
+
alt.datum.Total > 0,
|
180 |
+
alt.value("seagreen"), # The positive color
|
181 |
+
alt.value("orangered"), # The negative color
|
182 |
+
),
|
183 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
184 |
)
|
185 |
# Line chart of price
|
186 |
+
price_fig = (
|
187 |
+
alt.Chart(price.reset_index())
|
188 |
+
.mark_line()
|
189 |
+
.encode(
|
190 |
+
x=alt.X("index:T", title="Date"),
|
191 |
+
y=alt.Y("Close:Q", title="Price"),
|
192 |
+
color=alt.value("crimson"),
|
193 |
+
)
|
194 |
+
)
|
195 |
+
st.altair_chart(
|
196 |
+
(net_flow_total_fig + price_fig).resolve_scale(
|
197 |
+
y="independent",
|
198 |
),
|
199 |
+
use_container_width=True,
|
200 |
)
|
|
|
|
|
201 |
|
202 |
# Section cumulative flow individual vs asset price
|
203 |
st.subheader(f"{asset} ETF Cumulative flow of individual funds vs asset price")
|
204 |
cum_flow_individual = etf_flow_individual.cumsum()
|
|
|
205 |
# Stacking area chart of flow from individual funds
|
206 |
+
cum_flow_individual_net_fig = (
|
207 |
+
alt.Chart(cum_flow_individual.reset_index())
|
208 |
+
.transform_fold(cum_flow_individual.columns, as_=["Funds", "Net Flow"])
|
209 |
+
.mark_area()
|
210 |
+
.encode(
|
211 |
+
x=alt.X("index:T", title="Date"),
|
212 |
+
y=alt.Y("Net Flow:Q", title="Net Flow"),
|
213 |
+
color=alt.Color("Funds:N").scale(scheme="tableau20"),
|
|
|
214 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
215 |
)
|
216 |
+
st.altair_chart(
|
217 |
+
(cum_flow_individual_net_fig + price_fig).resolve_scale(y="independent"),
|
218 |
+
use_container_width=True,
|
219 |
+
)
|
220 |
|
221 |
# Section cumulative flow total vs asset price
|
222 |
st.subheader(f"{asset} ETF Cumulative flow total vs asset price")
|
223 |
cum_flow_total = etf_flow_total.cumsum()
|
|
|
224 |
# Area chart for cumulative flow
|
225 |
+
cum_flow_total_fig = (
|
226 |
+
alt.Chart(cum_flow_total.reset_index())
|
227 |
+
.transform_calculate(
|
228 |
+
negative="datum.Total < 0",
|
229 |
+
)
|
230 |
+
.mark_area()
|
231 |
+
.encode(
|
232 |
+
x=alt.X("index:T"),
|
233 |
+
y=alt.Y("Total:Q", impute={"value": 0}),
|
234 |
+
color=alt.Color("negative:N", title="Negative Flow").scale(
|
235 |
+
scheme="set2"
|
236 |
+
),
|
237 |
+
)
|
238 |
)
|
239 |
+
st.altair_chart(
|
240 |
+
(cum_flow_total_fig + price_fig).resolve_scale(
|
241 |
+
y="independent",
|
|
|
|
|
|
|
|
|
|
|
242 |
),
|
243 |
+
use_container_width=True,
|
244 |
)
|
|