Spaces:
Running
Running
bintangyosua
commited on
Commit
β’
ccd9626
1
Parent(s):
cdab96c
Upload 7 files
Browse files- Dockerfile +16 -0
- README.md +45 -12
- __pycache__/btc.cpython-311.pyc +0 -0
- __pycache__/multi_crypto.cpython-311.pyc +0 -0
- development.md +8 -0
- multi_crypto.py +186 -0
- requirements.txt +9 -0
Dockerfile
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.11.4
|
2 |
+
COPY --from=ghcr.io/astral-sh/uv:0.4.20 /uv /bin/uv
|
3 |
+
|
4 |
+
RUN useradd -m -u 1000 user
|
5 |
+
ENV PATH="/home/user/.local/bin:$PATH"
|
6 |
+
ENV UV_SYSTEM_PYTHON=1
|
7 |
+
|
8 |
+
WORKDIR /app
|
9 |
+
|
10 |
+
COPY --chown=user ./requirements.txt requirements.txt
|
11 |
+
RUN uv pip install -r requirements.txt
|
12 |
+
|
13 |
+
COPY --chown=user . /app
|
14 |
+
USER user
|
15 |
+
|
16 |
+
CMD ["marimo", "run", "multi_crypto.py", "--include-code", "--host", "0.0.0.0", "--port", "7860"]
|
README.md
CHANGED
@@ -1,12 +1,45 @@
|
|
1 |
-
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
-
colorFrom: indigo
|
5 |
-
colorTo:
|
6 |
-
sdk: docker
|
7 |
-
pinned:
|
8 |
-
license: mit
|
9 |
-
short_description:
|
10 |
-
---
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Political Ideologies Analysis and Classification
|
3 |
+
emoji: π
|
4 |
+
colorFrom: indigo
|
5 |
+
colorTo: purple
|
6 |
+
sdk: docker
|
7 |
+
pinned: true
|
8 |
+
license: mit
|
9 |
+
short_description: Analysis and Classification
|
10 |
+
---
|
11 |
+
|
12 |
+
# Political Ideologies Analysis
|
13 |
+
|
14 |
+
This project provides a comprehensive analysis of political ideologies using data from the Huggingface Political Ideologies dataset. The analysis involves data preprocessing, mapping ideological labels, and visualizing political statements through Word2Vec embeddings and t-SNE projections. Additionally, an interactive tool is created for exploring political ideologies and their related issue types in a 2D space.
|
15 |
+
|
16 |
+
## Project Overview
|
17 |
+
|
18 |
+
The goal of this project is to analyze the political ideologies dataset to understand the distribution of political ideologies (conservative vs liberal) and their association with various issue types. The analysis involves:
|
19 |
+
|
20 |
+
- **Data Loading and Cleaning**: Loading, cleaning, and mapping data from the Huggingface dataset.
|
21 |
+
- **Label Mapping**: Mapping ideological labels (conservative and liberal) and issue types to numerical values.
|
22 |
+
- **Word2Vec Embeddings**: Generating word embeddings for political statements to create vector representations.
|
23 |
+
- **Dimensionality Reduction**: Using t-SNE to reduce the dimensionality of embeddings and visualize them in 2D.
|
24 |
+
- **Interactive Visualizations**: Visualizing the data using Altair with interactive charts to explore ideology and issue type distributions.
|
25 |
+
|
26 |
+
## Dataset
|
27 |
+
|
28 |
+
The dataset used in this project is the [Political Ideologies dataset](https://huggingface.co/datasets/JyotiNayak/political_ideologies) from Huggingface, which contains political statements along with their corresponding labels (conservative or liberal) and issue types (economic, environmental, social, etc.).
|
29 |
+
|
30 |
+
## Requirements
|
31 |
+
|
32 |
+
- Python 3.x
|
33 |
+
- TensorFlow
|
34 |
+
- Gensim
|
35 |
+
- Pandas
|
36 |
+
- NumPy
|
37 |
+
- Matplotlib
|
38 |
+
- Seaborn
|
39 |
+
- Altair
|
40 |
+
|
41 |
+
You can install the necessary dependencies with:
|
42 |
+
|
43 |
+
```bash
|
44 |
+
pip install -r requirements.txt
|
45 |
+
```
|
__pycache__/btc.cpython-311.pyc
ADDED
Binary file (15.3 kB). View file
|
|
__pycache__/multi_crypto.cpython-311.pyc
ADDED
Binary file (9.97 kB). View file
|
|
development.md
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Development
|
2 |
+
|
3 |
+
## Testing your Dockerfile locally
|
4 |
+
|
5 |
+
```bash
|
6 |
+
docker build -t marimo-app .
|
7 |
+
docker run -it --rm -p 7860:7860 marimo-app
|
8 |
+
```
|
multi_crypto.py
ADDED
@@ -0,0 +1,186 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import marimo
|
2 |
+
|
3 |
+
__generated_with = "0.9.15"
|
4 |
+
app = marimo.App(width="medium")
|
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 |
+
|
25 |
+
from sklearn.preprocessing import MinMaxScaler
|
26 |
+
return (
|
27 |
+
MinMaxScaler,
|
28 |
+
alt,
|
29 |
+
date,
|
30 |
+
datetime,
|
31 |
+
mo,
|
32 |
+
mpf,
|
33 |
+
np,
|
34 |
+
pd,
|
35 |
+
plt,
|
36 |
+
sns,
|
37 |
+
timedelta,
|
38 |
+
yf,
|
39 |
+
)
|
40 |
+
|
41 |
+
|
42 |
+
@app.cell(hide_code=True)
|
43 |
+
def __(datetime, timedelta, yf):
|
44 |
+
tickers = [f'{ticker}-USD' for ticker in [
|
45 |
+
'BTC', 'ETH', 'AR', 'SOL', 'ADA', 'XMR',
|
46 |
+
'DOGE', 'SHIB', 'PEPE24478', 'BNB', 'AVAX',
|
47 |
+
]]
|
48 |
+
yesterday = (datetime.now() - timedelta(days=1)).strftime('%Y-%m-%d')
|
49 |
+
data = yf.download(tickers, start=yesterday, interval='5m')
|
50 |
+
closes = data['Close']
|
51 |
+
return closes, data, tickers, yesterday
|
52 |
+
|
53 |
+
|
54 |
+
@app.cell(hide_code=True)
|
55 |
+
def __(closes):
|
56 |
+
highest_percentage_change = {}
|
57 |
+
for ticker in closes.columns:
|
58 |
+
# Group by day and calculate min and max within the day
|
59 |
+
daily_high = closes[ticker].resample('D').max()
|
60 |
+
daily_low = closes[ticker].resample('D').min()
|
61 |
+
# Calculate percentage change
|
62 |
+
daily_percentage_change = ((daily_high - daily_low) / daily_low) * 100
|
63 |
+
# Get the highest percentage change within the day
|
64 |
+
highest_percentage_change[ticker] = daily_percentage_change.max()
|
65 |
+
return (
|
66 |
+
daily_high,
|
67 |
+
daily_low,
|
68 |
+
daily_percentage_change,
|
69 |
+
highest_percentage_change,
|
70 |
+
ticker,
|
71 |
+
)
|
72 |
+
|
73 |
+
|
74 |
+
@app.cell(hide_code=True)
|
75 |
+
def __(mo):
|
76 |
+
mo.md("""## Highest Returns in the since Yesterday""")
|
77 |
+
return
|
78 |
+
|
79 |
+
|
80 |
+
@app.cell(hide_code=True)
|
81 |
+
def __(highest_percentage_change, mo, tickers):
|
82 |
+
def show_highest_percentage(ticker):
|
83 |
+
percentage = highest_percentage_change[ticker]
|
84 |
+
up = 'success' if percentage > 0 else 'danger'
|
85 |
+
percentage_text = '%.2f%%' % percentage if percentage is not None else 'N/A'
|
86 |
+
return mo.callout(value=f'{ticker} {percentage_text}', kind=up)
|
87 |
+
|
88 |
+
# Calculate and sort percentage changes
|
89 |
+
highest_percentage_sorted = sorted(highest_percentage_change.items(), key=lambda x: x[1], reverse=True)
|
90 |
+
highest, second_highest = highest_percentage_sorted[0], highest_percentage_sorted[1]
|
91 |
+
lowest, second_lowest = highest_percentage_sorted[-1], highest_percentage_sorted[-2]
|
92 |
+
|
93 |
+
# Generate markdown explanations
|
94 |
+
callouts_length = int(len(tickers) / 2)
|
95 |
+
top_callout = mo.md(f"""
|
96 |
+
### Overview of Highest and Lowest Daily Percentage Changes
|
97 |
+
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}%.
|
98 |
+
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}%.
|
99 |
+
""")
|
100 |
+
|
101 |
+
callouts_top = mo.hstack([show_highest_percentage(ticker) for ticker in tickers[:callouts_length]])
|
102 |
+
|
103 |
+
callouts_bottom = mo.hstack([show_highest_percentage(ticker) for ticker in tickers[callouts_length:]])
|
104 |
+
|
105 |
+
# mo.vstack([top_callout, callouts_top, callouts_bottom], align='start', heights='equal')
|
106 |
+
return (
|
107 |
+
callouts_bottom,
|
108 |
+
callouts_length,
|
109 |
+
callouts_top,
|
110 |
+
highest,
|
111 |
+
highest_percentage_sorted,
|
112 |
+
lowest,
|
113 |
+
second_highest,
|
114 |
+
second_lowest,
|
115 |
+
show_highest_percentage,
|
116 |
+
top_callout,
|
117 |
+
)
|
118 |
+
|
119 |
+
|
120 |
+
@app.cell(hide_code=True)
|
121 |
+
def __(top_callout):
|
122 |
+
top_callout
|
123 |
+
return
|
124 |
+
|
125 |
+
|
126 |
+
@app.cell(hide_code=True)
|
127 |
+
def __(callouts_top):
|
128 |
+
callouts_top
|
129 |
+
return
|
130 |
+
|
131 |
+
|
132 |
+
@app.cell(hide_code=True)
|
133 |
+
def __(callouts_bottom):
|
134 |
+
callouts_bottom
|
135 |
+
return
|
136 |
+
|
137 |
+
|
138 |
+
@app.cell(hide_code=True)
|
139 |
+
def __(mo):
|
140 |
+
mo.md(r"""## Log Returns Correlation""")
|
141 |
+
return
|
142 |
+
|
143 |
+
|
144 |
+
@app.cell(hide_code=True)
|
145 |
+
def __(closes, mo, np):
|
146 |
+
# Calculate log returns and correlation matrix
|
147 |
+
log_returns = np.log(closes / closes.shift(1))
|
148 |
+
correlation_matrix = log_returns.corr()
|
149 |
+
|
150 |
+
# Identify the highest and lowest correlations
|
151 |
+
highest_corr = correlation_matrix.unstack().sort_values(ascending=False).drop_duplicates().iloc[1]
|
152 |
+
lowest_corr = correlation_matrix.unstack().sort_values().drop_duplicates().iloc[0]
|
153 |
+
|
154 |
+
mo.md(f"""
|
155 |
+
### Highest Correlation\n\nThe highest correlation is between `{highest_corr}` and `{highest_corr}` with a value of **{highest_corr:.2f}**, indicating a strong positive relationship. This suggests that these two assets move similarly over the selected period.\n
|
156 |
+
### Lowest Correlation\n\nThe lowest correlation is between `{lowest_corr}` and `{lowest_corr}` with a value of **{lowest_corr:.2f}**, indicating a weak or almost no relationship. These assets may provide diversification benefits in a portfolio.
|
157 |
+
|
158 |
+
### Additional Insights
|
159 |
+
|
160 |
+
- **High Positive Correlations**: Assets with high correlations tend to respond similarly to market events, which can be useful for **trend-following strategies**.
|
161 |
+
- **Low or Negative Correlations**: Assets with low or negative correlations might help reduce overall portfolio risk, making them useful for **diversification**.
|
162 |
+
- **Portfolio Strategy**: If you're seeking to **balance risk**, consider assets with lower correlations, while highly correlated assets can be beneficial for **momentum-based** portfolios.
|
163 |
+
""")
|
164 |
+
return correlation_matrix, highest_corr, log_returns, lowest_corr
|
165 |
+
|
166 |
+
|
167 |
+
@app.cell
|
168 |
+
def __(log_returns, plt, sns):
|
169 |
+
plt.figure(figsize=(6, 5))
|
170 |
+
sns.heatmap(log_returns.corr(), cmap="YlGnBu", annot=True)
|
171 |
+
plt.gca()
|
172 |
+
return
|
173 |
+
|
174 |
+
|
175 |
+
@app.cell
|
176 |
+
def __():
|
177 |
+
return
|
178 |
+
|
179 |
+
|
180 |
+
@app.cell
|
181 |
+
def __():
|
182 |
+
return
|
183 |
+
|
184 |
+
|
185 |
+
if __name__ == "__main__":
|
186 |
+
app.run()
|
requirements.txt
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
altair==5.4.1
|
2 |
+
marimo==0.9.18
|
3 |
+
matplotlib==3.7.1
|
4 |
+
mplfinance==0.12.10b0
|
5 |
+
numpy==1.24.2
|
6 |
+
pandas==1.5.3
|
7 |
+
scikit_learn==1.2.2
|
8 |
+
seaborn==0.13.2
|
9 |
+
yfinance==0.2.49
|