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

Fixed bugs in pandas_data and data.py which didnt correctly handle long lengths in get_historical_prices #661

Closed
wants to merge 19 commits into from

Conversation

brettelliot
Copy link
Collaborator

@brettelliot brettelliot commented Dec 11, 2024

Description by Korbit AI

What change is being made?

Fix bugs in pandas_data.py and data.py to correctly handle extended lengths in the get_historical_prices function and revise test cases to reflect updates with a focus on correct handling of API keys and trading day calculations.

Why are these changes being made?

The changes address issues with calculating historical prices when dealing with extended data lengths, particularly accounting for long weekends and potential data gaps. The updates to test cases ensure more robust handling of API configurations and correct assessment of trading day calculations, such as the first trading day after Thanksgiving. This approach aims to improve data consistency and accuracy in historical data acquisition.

Is this description stale? Ask me to generate a new description by commenting /korbit-generate-pr-description

Copy link
Contributor

@korbit-ai korbit-ai bot left a comment

Choose a reason for hiding this comment

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

Review Summary by Korbit AI

Code Execution Comments

  • Review overflow and buffer values for accurate processing during holidays or multiple market closures.
Files scanned
File Path Reviewed
lumibot/data_sources/pandas_data.py
lumibot/tools/polygon_helper.py
lumibot/entities/data.py

Explore our documentation to understand the languages and file types we support and the files we ignore.

Need a new review? Comment /korbit-review on this PR and I'll review your latest changes.

Korbit Guide: Usage and Customization

Interacting with Korbit

  • You can manually ask Korbit to review your PR using the /korbit-review command in a comment at the root of your PR.
  • You can ask Korbit to generate a new PR description using the /korbit-generate-pr-description command in any comment on your PR.
  • Too many Korbit comments? I can resolve all my comment threads if you use the /korbit-resolve command in any comment on your PR.
  • Chat with Korbit on issues we post by tagging @korbit-ai in your reply.
  • Help train Korbit to improve your reviews by giving a 👍 or 👎 on the comments Korbit posts.

Customizing Korbit

  • Check out our docs on how you can make Korbit work best for you and your team.
  • Customize Korbit for your organization through the Korbit Console.

Current Korbit Configuration

General Settings
Setting Value
Review Schedule Automatic excluding drafts
Max Issue Count 10
Automatic PR Descriptions
Issue Categories
Category Enabled
Naming
Database Operations
Documentation
Logging
Error Handling
Systems and Environment
Objects and Data Structures
Readability and Maintainability
Asynchronous Processing
Design Patterns
Third-Party Libraries
Performance
Security
Functionality

Feedback and Support

Comment on lines 415 to 417
if ts_unit == "day":
# Multiply td * length * 1.5 to get the end datetime with overflow + 3 days for long weekends
td = (td * length * 1.5) + timedelta(days=3)
Copy link
Contributor

Choose a reason for hiding this comment

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

category Functionality

Inflexible Date Buffer for Market Closures

Tell me more

What is the issue?
The hardcoded overflow factor of 1.5 and additional 3 days buffer may not be sufficient for all scenarios, particularly during periods with multiple holidays or market closures.

Why this matters
During periods with multiple holidays (e.g., Christmas to New Year's) or unexpected market closures, the calculation could still result in insufficient data being retrieved, causing potential data gaps or incorrect analysis.

Chat with Korbit by mentioning @korbit-ai, and give a 👍 or 👎 to help Korbit improve your reviews.

Copy link
Collaborator

@davidlatte davidlatte left a comment

Choose a reason for hiding this comment

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

Small comment about extra days for a long length backtest.

As an FYI, my own historical usage is:

  • 30 daily candles
  • 2 weeks of 1hr candles
  • 4 trading days of 15m candles
  • all of today's 1m candles.

Comment on lines 416 to 417
# Multiply td * length * 1.5 to get the end datetime with overflow + 3 days for long weekends
td = (td * length * 1.5) + timedelta(days=3)
Copy link
Collaborator

Choose a reason for hiding this comment

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

1.5 multiplier can be large if someone is running a large backtest of like 2 years. How about instead using a round weeks check?

weeks_requested = td // 5  # Full trading week is 5 days
extra_padding_days = weeks_requested * 3  # to account for 3day weekends
td += extra_padding_days

…ata with timeshifts; remove uneeded fix in data.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants