Spaces:
Runtime error
Runtime error
Update README.md
Browse files
README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
emoji: 👁
|
4 |
colorFrom: pink
|
5 |
colorTo: pink
|
@@ -10,4 +10,66 @@ pinned: false
|
|
10 |
license: apache-2.0
|
11 |
---
|
12 |
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
+
title: Financial Market Risk Assessment
|
3 |
emoji: 👁
|
4 |
colorFrom: pink
|
5 |
colorTo: pink
|
|
|
10 |
license: apache-2.0
|
11 |
---
|
12 |
|
13 |
+
<img src="images/icon.webp" width="100" alt="alt text">
|
14 |
+
|
15 |
+
# Financial Market Risk Assessment
|
16 |
+
This project aims to cluster stocks from stock market indexes based on their beta (risk) and R-squared values (dependency on the market) in order to asses risks for investment portfolios.
|
17 |
+
|
18 |
+
The script fetches historical stock data from Yahoo Finance (a default period of five years), calculates the beta and R-squared for each stock against the S&P 500 index, and performs clustering using the Gaussian Mixture Model (GMM).
|
19 |
+
|
20 |
+
## Beta and R-Squared in Finance
|
21 |
+
|
22 |
+
### Beta
|
23 |
+
Beta is a measure of a stock's volatility in relation to the overall market. It indicates how sensitive a stock's price is to market movements.
|
24 |
+
* β = 1: Indicates that the stock's price will move with the market.
|
25 |
+
* β < 1: Indicates that the stock is less volatile than the market.
|
26 |
+
* β > 1: Indicates that the stock is more volatile than the market.
|
27 |
+
* β = 0: Indicates that the stock's price is not correlated with the market.
|
28 |
+
* Negative β: Indicates that the stock moves inversely to the market.
|
29 |
+
|
30 |
+
### R-Squared
|
31 |
+
In the context of finance, R-squared is often used to evaluate how well a stock's price movements can be explained by the movements of the overall market. A higher R-squared value indicates a stronger relationship between the stock and the market.
|
32 |
+
|
33 |
+
* R² = 1: This indicates a perfect linear relationship between the stock and the market. All of the stock's price movements can be explained by the market's movements.
|
34 |
+
* R² = 0.5: This suggests that 50% of the stock's price movements can be explained by the market's movements, while the remaining 50% is due to other factors.
|
35 |
+
* R² = 0.25: This indicates that only 25% of the stock's price movements can be explained by the market's movements, while the remaining 75% is attributed to other factors.
|
36 |
+
* R² = 0: This suggests that none of the stock's price movements can be explained by the market's movements. The stock's price movements are entirely independent of the market.
|
37 |
+
|
38 |
+
## Gaussian Mixture Model (GMM)
|
39 |
+
Gaussian Mixture Model (GMM) is a probabilistic model that assumes the data is generated from a mixture of a finite number of Gaussian distributions. It is commonly used for clustering tasks, where the goal is to group similar data points together based on their underlying probability distributions.
|
40 |
+
|
41 |
+
The optimal number of clusters can be determined using the Bayesian Information Criterion (BIC), as it balance the goodness of fit with the complexity of the model, helping to avoid overfitting or underfitting.
|
42 |
+
|
43 |
+
## Results
|
44 |
+
|
45 |
+
The script generates a scatter plot showing the clustered stocks based on their beta and R-squared values. Each cluster is represented by a different color, and the size of each point indicates the latest close price of the stock.
|
46 |
+
|
47 |
+
## S&P500
|
48 |
+
<img src="images/SP500_BIC.png" width="500" alt="alt text">
|
49 |
+
<img src="images/SP500_example.png" width="850" alt="alt text">
|
50 |
+
|
51 |
+
## TASE
|
52 |
+
<img src="images/TASE_BIC.png" width="500" alt="alt text">
|
53 |
+
<img src="images/TASE_example.png" width="850" alt="alt text">
|
54 |
+
|
55 |
+
## Dependencies
|
56 |
+
|
57 |
+
You can install these dependencies using pip:
|
58 |
+
|
59 |
+
```
|
60 |
+
pip install pandas numpy tqdm scikit-learn plotly matplotlib yfinance
|
61 |
+
```
|
62 |
+
|
63 |
+
## Usage
|
64 |
+
|
65 |
+
### S&P 500 Stocks
|
66 |
+
|
67 |
+
```
|
68 |
+
python Stocks_Risk_Clustering_SP500.py
|
69 |
+
```
|
70 |
+
|
71 |
+
### TASE Stocks
|
72 |
+
|
73 |
+
```
|
74 |
+
python Stocks_Risk_Clustering_TASE.py
|
75 |
+
```
|