bintangyosua commited on
Commit
9128e73
1 Parent(s): 5b64167

Update multi_crypto.py

Browse files
Files changed (1) hide show
  1. multi_crypto.py +197 -197
multi_crypto.py CHANGED
@@ -1,197 +1,197 @@
1
- import marimo
2
-
3
- __generated_with = "0.9.15"
4
- app = marimo.App(width="full")
5
-
6
-
7
- @app.cell(hide_code=True)
8
- def __(mo):
9
- mo.md(r"""# Cryptocurrency Minuet Dashboard""")
10
- return
11
-
12
-
13
- @app.cell(hide_code=True)
14
- def __():
15
- import marimo as mo
16
- import pandas as pd
17
- import numpy as np
18
- import matplotlib.pyplot as plt
19
- import seaborn as sns
20
- import yfinance as yf
21
- import mplfinance as mpf
22
- import altair as alt
23
- from datetime import date, timedelta, datetime
24
- import pytz
25
-
26
- from sklearn.preprocessing import MinMaxScaler
27
- return (
28
- MinMaxScaler,
29
- alt,
30
- date,
31
- datetime,
32
- mo,
33
- mpf,
34
- np,
35
- pd,
36
- plt,
37
- pytz,
38
- sns,
39
- timedelta,
40
- yf,
41
- )
42
-
43
-
44
- @app.cell(hide_code=True)
45
- def __(datetime, mo):
46
- start_date_input = mo.ui.date(value=datetime.now().date())
47
-
48
- mo.md('## Input')
49
- return (start_date_input,)
50
-
51
-
52
- @app.cell(hide_code=True)
53
- def __(mo, start_date_input):
54
-
55
- mo.md(f"""
56
- Please enter yout start date range: {start_date_input}
57
- """)
58
- return
59
-
60
-
61
- @app.cell(hide_code=True)
62
- def __(datetime, pd, pytz, start_date_input, yf):
63
- tickers = [f'{ticker}-USD' for ticker in [
64
- 'BTC', 'ETH', 'AR', 'SOL', 'ADA', 'XMR',
65
- 'DOGE', 'SHIB', 'PEPE24478', 'BNB', 'AVAX',
66
- ]]
67
-
68
- # Mendapatkan waktu saat ini (jam, menit, detik)
69
- current_time = datetime.now().time()
70
-
71
- print(f'current time: {current_time}')
72
-
73
- # Menggabungkan tanggal dari input dengan waktu sekarang
74
- now = datetime.combine(start_date_input.value, current_time)
75
-
76
- # Menambahkan zona waktu UTC
77
- now = now.replace(tzinfo=pytz.UTC)
78
-
79
- # Mendapatkan tanggal untuk start_date (menggunakan tanggal input)
80
- start_date = start_date_input.value.strftime('%Y-%m-%d')
81
-
82
- # Mendapatkan data dari Yahoo Finance
83
- data = yf.download(tickers, start=start_date, interval='5m')
84
-
85
- # Mengonversi index ke datetime dan mengubah zona waktunya ke UTC
86
- data.index = pd.to_datetime(data.index).tz_convert('UTC')
87
-
88
- # Memfilter data untuk hanya yang sebelum waktu sekarang
89
- data = data[data.index > now]
90
-
91
- # Mengambil harga penutupan
92
- closes = data['Close']
93
- return closes, current_time, data, now, start_date, tickers
94
-
95
-
96
- @app.cell
97
- def __(closes):
98
- closes
99
- return
100
-
101
-
102
- @app.cell(hide_code=True)
103
- def __(closes):
104
- highest_percentage_change = {}
105
- for ticker in closes.columns:
106
- # Group by day and calculate min and max within the day
107
- daily_high = closes[ticker].resample('D').max()
108
- daily_low = closes[ticker].resample('D').min()
109
- # Calculate percentage change
110
- daily_percentage_change = ((daily_high - daily_low) / daily_low) * 100
111
- # Get the highest percentage change within the day
112
- highest_percentage_change[ticker] = daily_percentage_change.max()
113
- return (
114
- daily_high,
115
- daily_low,
116
- daily_percentage_change,
117
- highest_percentage_change,
118
- ticker,
119
- )
120
-
121
-
122
- @app.cell(hide_code=True)
123
- def __(mo):
124
- mo.md("""## Highest Returns in the since Yesterday""")
125
- return
126
-
127
-
128
- @app.cell(hide_code=True)
129
- def __(highest_percentage_change, pd):
130
- def show_highest_percentage(ticker):
131
- percentage = highest_percentage_change[ticker]
132
- return percentage
133
-
134
- def percentage_to_text(percentage):
135
- return '%.2f%%' % percentage if percentage is not None else 'N/A'
136
-
137
- # Calculate and sort percentage changes
138
- highest_percentage_sorted = sorted(highest_percentage_change.items(), key=lambda x: x[1], reverse=True)
139
- highest, second_highest = highest_percentage_sorted[0], highest_percentage_sorted[1]
140
- lowest, second_lowest = highest_percentage_sorted[-1], highest_percentage_sorted[-2]
141
-
142
- # Calculate and sort percentage changes
143
- # Urutkan berdasarkan persentase, hasilkan tuple (ticker, persentase)
144
- highest_percentage_sorted = sorted(highest_percentage_change.items(), key=lambda x: x[1], reverse=True)
145
-
146
- # Pisahkan ticker dan persentase yang sudah diurutkan
147
- sorted_tickers = [ticker for ticker, _ in highest_percentage_sorted]
148
- sorted_percentages = [percentage_to_text(percentage) for _, percentage in highest_percentage_sorted]
149
-
150
- # Membuat DataFrame dengan kolom yang sudah sesuai
151
- highest_percentage = pd.DataFrame(
152
- {
153
- 'Ticker': sorted_tickers,
154
- 'Percentage': sorted_percentages
155
- }
156
- )
157
- return (
158
- highest,
159
- highest_percentage,
160
- highest_percentage_sorted,
161
- lowest,
162
- percentage_to_text,
163
- second_highest,
164
- second_lowest,
165
- show_highest_percentage,
166
- sorted_percentages,
167
- sorted_tickers,
168
- )
169
-
170
-
171
- @app.cell(hide_code=True)
172
- def __(
173
- highest,
174
- highest_percentage,
175
- lowest,
176
- mo,
177
- second_highest,
178
- second_lowest,
179
- ):
180
- mo.vstack([
181
- mo.md(f"""
182
- ### Overview of Highest and Lowest Daily Percentage Changes
183
- The **highest daily percentage change** was recorded by `{highest[0]}` at {highest[1]:.2f}%. The **second highest** was `{second_highest[0]}` with a change of {second_highest[1]:.2f}%.
184
- The **lowest daily percentage change** occurred for `{lowest[0]}` at {lowest[1]:.2f}%. The **second lowest** was `{second_lowest[0]}` with a change of {second_lowest[1]:.2f}%.
185
- """),
186
- highest_percentage
187
- ])
188
- return
189
-
190
-
191
- @app.cell
192
- def __():
193
- return
194
-
195
-
196
- if __name__ == "__main__":
197
- app.run()
 
