lumibot 4.0.23__py3-none-any.whl → 4.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of lumibot might be problematic. Click here for more details.
- lumibot/__pycache__/__init__.cpython-312.pyc +0 -0
- lumibot/__pycache__/constants.cpython-312.pyc +0 -0
- lumibot/__pycache__/credentials.cpython-312.pyc +0 -0
- lumibot/backtesting/__init__.py +6 -5
- lumibot/backtesting/__pycache__/__init__.cpython-312.pyc +0 -0
- lumibot/backtesting/__pycache__/alpaca_backtesting.cpython-312.pyc +0 -0
- lumibot/backtesting/__pycache__/alpha_vantage_backtesting.cpython-312.pyc +0 -0
- lumibot/backtesting/__pycache__/backtesting_broker.cpython-312.pyc +0 -0
- lumibot/backtesting/__pycache__/ccxt_backtesting.cpython-312.pyc +0 -0
- lumibot/backtesting/__pycache__/databento_backtesting.cpython-312.pyc +0 -0
- lumibot/backtesting/__pycache__/interactive_brokers_rest_backtesting.cpython-312.pyc +0 -0
- lumibot/backtesting/__pycache__/pandas_backtesting.cpython-312.pyc +0 -0
- lumibot/backtesting/__pycache__/polygon_backtesting.cpython-312.pyc +0 -0
- lumibot/backtesting/__pycache__/thetadata_backtesting.cpython-312.pyc +0 -0
- lumibot/backtesting/__pycache__/yahoo_backtesting.cpython-312.pyc +0 -0
- lumibot/backtesting/backtesting_broker.py +209 -9
- lumibot/backtesting/databento_backtesting.py +141 -24
- lumibot/backtesting/thetadata_backtesting.py +63 -42
- lumibot/brokers/__pycache__/__init__.cpython-312.pyc +0 -0
- lumibot/brokers/__pycache__/alpaca.cpython-312.pyc +0 -0
- lumibot/brokers/__pycache__/bitunix.cpython-312.pyc +0 -0
- lumibot/brokers/__pycache__/broker.cpython-312.pyc +0 -0
- lumibot/brokers/__pycache__/ccxt.cpython-312.pyc +0 -0
- lumibot/brokers/__pycache__/example_broker.cpython-312.pyc +0 -0
- lumibot/brokers/__pycache__/interactive_brokers.cpython-312.pyc +0 -0
- lumibot/brokers/__pycache__/interactive_brokers_rest.cpython-312.pyc +0 -0
- lumibot/brokers/__pycache__/projectx.cpython-312.pyc +0 -0
- lumibot/brokers/__pycache__/schwab.cpython-312.pyc +0 -0
- lumibot/brokers/__pycache__/tradier.cpython-312.pyc +0 -0
- lumibot/brokers/__pycache__/tradovate.cpython-312.pyc +0 -0
- lumibot/brokers/alpaca.py +11 -1
- lumibot/brokers/tradeovate.py +475 -0
- lumibot/components/grok_news_helper.py +284 -0
- lumibot/components/options_helper.py +90 -34
- lumibot/credentials.py +3 -0
- lumibot/data_sources/__pycache__/__init__.cpython-312.pyc +0 -0
- lumibot/data_sources/__pycache__/alpaca_data.cpython-312.pyc +0 -0
- lumibot/data_sources/__pycache__/alpha_vantage_data.cpython-312.pyc +0 -0
- lumibot/data_sources/__pycache__/bitunix_data.cpython-312.pyc +0 -0
- lumibot/data_sources/__pycache__/ccxt_backtesting_data.cpython-312.pyc +0 -0
- lumibot/data_sources/__pycache__/ccxt_data.cpython-312.pyc +0 -0
- lumibot/data_sources/__pycache__/data_source.cpython-312.pyc +0 -0
- lumibot/data_sources/__pycache__/data_source_backtesting.cpython-312.pyc +0 -0
- lumibot/data_sources/__pycache__/databento_data_polars_backtesting.cpython-312.pyc +0 -0
- lumibot/data_sources/__pycache__/databento_data_polars_live.cpython-312.pyc +0 -0
- lumibot/data_sources/__pycache__/example_broker_data.cpython-312.pyc +0 -0
- lumibot/data_sources/__pycache__/exceptions.cpython-312.pyc +0 -0
- lumibot/data_sources/__pycache__/interactive_brokers_data.cpython-312.pyc +0 -0
- lumibot/data_sources/__pycache__/interactive_brokers_rest_data.cpython-312.pyc +0 -0
- lumibot/data_sources/__pycache__/pandas_data.cpython-312.pyc +0 -0
- lumibot/data_sources/__pycache__/polars_mixin.cpython-312.pyc +0 -0
- lumibot/data_sources/__pycache__/polygon_data_polars.cpython-312.pyc +0 -0
- lumibot/data_sources/__pycache__/projectx_data.cpython-312.pyc +0 -0
- lumibot/data_sources/__pycache__/schwab_data.cpython-312.pyc +0 -0
- lumibot/data_sources/__pycache__/tradier_data.cpython-312.pyc +0 -0
- lumibot/data_sources/__pycache__/tradovate_data.cpython-312.pyc +0 -0
- lumibot/data_sources/__pycache__/yahoo_data_polars.cpython-312.pyc +0 -0
- lumibot/data_sources/data_source_backtesting.py +3 -5
- lumibot/data_sources/databento_data_polars_backtesting.py +194 -48
- lumibot/data_sources/pandas_data.py +6 -3
- lumibot/data_sources/polars_mixin.py +126 -21
- lumibot/data_sources/tradeovate_data.py +80 -0
- lumibot/data_sources/tradier_data.py +2 -1
- lumibot/entities/__pycache__/__init__.cpython-312.pyc +0 -0
- lumibot/entities/__pycache__/asset.cpython-312.pyc +0 -0
- lumibot/entities/__pycache__/bar.cpython-312.pyc +0 -0
- lumibot/entities/__pycache__/bars.cpython-312.pyc +0 -0
- lumibot/entities/__pycache__/chains.cpython-312.pyc +0 -0
- lumibot/entities/__pycache__/data.cpython-312.pyc +0 -0
- lumibot/entities/__pycache__/dataline.cpython-312.pyc +0 -0
- lumibot/entities/__pycache__/order.cpython-312.pyc +0 -0
- lumibot/entities/__pycache__/position.cpython-312.pyc +0 -0
- lumibot/entities/__pycache__/quote.cpython-312.pyc +0 -0
- lumibot/entities/__pycache__/trading_fee.cpython-312.pyc +0 -0
- lumibot/entities/asset.py +8 -0
- lumibot/entities/order.py +1 -1
- lumibot/entities/quote.py +14 -0
- lumibot/example_strategies/__pycache__/__init__.cpython-312.pyc +0 -0
- lumibot/example_strategies/__pycache__/test_broker_functions.cpython-312-pytest-8.4.1.pyc +0 -0
- lumibot/strategies/__pycache__/__init__.cpython-312.pyc +0 -0
- lumibot/strategies/__pycache__/_strategy.cpython-312.pyc +0 -0
- lumibot/strategies/__pycache__/strategy.cpython-312.pyc +0 -0
- lumibot/strategies/__pycache__/strategy_executor.cpython-312.pyc +0 -0
- lumibot/strategies/_strategy.py +95 -27
- lumibot/strategies/strategy.py +5 -6
- lumibot/strategies/strategy_executor.py +2 -2
- lumibot/tools/__pycache__/__init__.cpython-312.pyc +0 -0
- lumibot/tools/__pycache__/alpaca_helpers.cpython-312.pyc +0 -0
- lumibot/tools/__pycache__/bitunix_helpers.cpython-312.pyc +0 -0
- lumibot/tools/__pycache__/black_scholes.cpython-312.pyc +0 -0
- lumibot/tools/__pycache__/ccxt_data_store.cpython-312.pyc +0 -0
- lumibot/tools/__pycache__/databento_helper.cpython-312.pyc +0 -0
- lumibot/tools/__pycache__/databento_helper_polars.cpython-312.pyc +0 -0
- lumibot/tools/__pycache__/debugers.cpython-312.pyc +0 -0
- lumibot/tools/__pycache__/decorators.cpython-312.pyc +0 -0
- lumibot/tools/__pycache__/helpers.cpython-312.pyc +0 -0
- lumibot/tools/__pycache__/indicators.cpython-312.pyc +0 -0
- lumibot/tools/__pycache__/lumibot_logger.cpython-312.pyc +0 -0
- lumibot/tools/__pycache__/pandas.cpython-312.pyc +0 -0
- lumibot/tools/__pycache__/polygon_helper.cpython-312.pyc +0 -0
- lumibot/tools/__pycache__/polygon_helper_async.cpython-312.pyc +0 -0
- lumibot/tools/__pycache__/polygon_helper_polars_optimized.cpython-312.pyc +0 -0
- lumibot/tools/__pycache__/projectx_helpers.cpython-312.pyc +0 -0
- lumibot/tools/__pycache__/schwab_helper.cpython-312.pyc +0 -0
- lumibot/tools/__pycache__/thetadata_helper.cpython-312.pyc +0 -0
- lumibot/tools/__pycache__/types.cpython-312.pyc +0 -0
- lumibot/tools/__pycache__/yahoo_helper.cpython-312.pyc +0 -0
- lumibot/tools/__pycache__/yahoo_helper_polars_optimized.cpython-312.pyc +0 -0
- lumibot/tools/databento_helper.py +384 -133
- lumibot/tools/databento_helper_polars.py +218 -156
- lumibot/tools/databento_roll.py +216 -0
- lumibot/tools/lumibot_logger.py +32 -17
- lumibot/tools/polygon_helper.py +65 -0
- lumibot/tools/thetadata_helper.py +588 -70
- lumibot/traders/__pycache__/__init__.cpython-312.pyc +0 -0
- lumibot/traders/__pycache__/trader.cpython-312.pyc +0 -0
- lumibot/traders/trader.py +1 -1
- lumibot/trading_builtins/__pycache__/__init__.cpython-312.pyc +0 -0
- lumibot/trading_builtins/__pycache__/custom_stream.cpython-312.pyc +0 -0
- lumibot/trading_builtins/__pycache__/safe_list.cpython-312.pyc +0 -0
- {lumibot-4.0.23.dist-info → lumibot-4.1.0.dist-info}/METADATA +1 -2
- {lumibot-4.0.23.dist-info → lumibot-4.1.0.dist-info}/RECORD +160 -44
- tests/backtest/check_timing_offset.py +198 -0
- tests/backtest/check_volume_spike.py +112 -0
- tests/backtest/comprehensive_comparison.py +166 -0
- tests/backtest/debug_comparison.py +91 -0
- tests/backtest/diagnose_price_difference.py +97 -0
- tests/backtest/direct_api_comparison.py +203 -0
- tests/backtest/profile_thetadata_vs_polygon.py +255 -0
- tests/backtest/root_cause_analysis.py +109 -0
- tests/backtest/test_accuracy_verification.py +244 -0
- tests/backtest/test_daily_data_timestamp_comparison.py +801 -0
- tests/backtest/test_databento.py +4 -0
- tests/backtest/test_databento_comprehensive_trading.py +564 -0
- tests/backtest/test_debug_avg_fill_price.py +112 -0
- tests/backtest/test_dividends.py +8 -3
- tests/backtest/test_example_strategies.py +54 -47
- tests/backtest/test_futures_edge_cases.py +451 -0
- tests/backtest/test_futures_single_trade.py +270 -0
- tests/backtest/test_futures_ultra_simple.py +191 -0
- tests/backtest/test_index_data_verification.py +348 -0
- tests/backtest/test_polygon.py +45 -24
- tests/backtest/test_thetadata.py +246 -60
- tests/backtest/test_thetadata_comprehensive.py +729 -0
- tests/backtest/test_thetadata_vs_polygon.py +557 -0
- tests/backtest/test_yahoo.py +1 -2
- tests/conftest.py +20 -0
- tests/test_backtesting_data_source_env.py +249 -0
- tests/test_backtesting_quiet_logs_complete.py +10 -11
- tests/test_databento_helper.py +73 -86
- tests/test_databento_timezone_fixes.py +21 -4
- tests/test_get_historical_prices.py +6 -6
- tests/test_options_helper.py +162 -40
- tests/test_polygon_helper.py +21 -13
- tests/test_quiet_logs_requirements.py +5 -5
- tests/test_thetadata_helper.py +487 -171
- tests/test_yahoo_data.py +125 -0
- {lumibot-4.0.23.dist-info → lumibot-4.1.0.dist-info}/LICENSE +0 -0
- {lumibot-4.0.23.dist-info → lumibot-4.1.0.dist-info}/WHEEL +0 -0
- {lumibot-4.0.23.dist-info → lumibot-4.1.0.dist-info}/top_level.txt +0 -0
tests/test_yahoo_data.py
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
import pytest
|
|
3
|
+
import math
|
|
4
|
+
from datetime import datetime, timedelta, time
|
|
5
|
+
import pytz
|
|
6
|
+
|
|
7
|
+
import pandas as pd
|
|
8
|
+
|
|
9
|
+
from lumibot.data_sources import YahooData
|
|
10
|
+
from lumibot.tools import print_full_pandas_dataframes, set_pandas_float_display_precision
|
|
11
|
+
from lumibot.entities import Asset
|
|
12
|
+
from lumibot.tools import get_trading_days
|
|
13
|
+
from tests.fixtures import BaseDataSourceTester
|
|
14
|
+
|
|
15
|
+
logger = logging.getLogger(__name__)
|
|
16
|
+
print_full_pandas_dataframes()
|
|
17
|
+
set_pandas_float_display_precision()
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
# @pytest.mark.skip()
|
|
21
|
+
class TestYahooData(BaseDataSourceTester):
|
|
22
|
+
|
|
23
|
+
def _create_data_source(self):
|
|
24
|
+
return YahooData()
|
|
25
|
+
|
|
26
|
+
@pytest.mark.xfail(reason="yahoo sucks")
|
|
27
|
+
def test_get_historical_prices_daily_bars_over_long_weekend(self):
|
|
28
|
+
tzinfo = pytz.timezone('America/New_York')
|
|
29
|
+
datetime_start = tzinfo.localize(datetime(2019, 1, 2))
|
|
30
|
+
datetime_end = tzinfo.localize(datetime(2019, 12, 31))
|
|
31
|
+
asset = Asset("SPY")
|
|
32
|
+
timestep = "day"
|
|
33
|
+
|
|
34
|
+
length = 10
|
|
35
|
+
data_source = YahooData(datetime_start, datetime_end)
|
|
36
|
+
|
|
37
|
+
# First trading day after MLK day
|
|
38
|
+
now = tzinfo.localize(datetime(2019, 1, 22)).replace(hour=9, minute=30)
|
|
39
|
+
data_source._datetime = now
|
|
40
|
+
bars = data_source.get_historical_prices(asset=asset, length=length, timestep=timestep)
|
|
41
|
+
self.check_length(bars=bars, length=length)
|
|
42
|
+
self.check_columns(bars=bars)
|
|
43
|
+
self.check_index(bars=bars)
|
|
44
|
+
# TODO: YahooData doesn't return the incomplete daily bar for the day like most live data sources.
|
|
45
|
+
# self.check_daily_bars(
|
|
46
|
+
# bars=bars,
|
|
47
|
+
# now=now,
|
|
48
|
+
# data_source_tz=data_source.tzinfo,
|
|
49
|
+
# time_check=time(0, 0),
|
|
50
|
+
# )
|
|
51
|
+
|
|
52
|
+
@pytest.mark.xfail(reason="yahoo sucks")
|
|
53
|
+
def test_get_historical_prices_daily_bars_for_backtesting_broker(self):
|
|
54
|
+
# Simulate what the backtesting broker does for yahoo
|
|
55
|
+
tzinfo = pytz.timezone('America/New_York')
|
|
56
|
+
datetime_start = tzinfo.localize(datetime(2019, 1, 2))
|
|
57
|
+
datetime_end = tzinfo.localize(datetime(2019, 12, 31))
|
|
58
|
+
asset = Asset("SPY")
|
|
59
|
+
timestep = "day"
|
|
60
|
+
length = 1
|
|
61
|
+
timeshift = timedelta(
|
|
62
|
+
days=-1
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
data_source = YahooData(datetime_start, datetime_end)
|
|
66
|
+
now = tzinfo.localize(datetime(2019, 4, 1, 9, 30))
|
|
67
|
+
data_source._datetime = now
|
|
68
|
+
|
|
69
|
+
bars = data_source.get_historical_prices(asset=asset, length=length, timestep=timestep, timeshift=timeshift)
|
|
70
|
+
self.check_length(bars=bars, length=length)
|
|
71
|
+
self.check_columns(bars=bars)
|
|
72
|
+
self.check_index(bars=bars)
|
|
73
|
+
# TODO: yahoo data is indexed at 4pm, so even this, which correctly gets the current bar,
|
|
74
|
+
# fails the check that the bar is before now and not from the future.
|
|
75
|
+
# self.check_daily_bars(
|
|
76
|
+
# bars=bars,
|
|
77
|
+
# now=now,
|
|
78
|
+
# data_source_tz=data_source.tzinfo,
|
|
79
|
+
# time_check=time(0, 0),
|
|
80
|
+
# )
|
|
81
|
+
|
|
82
|
+
def test_format_index_symbol(self):
|
|
83
|
+
"""Test that index symbols are properly formatted for Yahoo Finance"""
|
|
84
|
+
data_source = YahooData()
|
|
85
|
+
|
|
86
|
+
# Test SPX -> ^SPX
|
|
87
|
+
symbols = data_source._format_index_symbol("SPX")
|
|
88
|
+
assert "^SPX" in symbols
|
|
89
|
+
assert "SPX" in symbols
|
|
90
|
+
|
|
91
|
+
# Test ^SPX -> ^SPX (already formatted)
|
|
92
|
+
symbols = data_source._format_index_symbol("^SPX")
|
|
93
|
+
assert "^SPX" in symbols
|
|
94
|
+
assert "SPX" in symbols
|
|
95
|
+
|
|
96
|
+
# Test other common indexes
|
|
97
|
+
symbols = data_source._format_index_symbol("DJI")
|
|
98
|
+
assert "^DJI" in symbols
|
|
99
|
+
assert "DJI" in symbols
|
|
100
|
+
|
|
101
|
+
@pytest.mark.xfail(reason="Depends on external Yahoo Finance API")
|
|
102
|
+
def test_get_historical_prices_index_asset(self):
|
|
103
|
+
"""Test getting historical prices for index assets"""
|
|
104
|
+
tzinfo = pytz.timezone('America/New_York')
|
|
105
|
+
datetime_start = tzinfo.localize(datetime(2019, 1, 2))
|
|
106
|
+
datetime_end = tzinfo.localize(datetime(2019, 12, 31))
|
|
107
|
+
|
|
108
|
+
# Test with SPX index
|
|
109
|
+
asset = Asset("SPX", asset_type="index")
|
|
110
|
+
timestep = "day"
|
|
111
|
+
length = 10
|
|
112
|
+
|
|
113
|
+
data_source = YahooData(datetime_start, datetime_end)
|
|
114
|
+
|
|
115
|
+
# Set the datetime to a valid trading day
|
|
116
|
+
now = tzinfo.localize(datetime(2019, 1, 22)).replace(hour=9, minute=30)
|
|
117
|
+
data_source._datetime = now
|
|
118
|
+
|
|
119
|
+
bars = data_source.get_historical_prices(asset=asset, length=length, timestep=timestep)
|
|
120
|
+
|
|
121
|
+
# Basic validation
|
|
122
|
+
self.check_length(bars=bars, length=length)
|
|
123
|
+
self.check_columns(bars=bars)
|
|
124
|
+
self.check_index(bars=bars)
|
|
125
|
+
|
|
File without changes
|
|
File without changes
|
|
File without changes
|