-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
138 lines (84 loc) · 4.07 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import numpy as np
import pandas as pd
import datetime
import os
import random
import streamlit as st
import plotly.express as px
import plotly.graph_objects as go
from data_reader import df_big_mac, df_market, df_country, df_market_mapping, pct_change, metrics, top_variation_value, summary_metrics, big_mac_exchange_rate
from visuals import add_trace_big_mac, add_trace_exchange, geo_scatter, plot_big_mac, plot_exchange, update_layout, map_country, world_map
st.title('Inflation detective :sleuth_or_spy:')
# map_options = ["Inflation Hotspots","Volume BTC traded"]
# map_selection = st.sidebar.checkbox("World maps", value=False)
### Selection of countries for line plot of exchange rate:
country_selection = st.sidebar.multiselect('Country of interest',
options= df_market_mapping.country.sort_values().unique())
bitcoin_market = st.sidebar.multiselect('Trading of currencies for Bitcoins', options=["Global trade"])
### Columns for layout:
# column_1, column_2, column_3 = st.columns(3)
column_1, column_2 = st.columns(2)
### Global map Volume BTC
if bitcoin_market == ["Global trade"]:
try:
st.info("Tracking volume of BTC traded globally")
world_map_volume_btc = df_market_mapping[["country","volume_btc"]]
st.write(geo_scatter(world_map_volume_btc))
## Biggest traders by country:
top_variation_volume = top_variation_value(50, "volume_btc")
st.info("Countries moving highest volume on a day:")
st.table(top_variation_volume)
except:
print('Error ploting Volume BTC map')
# World map exchange rate:
if len(country_selection) == 0 and bitcoin_market == []:
world_map_inflation = world_map(df_market_mapping[["country","currency_code", "pct"]])
st.info("Percentual variation on exchange rate by country")
st.write(world_map_inflation)
st.info("Countries with highest variation on exchange rate:")
top_variation_pct = top_variation_value(10, "pct")
st.table(top_variation_pct)
try:
for index, country in enumerate(country_selection):
currency_code = map_country(df_country, country)
last_exchange_rate, pct_delta, metric_volume_btc = metrics(df_market, currency_code )
dollar_big_mac, date = big_mac_exchange_rate(country)
if (index == 0):
with column_1:
st.metric("Implicit Exchange rate",
f"{last_exchange_rate}"+' ' + currency_code+"/USD",
delta = pct_delta,
delta_color= "off" )
st.metric("BTC traded today", metric_volume_btc)
with column_2:
st.metric(f"Dollar Big Mac *{date}*", dollar_big_mac)
graph_exchange = plot_exchange(df_market, currency_code )
graph_big_mac_ex = plot_big_mac(df_big_mac,"dollar_ex", country)
graph_big_mac = plot_big_mac(df_big_mac,"dollar_price", country)
else:
add_trace_exchange(df_market,currency_code, graph_exchange )
add_trace_big_mac(df_big_mac,"dollar_ex", country, graph_big_mac_ex)
add_trace_big_mac(df_big_mac,"dollar_price", country, graph_big_mac)
### Update layout
update_layout(graph_exchange,
"Implicit exhange rate", "time",
"% Variation", "Currency code")
update_layout(graph_big_mac,
"USD to buy a Big Mac", "time",
"USD Price","Country")
update_layout(graph_big_mac_ex,
"Historical exhange rate", "time",
"Exchange rate", "Currency code")
### Implicit exchange rate:
st.write(graph_exchange)
### Complementary metrics:
average, max, min = summary_metrics(df_market, currency_code)
if average > 0:
st.error(f" The {currency_code} has been devalued in average by {round(average,2)}%")
else:
st.info(f"{currency_code} has been appreciated by {abs(round(average,2))}% relative to the USD")
### Big Mac visuals:
st.write(graph_big_mac_ex)
st.write(graph_big_mac)
except:
print('Waiting for country selection')