-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upgraded Sentiment Analysis with Real-time Market Insights #28
base: main
Are you sure you want to change the base?
Conversation
Hello,
I tried to clone it and followed all the instructions, but it doesn't work.
Thank you!
Umer
…On Thu, Dec 26, 2024, 4:21 PM Jerry Buaba ***@***.***> wrote:
I've updated the sentiment analysis system to provide more comprehensive
market insights. The main improvements focus on news sentiment analysis,
working alongside the existing insider trading signals.
Key changes:
- Integrated NewsAPI to fetch real-time news articles about our target
companies
- Added company name resolution using yfinance for more accurate news
searching
- Expanded sentiment analysis to process all relevant articles from
the date range passed in the run command (default of 3 months might need a
higher tier news API key to fetch)
- Using GPT-4 to analyze news sentiment with a focus on market impact
- Combined news and insider trading signals (60/40 weight) for final
sentiment as insider trading sentiment is more concrete
The agent now looks at both insider trading patterns and broad market
sentiment from news, giving us a more complete picture. News analysis
focuses on concrete factors like revenue impact, market competition, and
product developments.
I've kept the original insider trading logic intact since it was working
well, just added the news layer on top of it. Happy to adjust the weights
or time window if we think it needs tuning.
sample sentiment analysis result:
========== Sentiment Analysis Agent ==========
{
"signal": "bearish",
"confidence": "60%",
"reasoning": {
"insider_sentiment": {
"signal": "bearish",
"confidence": "100%",
"bullish_trades": 0,
"bearish_trades": 4
},
"news_sentiment": {
"signal": "bullish",
"confidence": "68%",
"articles_analyzed": 2,
"key_points": [
"Apple's AI rollout is expected to drive demand for the iPhone 16, boosting revenue.",
"The article discusses AI chatbots selecting stocks, which doesn't directly impact company fundamentals.",
"No specific company or innovation/product development details were provided that could influence stock value.",
"The potential increase in market value to $4 trillion indicates strong investor confidence."
]
}
}
}
================================================
------------------------------
You can view, comment on, or merge this pull request online at:
#28
Commit Summary
- 5731b71
<5731b71>
adds sentiment analysis from news
File Changes
(5 files <https://github.com/virattt/ai-hedge-fund/pull/28/files>)
- *M* README.md
<https://github.com/virattt/ai-hedge-fund/pull/28/files#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5>
(3)
- *M* poetry.lock
<https://github.com/virattt/ai-hedge-fund/pull/28/files#diff-f53a023eedfa3fbf2925ec7dc76eecdc954ea94b7e47065393dbad519613dc89>
(319)
- *M* pyproject.toml
<https://github.com/virattt/ai-hedge-fund/pull/28/files#diff-50c86b7ed8ac2cf95bd48334961bf0530cdc77b5a56f852c5c61b89d735fd711>
(1)
- *M* src/agents/sentiment.py
<https://github.com/virattt/ai-hedge-fund/pull/28/files#diff-a64a10c31209ffbd704c09cef900b6b2058dedf0095ab3985c5f44ee81d9b253>
(214)
- *M* src/tools/api.py
<https://github.com/virattt/ai-hedge-fund/pull/28/files#diff-e20f3acd8c0a3a5f227c9942aa5333700a227afd267b10fe5a02495da8547856>
(37)
Patch Links:
- https://github.com/virattt/ai-hedge-fund/pull/28.patch
- https://github.com/virattt/ai-hedge-fund/pull/28.diff
—
Reply to this email directly, view it on GitHub
<#28>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AWPTXVZFGCMX4ANU3ZEQMB32HSMSJAVCNFSM6AAAAABUH3GVV6VHI2DSMVQWIX3LMV43ASLTON2WKOZSG43DAMRUGQ4TMOA>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
hi @umershahid84 thanks for trying this out. would you be kind enough to share what error message or logs you get that shows this doesn't work, please? as the only extra dependency added to this feature is yfinance, and should work as expected if you have all existing dependencies installed via off the top of my head, an issue you might encounter is a rate limit from the newsAPI if you have a free tier and try to get responses from over a month as the free tier API does not allow that. if this is the problem and you do have a free tier API from newsAPI, you can resolve this by running the tool with a specific date range command to ensure you are not hitting the rate limit. you can do this like: poetry run python src/main.py --ticker AAPL --start-date 2024-12-01 --end-date 2024-12-26 --show-reasoning this should fix the issue as this range is between the allowed range for the free tier. alternatively, you could let me know and I am more than happy to share an API key from my account as I have paid credits if you would like to test this for a much longer span, like the 3 month default if a date range is not specified. While this should resolve the issue, I am also open to modifying the code to always only query for the last month's worth of news so it is unaffected by whatever date range is being used to run the project as long as an API key for the newsAPI is provided. thanks |
Hello,
see below a screenshot.
[image: image.png]
Thank you!
Umer Shahid
…On Fri, Dec 27, 2024 at 2:13 AM Jerry Buaba ***@***.***> wrote:
hi @umershahid84 <https://github.com/umershahid84> thanks for trying this
out. would you be kind enough to share what error message or logs you get
that shows this doesn't work, please? as the only extra dependency added to
this feature is yfinance, and should work as expected if you have all
existing dependencies installed via poetry install.
off the top of my head, an issue you might encounter is a rate limit from
the newsAPI if you have a free tier and try to get responses from over a
month as the free tier API does not allow that.
if this is the problem and you do have a free tier API from newsAPI, you
can resolve this by running the tool with a specific date range command to
ensure you are not hitting the rate limit. you can do this like:
poetry run python src/main.py --ticker AAPL --start-date 2024-12-01 --end-date 2024-12-26 --show-reasoning
this should fix the issue as this range is between the allowed range for
the free tier. alternatively, you could let me know and I am more than
happy to share an API key from my account as I have paid credits if you
would like to test this for a much longer span, like the 3 month default if
a date range is not specified.
While this should resolve the issue, I am also open to modifying the code
to always only query for the last month's worth of news so it is unaffected
by whatever date range is being used to run the project as long as an API
key for the newsAPI is provided. thanks
—
Reply to this email directly, view it on GitHub
<#28 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AWPTXVY5GZU5AJ4AJXRFXDT2HUR3VAVCNFSM6AAAAABUH3GVV6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKNRTGU2DCNZQG4>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
@umershahid84 the image you attached seems to be attached improperly. |
This is a great addition, would be neat to additionally incorporate X data feeds for sentiment there as well as breaking news |
@vinniejames that sounds amazing and would be a neat addition but the X API is so expensive at $100/mo for a basic plan with 10k pulls per month. if @virattt gives the go ahead, I would be more than happy to add that! |
I think even 10k pulls/month is not enough to get a good understanding of market sentiment |
@virattt any chance this will be looked at? if there are no plans on adding something like this to the project, please feel free to let me know :) this is what an output currently looks like for running with reasoning: poetry run python src/main.py --ticker MSTR --start-date 2024-06-01 --end-date 2025-01-18 --show-reasoning
? Select your AI analysts. done (4 selections)
Selected analysts: Technical Analyst, Fundamentals Analyst, Sentiment Analyst, Valuation Analyst
========== Fundamental Analysis Agent ==========
{
"MSTR": {
"signal": "neutral",
"confidence": 25.0,
"reasoning": {
"profitability_signal": {
"signal": "bearish",
"details": "ROE: -14.60%, Net Margin: -87.00%, Op Margin: -194.94%"
},
"growth_signal": {
"signal": "neutral",
"details": "Revenue Growth: -2.79%, Earnings Growth: -93.69%"
},
"financial_health_signal": {
"signal": "neutral",
"details": "Current Ratio: 0.65, D/E: 1.21"
},
"price_ratios_signal": {
"signal": "bullish",
"details": "P/E: -80.55, P/B: 8.68, P/S: 70.12"
}
}
}
}
================================================
========== Technical Analyst ==========
{
"MSTR": {
"signal": "bullish",
"confidence": 55,
"strategy_signals": {
"trend_following": {
"signal": "bullish",
"confidence": 22,
"metrics": {
"adx": 21.51270550408803,
"trend_strength": 0.21512705504088028
}
},
"mean_reversion": {
"signal": "neutral",
"confidence": 50,
"metrics": {
"z_score": 0.8347289724883126,
"price_vs_bb": 1.0339300537585485,
"rsi_14": 60.63605324740093,
"rsi_28": 50.87719298245614
}
},
"momentum": {
"signal": "bullish",
"confidence": 100,
"metrics": {
"momentum_1m": 0.0244798701087523,
"momentum_3m": 0.8946524250356122,
"momentum_6m": 1.212044477017976,
"volume_momentum": 1.147511293360851
}
},
"volatility": {
"signal": "neutral",
"confidence": 50,
"metrics": {
"historical_volatility": 1.177242999205214,
"volatility_regime": 0.9971884739588139,
"volatility_z_score": -0.016163006457079663,
"atr_ratio": 0.07520807061790667
}
},
"statistical_arbitrage": {
"signal": "neutral",
"confidence": 50,
"metrics": {
"hurst_exponent": 4.4162737839765496e-15,
"skewness": 0.3850078148661564,
"kurtosis": 0.48159889181993865
}
}
}
}
}
================================================
========== Valuation Analysis Agent ==========
{
"MSTR": {
"signal": "bearish",
"confidence": 100.0,
"reasoning": {
"dcf_analysis": {
"signal": "bearish",
"details": "Intrinsic Value: $-36,235,027.64, Market Cap: $32,762,470,020.00, Gap: -100.1%"
},
"owner_earnings_analysis": {
"signal": "bearish",
"details": "Owner Earnings Value: $0.00, Market Cap: $32,762,470,020.00, Gap: -100.0%"
}
}
}
}
================================================
========== Sentiment Analysis Agent ==========
{
"MSTR": {
"signal": "bearish",
"confidence": 56.05,
"reasoning": {
"insider_sentiment": {
"signal": "bearish",
"confidence": 93.42,
"bullish_trades": 64,
"bearish_trades": 909
},
"news_sentiment": {
"signal": "neutral",
"confidence": 60.0,
"articles_analyzed": 5,
"key_points": [
"No direct information on revenue, competition, regulation, or innovation, hence neutral on stock price impact.",
"Increased stake by Salem Investment Counselors may indicate institutional confidence but does not directly impact competition or product
development.",
"Mentions of future rate cuts are noted but do not directly provide information on stock value impacts for MicroStrategy.",
"Continued emphasis on Bitcoin over core software operations may undermine traditional revenue streams.",
"No mention of revenue, profit, regulatory changes, or product innovations in the report affecting stock value.",
"Brookstone Capital Management's increase in holdings could signal confidence in MicroStrategy's future performance, potentially influencing other
investors.",
"Increase in institutional holdings by Wedmont Private Capital, indicating confidence but not directly linked to company's financial
performance.",
"MicroStrategy's financial focus on Bitcoin increases volatility risk due to cryptocurrency market fluctuations.",
"The article discusses MicroStrategy's position among growth stocks, but lacks specific information on revenue, competition, regulations, or
innovations."
]
}
}
}
}
================================================
========== Risk Management Agent ==========
{
"MSTR": {
"remaining_position_limit": 20000.0,
"current_price": 396.5,
"reasoning": {
"portfolio_value": 100000.0,
"current_position": 0.0,
"position_limit": 20000.0,
"remaining_limit": 20000.0,
"available_cash": 100000.0
}
}
}
================================================
========== Portfolio Management Agent ==========
{
"MSTR": {
"action": "hold",
"quantity": 0,
"confidence": 56.05,
"reasoning": "Despite the technical analyst's bullish signal with moderate confidence, the valuation and sentiment agents both indicate bearish signals
with high confidence. Given these mixed signals and the high bearish confidence from the valuation agent, I'll opt to hold this position rather than
initiating a buy."
}
}
================================================
✓ Fundamentals [MSTR] Done
✓ Sentiment [MSTR] Done
✓ Technical Analyst [MSTR] Done
✓ Valuation [MSTR] Done
✓ Risk Management [MSTR] Done
✓ Portfolio Management[MSTR] Done
Analysis for MSTR
==================================================
ANALYST SIGNALS: [MSTR]
+-------------------+----------+--------------+
| Analyst | Signal | Confidence |
+===================+==========+==============+
| Fundamentals | NEUTRAL | 25.0% |
+-------------------+----------+--------------+
| Technical Analyst | BULLISH | 55% |
+-------------------+----------+--------------+
| Valuation | BEARISH | 100.0% |
+-------------------+----------+--------------+
| Sentiment | BEARISH | 56.05% |
+-------------------+----------+--------------+
| Risk Management | | None% |
+-------------------+----------+--------------+
TRADING DECISION: [MSTR]
+------------+-------+
| Action | HOLD |
+------------+-------+
| Quantity | 0 |
+------------+-------+
| Confidence | 56.0% |
+------------+-------+
Reasoning: Despite the technical analyst's bullish signal with moderate confidence, the valuation and sentiment agents both indicate bearish signals with high confidence. Given these mixed signals and the high bearish confidence from the valuation agent, I'll opt to hold this position rather than initiating a buy.
PORTFOLIO SUMMARY:
+----------+----------+------------+--------------+
| Ticker | Action | Quantity | Confidence |
+==========+==========+============+==============+
| MSTR | HOLD | 0 | 56.0% |
+----------+----------+------------+--------------+ |
@buabaj - I'm adding news to the sentiment agent tomorrow. Haven't heard of NewsAPI, but at $449/month just for news data, it is really steep. |
Any idea who the creator is of NewsAPI? |
Hi @virattt yes, i do agree that the pricing is quite steep and I do not the creator, it just came up as one of the good news consolidation sources more affordable than BBG. NewsData seems a lot more affordable at $150/mo (https://newsdata.io/pricing) if you want us to consider that instead. I've been testing NewsAPI with the free tier on this project with no issues though. Is there something different you want done with the news sentiment though? I'm willing to contribute that if possible |
I've updated the sentiment analysis system to provide more comprehensive market insights. The main improvements focus on news sentiment analysis, working alongside the existing insider trading signals.
Key changes:
The agent now looks at both insider trading patterns and broad market sentiment from news, giving us a more complete picture. News analysis focuses on concrete factors like revenue impact, market competition, and product developments.
I've kept the original insider trading logic intact since it was working well, just added the news layer on top of it. Happy to adjust the weights or time window if we think it needs tuning.
sample sentiment analysis result: