Skip to content
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

Add news data analysis to trading strategies #20

Merged
merged 1 commit into from
Jan 5, 2025

Conversation

vishwamartur
Copy link
Owner

@vishwamartur vishwamartur commented Jan 5, 2025

Related to #2

Incorporate news data analysis into futures and options trading strategies.

  • Futures Strategy (strategies/futures_strategy.py)

    • Import NewsDataFetcher from data/news_data_fetcher.py.
    • Initialize NewsDataFetcher in the __init__ method.
    • Add _analyze_news_data method to analyze news data.
    • Update generate_signal method to incorporate news data analysis.
  • Options Strategy (strategies/options_strategy.py)

    • Import NewsDataFetcher from data/news_data_fetcher.py.
    • Initialize NewsDataFetcher in the __init__ method.
    • Add _analyze_news_data method to analyze news data.
    • Update generate_signal method to incorporate news data analysis.

Summary by CodeRabbit

  • New Features

    • Enhanced trading strategies by integrating news data sentiment analysis
    • Added news data processing to futures and options trading signal generation
    • Incorporated news sentiment scores into overall trading decision-making process
  • Improvements

    • Expanded information sources for trading signals
    • Implemented news data analysis method in both strategy classes

Related to #2

Incorporate news data analysis into futures and options trading strategies.

* **Futures Strategy (`strategies/futures_strategy.py`)**
  - Import `NewsDataFetcher` from `data/news_data_fetcher.py`.
  - Initialize `NewsDataFetcher` in the `__init__` method.
  - Add `_analyze_news_data` method to analyze news data.
  - Update `generate_signal` method to incorporate news data analysis.

* **Options Strategy (`strategies/options_strategy.py`)**
  - Import `NewsDataFetcher` from `data/news_data_fetcher.py`.
  - Initialize `NewsDataFetcher` in the `__init__` method.
  - Add `_analyze_news_data` method to analyze news data.
  - Update `generate_signal` method to incorporate news data analysis.
Copy link

coderabbitai bot commented Jan 5, 2025

Walkthrough

The pull request introduces news data integration into trading signal generation for both FuturesStrategy and OptionsStrategy classes. By adding a NewsDataFetcher and implementing a new _analyze_news_data method in each strategy, the changes enhance the trading decision-making process. The modifications allow fetching and processing news articles, computing sentiment scores, and incorporating these scores into the overall trading signal calculation.

Changes

File Change Summary
strategies/futures_strategy.py - Added NewsDataFetcher import
- Created news_fetcher in __init__
- Added _analyze_news_data method to compute news sentiment score
- Updated generate_signal to include news data processing
strategies/options_strategy.py - Added NewsDataFetcher import
- Initialized news_fetcher in constructor
- Added _analyze_news_data method to compute news sentiment score
- Modified generate_signal to fetch and analyze news data

Sequence Diagram

sequenceDiagram
    participant Strategy
    participant NewsDataFetcher
    participant NewsAnalyzer

    Strategy->>NewsDataFetcher: Fetch news data
    NewsDataFetcher-->>Strategy: Return news articles
    Strategy->>NewsAnalyzer: Analyze news sentiment
    NewsAnalyzer-->>Strategy: Compute news score
    Strategy->>Strategy: Integrate news score with other signals
Loading

Possibly related PRs

Poem

🐰 Trader Rabbit's News Delight

Whiskers twitching, market in sight,
News data flows, signals burning bright,
Sentiment scores dance with glee,
Trading strategies now set free!
Hop, hop, hurrah for insight's might! 🚀


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (6)
strategies/futures_strategy.py (3)

29-32: Initialize the news fetcher with graceful fallback.
If the API key or endpoint is missing or invalid, consider logging a warning or falling back to a no-op fetcher.


70-71: Confirm weighting logic.
You are combining multiple scores equally. If news data is less reliable, consider assigning a lower weight or a dynamic weighting approach.


144-165: Evaluate duplication across strategies.
These lines match the _analyze_news_data approach in OptionsStrategy. Consider refactoring into a shared utility to maintain DRY principles.

Would you like help creating a shared helper for analyzing news data?

strategies/options_strategy.py (3)

63-66: Handle fetch errors.
Like with the futures strategy, consider adding error handling around the asynchronous news fetch call.


71-72: Weighing the signals.
Integration of the news signal is done similarly to the futures strategy. Verify if uniform weighting is appropriate for options data, or if you need a different weighting approach.


183-204: Refactor repeated logic.
As seen in futures_strategy.py, _analyze_news_data is identical. Moving this to a shared helper or base class would reduce duplication and promote consistency.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4850195 and e124e7d.

📒 Files selected for processing (2)
  • strategies/futures_strategy.py (4 hunks)
  • strategies/options_strategy.py (4 hunks)
🔇 Additional comments (6)
strategies/futures_strategy.py (4)

8-8: Consider verifying the fetcher configuration.
By instantiating NewsDataFetcher directly, you're assuming the config keys exist. You might want to validate the presence or correctness of news_api_key and news_api_endpoint before usage.


12-12: Docstring update looks great.
The inclusion of “news data” in the docstring properly reflects the updated functionality.


36-36: Docstring alignment.
The method description now references news data. This ensures clarity for developers.


61-64: 🛠️ Refactor suggestion

Check for potential network errors.
When calling fetch_news_data, there could be network or API failures. Consider wrapping this in a try/except block or verifying the data attributes before processing.

strategies/options_strategy.py (2)

6-6: Importing NewsDataFetcher
Import statement is consistent with the futures strategy. Well done.


28-31: Validate config for news fetcher.
Similar to the futures strategy, ensure that config["api"]["news_api_key"] and config["api"]["news_api_endpoint"] are present and valid prior to initialization.

@vishwamartur vishwamartur merged commit df88ae6 into main Jan 5, 2025
8 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant