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

Verified functionality of thetadata package #489

Open
wants to merge 18 commits into
base: dev
Choose a base branch
from
Open

Conversation

haochili
Copy link
Collaborator

@haochili haochili commented Jul 9, 2024

I operated unit testing script that was created on thetadata package, verified unit test with passing result.
-Verified stock dataset can be downloaded from thetadata web to local father, then parsed by lumibot properly
-I manually run martingale_8 with this branch locally built on my computer, and verified existing backtesting feature (with polygon) wasn't broken. I got the same return as I did with "dev" branch: 3.5.12.

  • In test_thetadata.py script:
  1. I added auto kill all ThetaTerminal.jar processes before and after the backtest. The original test script didn't have this step, causing the test cases to fail due to redundant process hanging from last round of test.

  2. I changed the script to automatically search for .env file at the root dir of the lumibot repo. I placed the credentials like username/password in the .env file, so the test_thetadata.py can run.

@haochili haochili requested a review from grzesir as a code owner July 9, 2024 22:24
Copy link
Contributor

korbit-ai bot commented Jul 9, 2024

My review is in progress 📖 - I will have feedback for you in a few minutes!

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.

I have reviewed your code and found 4 potential issues. To discuss my individual comments that I have added, tag me in replies using @korbit-ai.


Please react with a 👍 to my comments that you find helpful and a 👎 to those you find unhelpful - this will help me learn and improve as we collaborate.


# fig = go.Figure()
fig = make_subplots(specs=[[{"secondary_y": True}]])

# Strategy line
# Updated format_positions function to handle lists and dicts
def format_positions(positions):
Copy link
Contributor

Choose a reason for hiding this comment

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

category Readability and Maintainability

The format_positions function is currently nested within plot_returns, which can make the code less readable and maintainable. Consider defining format_positions at the module level to improve code organization and potential reusability.

Comment on lines +162 to +218
assert current_asset_price == 133.52

# Option Chain: Get Full Option Chain Information
chain = self.get_chain(self.chains, exchange="SMART")
expiration = self.select_option_expiration(chain, days_to_expiration=1)
# expiration = datetime.date(2023, 8, 4)

strike_price = round(current_asset_price)
option_asset = Asset(
symbol=underlying_asset.symbol,
asset_type="option",
expiration=expiration,
right="CALL",
strike=strike_price,
multiplier=100,
)
current_option_price = self.get_last_price(option_asset)

assert current_option_price == 4.10

# Get historical prices for the option
option_prices = self.get_historical_prices(option_asset, 100, "minute")
df = option_prices.df

# Assert that the first price is the right price
assert df["close"].iloc[-1] == 4.11

# Check that the time of the last bar is 2023-07-31T19:58:00.000Z
last_dt = df.index[-1]
assert last_dt == datetime.datetime(2023, 7, 31, 19, 58, tzinfo=datetime.timezone.utc)
Copy link
Contributor

Choose a reason for hiding this comment

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

category Tests

The tests contain hardcoded values for asset prices and option prices, which can make the tests fragile and less reliable if the underlying data changes. Consider replacing these hardcoded values with mock objects or setup methods that generate the necessary data dynamically to improve test robustness.

Comment on lines 8 to 9
import pandas as pd

from lumibot.backtesting import BacktestingBroker, PolygonDataBacktesting
Copy link
Contributor

Choose a reason for hiding this comment

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

category Readability and Maintainability

Hi, I noticed that there's an inconsistency in the use of blank lines in the import section and between methods. Could you please align this with our team's style guide? Either we keep a single blank line after imports and between methods for clarity, or we remove unnecessary blank lines if compactness is preferred.

Comment on lines +280 to +313
data_source = ThetaDataBacktesting(
datetime_start=backtesting_start,
datetime_end=backtesting_end,
username=THETADATA_USERNAME,
password=THETADATA_PASSWORD,
)
Copy link
Contributor

Choose a reason for hiding this comment

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

category Tests

The test_thetadata_restclient method is making real API calls, which can cause flakiness in the tests. To improve test reliability, consider mocking these API calls to ensure that the tests can run in isolation without depending on external services.

…nch. The current test_polygon.py on this branch was outdated, and somehow didn't get synced with manual conflicts resolution.

Signed-off-by: Haochi Li <[email protected]>
…e used for condor martingale and other strategies

Still pending on skipping holidays and weekends features to remove the warnings.

Signed-off-by: Haochi Li <[email protected]>
1. Introduced a automatic holiday + weekends detection feature in thetadata_helper.py
   When see weekends or holiday, skip streaming data from thetadata
2. Handled error messages, in skip days, avoid print out any error messages
3. If there is data stream error in normal days, still print out errors as original logic does

Signed-off-by: Haochi Li <[email protected]>
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