1
+ import marimo
2
+
3
+ __generated_with = "0.9.15"
4
+ app = marimo.App(width="full")
5
+
6
+
7
+ @app.cell(hide_code=True)
8
+ def __(mo):
9
+ mo.md(r"""# Cryptocurrency Minuet Dashboard""")
10
+ return
11
+
12
+
13
+ @app.cell(hide_code=True)
14
+ def __():
15
+ import marimo as mo
16
+ import pandas as pd
17
+ import numpy as np
18
+ import matplotlib.pyplot as plt
19
+ import seaborn as sns
20
+ import yfinance as yf
21
+ import mplfinance as mpf
22
+ import altair as alt
23
+ from datetime import date, timedelta, datetime
24
+ import pytz
25
+
26
+ from sklearn.preprocessing import MinMaxScaler
27
+ return (
28
+ MinMaxScaler,
29
+ alt,
30
+ date,
31
+ datetime,
32
+ mo,
33
+ mpf,
34
+ np,
35
+ pd,
36
+ plt,
37
+ pytz,
38
+ sns,
39
+ timedelta,
40
+ yf,
41
+ )
42
+
43
+
44
+ @app.cell(hide_code=True)
45
+ def __(datetime, mo):
46
+ start_date_input = mo.ui.date(value=(datetime.now() - timedelta(days=1)).date())
47
+
48
+ mo.md('## Input')
49
+ return (start_date_input,)
50
+
51
+
52
+ @app.cell(hide_code=True)
53
+ def __(mo, start_date_input):
54
+
55
+ mo.md(f"""
56
+ Please enter yout start date range: {start_date_input}
57
+ """)
58
+ return
59
+
60
+
61
+ @app.cell(hide_code=True)
62
+ def __(datetime, pd, pytz, start_date_input, yf):
63
+ tickers = [f'{ticker}-USD' for ticker in [
64
+ 'BTC', 'ETH', 'AR', 'SOL', 'ADA', 'XMR',
65
+ 'DOGE', 'SHIB', 'PEPE24478', 'BNB', 'AVAX',
66
+ ]]
67
+
68
+ # Mendapatkan waktu saat ini (jam, menit, detik)
69
+ current_time = datetime.now().time()
70
+
71
+ print(f'current time: {current_time}')
72
+
73
+ # Menggabungkan tanggal dari input dengan waktu sekarang
74
+ now = datetime.combine(start_date_input.value, current_time)
75
+
76
+ # Menambahkan zona waktu UTC
77
+ now = now.replace(tzinfo=pytz.UTC)
78
+
79
+ # Mendapatkan tanggal untuk start_date (menggunakan tanggal input)
80
+ start_date = start_date_input.value.strftime('%Y-%m-%d')
81
+
82
+ # Mendapatkan data dari Yahoo Finance
83
+ data = yf.download(tickers, start=start_date, interval='5m')
84
+
85
+ # Mengonversi index ke datetime dan mengubah zona waktunya ke UTC
86
+ data.index = pd.to_datetime(data.index).tz_convert('UTC')
87
+
88
+ # Memfilter data untuk hanya yang sebelum waktu sekarang
89
+ data = data[data.index > now]
90
+
91
+ # Mengambil harga penutupan
92
+ closes = data['Close']
93
+ return closes, current_time, data, now, start_date, tickers
94
+
95
+
96
+ @app.cell
97
+ def __(closes):
98
+ closes
99
+ return
100
+
101
+
102
+ @app.cell(hide_code=True)
103
+ def __(closes):
104
+ highest_percentage_change = {}
105
+ for ticker in closes.columns:
106
+ # Group by day and calculate min and max within the day
107
+ daily_high = closes[ticker].resample('D').max()
108
+ daily_low = closes[ticker].resample('D').min()
109
+ # Calculate percentage change
110
+ daily_percentage_change = ((daily_high - daily_low) / daily_low) * 100
111
+ # Get the highest percentage change within the day
112
+ highest_percentage_change[ticker] = daily_percentage_change.max()
113
+ return (
114
+ daily_high,
115
+ daily_low,
116
+ daily_percentage_change,
117
+ highest_percentage_change,
118
+ ticker,
119
+ )
120
+
121
+
122
+ @app.cell(hide_code=True)
123
+ def __(mo):
124
+ mo.md("""## Highest Returns in the since Yesterday""")
125
+ return
126
+
127
+
128
+ @app.cell(hide_code=True)
129
+ def __(highest_percentage_change, pd):
130
+ def show_highest_percentage(ticker):
131
+ percentage = highest_percentage_change[ticker]
132
+ return percentage
133
+
134
+ def percentage_to_text(percentage):
135
+ return '%.2f%%' % percentage if percentage is not None else 'N/A'
136
+
137
+ # Calculate and sort percentage changes
138
+ highest_percentage_sorted = sorted(highest_percentage_change.items(), key=lambda x: x[1], reverse=True)
139
+ highest, second_highest = highest_percentage_sorted[0], highest_percentage_sorted[1]
140
+ lowest, second_lowest = highest_percentage_sorted[-1], highest_percentage_sorted[-2]
141
+
142
+ # Calculate and sort percentage changes
143
+ # Urutkan berdasarkan persentase, hasilkan tuple (ticker, persentase)
144
+ highest_percentage_sorted = sorted(highest_percentage_change.items(), key=lambda x: x[1], reverse=True)
145
+
146
+ # Pisahkan ticker dan persentase yang sudah diurutkan
147
+ sorted_tickers = [ticker for ticker, _ in highest_percentage_sorted]
148
+ sorted_percentages = [percentage_to_text(percentage) for _, percentage in highest_percentage_sorted]
149
+
150
+ # Membuat DataFrame dengan kolom yang sudah sesuai
151
+ highest_percentage = pd.DataFrame(
152
+ {
153
+ 'Ticker': sorted_tickers,
154
+ 'Percentage': sorted_percentages
155
+ }
156
+ )
157
+ return (
158
+ highest,
159
+ highest_percentage,
160
+ highest_percentage_sorted,
161
+ lowest,
162
+ percentage_to_text,
163
+ second_highest,
164
+ second_lowest,
165
+ show_highest_percentage,
166
+ sorted_percentages,
167
+ sorted_tickers,
168
+ )
169
+
170
+
171
+ @app.cell(hide_code=True)
172
+ def __(
173
+ highest,
174
+ highest_percentage,
175
+ lowest,
176
+ mo,
177
+ second_highest,
178
+ second_lowest,
179
+ ):
180
+ mo.vstack([
181
+ mo.md(f"""
182
+ ### Overview of Highest and Lowest Daily Percentage Changes
183
+ The **highest daily percentage change** was recorded by `{highest[0]}` at {highest[1]:.2f}%. The **second highest** was `{second_highest[0]}` with a change of {second_highest[1]:.2f}%.
184
+ The **lowest daily percentage change** occurred for `{lowest[0]}` at {lowest[1]:.2f}%. The **second lowest** was `{second_lowest[0]}` with a change of {second_lowest[1]:.2f}%.
185
+ """),
186
+ highest_percentage
187
+ ])
188
+ return
189
+
190
+
191
+ @app.cell
192
+ def __():
193
+ return
194
+
195
+
196
+ if __name__ == "__main__":
197
+ app.run()