Spaces:
Sleeping
Sleeping
Manus commited on
Commit ·
a215e8b
1
Parent(s): a09885b
Fix indentation error in plot.py
Browse files
app.py
CHANGED
|
@@ -33,10 +33,10 @@ def sentiment_analysis(ticker, start_date, end_date, api_key):
|
|
| 33 |
start = pd.to_datetime(start_date)
|
| 34 |
end = pd.to_datetime(end_date)
|
| 35 |
articles = newsapi.get_everything(
|
| 36 |
-
q=ticker, from_param=start.strftime(
|
| 37 |
-
language=
|
| 38 |
)
|
| 39 |
-
sentiments = [analyzer.polarity_scores(article[
|
| 40 |
avg_sentiment = np.mean(sentiments) if sentiments else 0.0
|
| 41 |
sentiment_text = f"Average sentiment for {ticker}: {avg_sentiment:.2f}"
|
| 42 |
return sentiment_text, avg_sentiment
|
|
@@ -45,9 +45,9 @@ def sentiment_analysis(ticker, start_date, end_date, api_key):
|
|
| 45 |
return f"Sentiment analysis failed: {str(e)}", None
|
| 46 |
|
| 47 |
def update_horizon_label(timeframe):
|
| 48 |
-
units = {
|
| 49 |
-
|
| 50 |
-
return gr.update(label=f"Horizon ({units.get(timeframe,
|
| 51 |
|
| 52 |
def run_dashboard(data_src, ticker, file_upload, timeframe, start_date, end_date, horizon, indicators,
|
| 53 |
include_sentiment, news_api_key, alpha_api_key, account_size, risk_percent, model,
|
|
|
|
| 33 |
start = pd.to_datetime(start_date)
|
| 34 |
end = pd.to_datetime(end_date)
|
| 35 |
articles = newsapi.get_everything(
|
| 36 |
+
q=ticker, from_param=start.strftime("%Y-%m-%d"), to=end.strftime("%Y-%m-%d"),
|
| 37 |
+
language='en', sort_by='relevancy'
|
| 38 |
)
|
| 39 |
+
sentiments = [analyzer.polarity_scores(article["title"])["compound"] for article in articles["articles"]]
|
| 40 |
avg_sentiment = np.mean(sentiments) if sentiments else 0.0
|
| 41 |
sentiment_text = f"Average sentiment for {ticker}: {avg_sentiment:.2f}"
|
| 42 |
return sentiment_text, avg_sentiment
|
|
|
|
| 45 |
return f"Sentiment analysis failed: {str(e)}", None
|
| 46 |
|
| 47 |
def update_horizon_label(timeframe):
|
| 48 |
+
units = {'1m': 'minutes', '5m': 'minutes', '15m': 'minutes', '30m': 'minutes',
|
| 49 |
+
'1h': 'hours', '4h': 'hours', '1d': 'days', '1wk': 'weeks'}
|
| 50 |
+
return gr.update(label=f"Horizon ({units.get(timeframe, 'days')})")
|
| 51 |
|
| 52 |
def run_dashboard(data_src, ticker, file_upload, timeframe, start_date, end_date, horizon, indicators,
|
| 53 |
include_sentiment, news_api_key, alpha_api_key, account_size, risk_percent, model,
|