-
Notifications
You must be signed in to change notification settings - Fork 131
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
Polygon.io Backtesting example is failing #256
Comments
c0indev3l
changed the title
Polygon.io Backtesting is failing
Polygon.io Backtesting example is failing
Jul 14, 2023
Moreover, in such a case requests doesn't seems to be cached as after an other run I'm still seeing "Getting pricing data ..." |
The request is being cached, however because of the nature of pricing data
we still have to check polygon whether we are missing anything on each run.
For example, options data tends to have a lot of periods where there is no
data, so we can’t be sure if we are missing data or if it just doesn’t
exist.
On Fri, Jul 14, 2023 at 10:47 AM working4coins ***@***.***> wrote:
Moreover, in such a case requests doesn't seems to be cached as after an
other run I'm still seeing "Getting pricing data ..."
—
Reply to this email directly, view it on GitHub
<#256 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAIYQK7YSGYY2FCNT2VXBLDXQFLXNANCNFSM6AAAAAA2KNTAKM>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
--
Robert Grzesik 347-635-3416
|
What version of lumibot and yfinance are you using? (pip show lumibot and
pip show yfinance). It looks like you’re getting a 401 error with yahoo.
On Fri, Jul 14, 2023 at 10:45 AM working4coins ***@***.***> wrote:
Hello,
from datetime import datetimefrom lumibot.backtesting import PolygonDataBacktestingfrom lumibot.strategies import Strategy
class MyStrategy(Strategy):
parameters = {
"symbol": "AAPL",
}
def initialize(self):
self.sleeptime = "1D"
def on_trading_iteration(self):
if self.first_iteration:
symbol = self.parameters["symbol"]
price = self.get_last_price(symbol)
qty = self.portfolio_value / price
order = self.create_order(symbol, quantity=qty, side="buy")
self.submit_order(order)
if __name__ == "__main__":
backtesting_start = datetime(2023, 1, 1)
backtesting_end = datetime(2023, 5, 1)
MyStrategy.backtest(
PolygonDataBacktesting,
backtesting_start,
backtesting_end,
polygon_api_key="YOUR_POLYGON_API_KEY",
polygon_has_paid_subscription=False,
)
raises
>python bot.py
Starting backtest for MyStrategy...
ERROR:root:Error getting the risk free rate: 401 Client Error: Unauthorized for url: https://query2.finance.yahoo.com/v10/finance/quoteSummary/%5EIRX?modules=summaryProfile%2CfinancialData%2CquoteType%2CdefaultKeyStatistics%2CassetProfile%2CsummaryDetail&ssl=true
INFO:backtest_stats:Starting backtest...
Progress |█--------------------------------------------------------| 2.00% [Elapsed: 0:00:03 ETA: 0:02:33]
Getting pricing data for AAPL from Polygon...
2023-07-14 16:37:06,634: root: ERROR: unsupported operand type(s) for /: 'float' and 'NoneType'
2023-07-14 16:37:06,637: root: ERROR: Traceback (most recent call last):
File "C:\Users\w4c\AppData\Roaming\Python\Python310\site-packages\lumibot\strategies\strategy_executor.py", line 570, in run
self._run_trading_session()
File "C:\Users\w4c\AppData\Roaming\Python\Python310\site-packages\lumibot\strategies\strategy_executor.py", line 538, in _run_trading_session
self._on_trading_iteration()
File "C:\Users\w4c\AppData\Roaming\Python\Python310\site-packages\lumibot\strategies\strategy_executor.py", line 261, in func_output
result = func_input(self, *args, **kwargs)
File "C:\Users\w4c\AppData\Roaming\Python\Python310\site-packages\lumibot\strategies\strategy_executor.py", line 285, in func_output
result = func_input(self, *args, **kwargs)
File "C:\Users\w4c\AppData\Roaming\Python\Python310\site-packages\lumibot\strategies\strategy_executor.py", line 69, in func_output
return func_input(self, *args, **kwargs)
File "C:\Users\w4c\AppData\Roaming\Python\Python310\site-packages\lumibot\strategies\strategy_executor.py", line 339, in _on_trading_iteration
on_trading_iteration()
File "C:\Users\w4c\AppData\Roaming\Python\Python310\site-packages\lumibot\tools\decorators.py", line 62, in func_output
frame, result = call_function_get_frame(func_input, *args, **kwargs)
File "C:\Users\w4c\AppData\Roaming\Python\Python310\site-packages\lumibot\tools\decorators.py", line 30, in call_function_get_frame
result = func(*args, **kwargs)
File "C:\Users\w4c\trading\lumibot\bot.py", line 17, in on_trading_iteration
qty = self.portfolio_value / price
TypeError: unsupported operand type(s) for /: 'float' and 'NoneType'
after changing API key I run into an other problem...
>python bot.py
Starting backtest for MyStrategy...
ERROR:root:Error getting the risk free rate: 401 Client Error: Unauthorized for url: https://query2.finance.yahoo.com/v10/finance/quoteSummary/%5EIRX?modules=summaryProfile%2CfinancialData%2CquoteType%2CdefaultKeyStatistics%2CassetProfile%2CsummaryDetail&ssl=true
INFO:backtest_stats:Starting backtest...
Progress |█--------------------------------------------------------| 2.00% [Elapsed: 0:00:03 ETA: 0:02:27]
Getting pricing data for AAPL from Polygon...
Sleeping 60 seconds getting pricing data for AAPL from Polygon because we don't have a paid subscription and we don't want to hit the rate limit. If you want to avoid this, you can get a paid subscription at https://polygon.io/pricing and set `polygon_has_paid_subscription=True` when starting the backtest.
Progress |█████████████████████████████████████████████████████████| 100.00% [Elapsed: 0:01:08 ETA: 0:00:00]2023-07-14 16:40:00,490: root: INFO: MyStrategy : --- MyStrategy Strategy Performance ---
2023-07-14 16:40:00,509: root: INFO: MyStrategy : Total Return: 30.47%
2023-07-14 16:40:00,509: root: INFO: MyStrategy : CAGR 132.76%
2023-07-14 16:40:00,510: root: INFO: MyStrategy : Volatility 23.27%
2023-07-14 16:40:00,510: root: INFO: MyStrategy : Sharpe 5.71
2023-07-14 16:40:00,510: root: INFO: MyStrategy : Max Drawdown 6.43% on 2023-03-02
2023-07-14 16:40:00,511: root: INFO: MyStrategy : RoMaD 2,065.44%
2023-07-14 16:40:00,511: root: INFO: MyStrategy : --- SPY Benchmark Performance ---
Getting pricing data for SPY from Polygon...
Sleeping 60 seconds getting pricing data for SPY from Polygon because we don't have a paid subscription and we don't want to hit the rate limit. If you want to avoid this, you can get a paid subscription at https://polygon.io/pricing and set `polygon_has_paid_subscription=True` when starting the backtest.
2023-07-14 16:41:00,900: root: ERROR: Error getting bars for SPY: You are requesting minute data from a daily data source. This is not supported.
2023-07-14 16:41:00,905: root: ERROR: Traceback (most recent call last):
File "C:\Users\w4c\AppData\Roaming\Python\Python310\site-packages\lumibot\data_sources\pandas_data.py", line 318, in _pull_source_symbol_bars_between_dates
res = data.get_bars_between_dates(
File "C:\Users\w4c\AppData\Roaming\Python\Python310\site-packages\lumibot\entities\data.py", line 577, in get_bars_between_dates
raise ValueError(
ValueError: You are requesting minute data from a daily data source. This is not supported.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\w4c\AppData\Roaming\Python\Python310\site-packages\lumibot\strategies\strategy_executor.py", line 587, in run
self._on_strategy_end()
File "C:\Users\w4c\AppData\Roaming\Python\Python310\site-packages\lumibot\strategies\strategy_executor.py", line 261, in func_output
result = func_input(self, *args, **kwargs)
File "C:\Users\w4c\AppData\Roaming\Python\Python310\site-packages\lumibot\strategies\strategy_executor.py", line 360, in _on_strategy_end
self.strategy._dump_stats()
File "C:\Users\w4c\AppData\Roaming\Python\Python310\site-packages\lumibot\strategies\_strategy.py", line 569, in _dump_stats
bars = self.data_source.get_historical_prices_between_dates(
File "C:\Users\w4c\AppData\Roaming\Python\Python310\site-packages\lumibot\backtesting\polygon_backtesting.py", line 191, in get_historical_prices_between_dates
response = super()._pull_source_symbol_bars_between_dates(
File "C:\Users\w4c\AppData\Roaming\Python\Python310\site-packages\lumibot\data_sources\pandas_data.py", line 323, in _pull_source_symbol_bars_between_dates
raise ValueError(f"Error getting bars for {asset}: {e}")
ValueError: Error getting bars for SPY: You are requesting minute data from a daily data source. This is not supported.
2023-07-14 16:41:00,907: root: INFO: MyStrategy : Executing the on_bot_crash event method
2023-07-14 16:41:00,916: root: INFO: MyStrategy : --- MyStrategy Strategy Performance ---
2023-07-14 16:41:00,932: root: INFO: MyStrategy : Total Return: 30.47%
2023-07-14 16:41:00,932: root: INFO: MyStrategy : CAGR 132.76%
2023-07-14 16:41:00,932: root: INFO: MyStrategy : Volatility 23.27%
2023-07-14 16:41:00,933: root: INFO: MyStrategy : Sharpe 5.71
2023-07-14 16:41:00,933: root: INFO: MyStrategy : Max Drawdown 6.43% on 2023-03-02
2023-07-14 16:41:00,933: root: INFO: MyStrategy : RoMaD 2,065.44%
2023-07-14 16:41:00,934: root: INFO: MyStrategy : --- SPY Benchmark Performance ---
Exception in thread MyStrategy:
Traceback (most recent call last):
File "C:\Users\w4c\AppData\Roaming\Python\Python310\site-packages\lumibot\data_sources\pandas_data.py", line 318, in _pull_source_symbol_bars_between_dates
res = data.get_bars_between_dates(
File "C:\Users\w4c\AppData\Roaming\Python\Python310\site-packages\lumibot\entities\data.py", line 577, in get_bars_between_dates
raise ValueError(
ValueError: You are requesting minute data from a daily data source. This is not supported.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\w4c\AppData\Roaming\Python\Python310\site-packages\lumibot\strategies\strategy_executor.py", line 587, in run
self._on_strategy_end()
File "C:\Users\w4c\AppData\Roaming\Python\Python310\site-packages\lumibot\strategies\strategy_executor.py", line 261, in func_output
result = func_input(self, *args, **kwargs)
File "C:\Users\w4c\AppData\Roaming\Python\Python310\site-packages\lumibot\strategies\strategy_executor.py", line 360, in _on_strategy_end
self.strategy._dump_stats()
File "C:\Users\w4c\AppData\Roaming\Python\Python310\site-packages\lumibot\strategies\_strategy.py", line 569, in _dump_stats
bars = self.data_source.get_historical_prices_between_dates(
File "C:\Users\w4c\AppData\Roaming\Python\Python310\site-packages\lumibot\backtesting\polygon_backtesting.py", line 191, in get_historical_prices_between_dates
response = super()._pull_source_symbol_bars_between_dates(
File "C:\Users\w4c\AppData\Roaming\Python\Python310\site-packages\lumibot\data_sources\pandas_data.py", line 323, in _pull_source_symbol_bars_between_dates
raise ValueError(f"Error getting bars for {asset}: {e}")
ValueError: Error getting bars for SPY: You are requesting minute data from a daily data source. This is not supported.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\w4c\AppData\Roaming\Python\Python310\site-packages\lumibot\data_sources\pandas_data.py", line 318, in _pull_source_symbol_bars_between_dates
res = data.get_bars_between_dates(
File "C:\Users\w4c\AppData\Roaming\Python\Python310\site-packages\lumibot\entities\data.py", line 577, in get_bars_between_dates
raise ValueError(
ValueError: You are requesting minute data from a daily data source. This is not supported.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\tools\Anaconda3\lib\threading.py", line 1016, in _bootstrap_inner
self.run()
File "C:\Users\w4c\AppData\Roaming\Python\Python310\site-packages\lumibot\strategies\strategy_executor.py", line 591, in run
self._on_bot_crash(e)
File "C:\Users\w4c\AppData\Roaming\Python\Python310\site-packages\lumibot\strategies\strategy_executor.py", line 273, in func_output
result = func_input(self, *args, **kwargs)
File "C:\Users\w4c\AppData\Roaming\Python\Python310\site-packages\lumibot\strategies\strategy_executor.py", line 371, in _on_bot_crash
self.strategy._dump_stats()
File "C:\Users\w4c\AppData\Roaming\Python\Python310\site-packages\lumibot\strategies\_strategy.py", line 569, in _dump_stats
bars = self.data_source.get_historical_prices_between_dates(
File "C:\Users\w4c\AppData\Roaming\Python\Python310\site-packages\lumibot\backtesting\polygon_backtesting.py", line 191, in get_historical_prices_between_dates
response = super()._pull_source_symbol_bars_between_dates(
File "C:\Users\w4c\AppData\Roaming\Python\Python310\site-packages\lumibot\data_sources\pandas_data.py", line 323, in _pull_source_symbol_bars_between_dates
raise ValueError(f"Error getting bars for {asset}: {e}")
ValueError: Error getting bars for SPY: You are requesting minute data from a daily data source. This is not supported.
2023-07-14 16:41:00,959: backtest_stats: INFO: Backtest took 0:02:08.247696 for a speed of 0.000
2023-07-14 16:41:00,962: root: WARNING: Cannot plot returns because the benchmark returns are missing
Creating indicators plot...
Creating tearsheet...
Traceback (most recent call last):
File "C:\Users\w4c\trading\lumibot\bot.py", line 25, in <module>
MyStrategy.backtest(
File "C:\Users\w4c\AppData\Roaming\Python\Python310\site-packages\lumibot\strategies\_strategy.py", line 1049, in backtest
strategy.tearsheet(
File "C:\Users\w4c\AppData\Roaming\Python\Python310\site-packages\lumibot\strategies\_strategy.py", line 695, in tearsheet
create_tearsheet(
File "C:\Users\w4c\AppData\Roaming\Python\Python310\site-packages\lumibot\tools\indicators.py", line 642, in create_tearsheet
_df2 = df2.copy()
AttributeError: 'NoneType' object has no attribute 'copy'
Kind regards
—
Reply to this email directly, view it on GitHub
<#256>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAIYQKYYIMQL6HG4NKOQZNTXQFLPPANCNFSM6AAAAAA2KNTAKM>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
--
Robert Grzesik 347-635-3416
|
|
@c0indev3l to fix the yahoo finance issue you should upgrade lumibot to the latest version for your initial question, did you replace "YOUR_POLYGON_API_KEY" with your actual polygon api key? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello,
raises
after changing API key I run into an other problem...
Kind regards
The text was updated successfully, but these errors were encountered: