-
Notifications
You must be signed in to change notification settings - Fork 177
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
UnboundLocalError: cannot access local variable 'loop_limit' where it is not associated with a value #341
Comments
It appears that 'loop_limit' has no default value, and isn't getting set if 'start' is not none. https://github.com/Lumiwealth/lumibot/blob/dev/lumibot/data_sources/alpaca_data.py |
Thanks for sharing this bug, I will take a look into it soon. In general,
we have not implemented the “X minutes” or “X days” parameter for every
broker yet, and I think we need to add it for Alpaca.
This should be a fairly easy fix but will take a few days to get to. In the
meantime you can simply query for single minutes and aggregate the data
using pandas agg() function, ChatGPT can help with this.
Robert Grzesik 347-635-3416
…On Wed, Jan 3, 2024 at 3:14 PM Jesse Jones ***@***.***> wrote:
It appears that 'loop_limit' has no default value, and isn't getting set
if 'start' is not none.
https://github.com/Lumiwealth/lumibot/blob/dev/lumibot/data_sources/alpaca_data.py
—
Reply to this email directly, view it on GitHub
<#341 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAIYQK5FMAEORU6I77NZXXTYMW3ZHAVCNFSM6AAAAABBL462XKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNZVHEYTGNRWHE>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
@grzesir Thanks for the reply. That would make sense if it's not implemented yet :D I was looking around to see if I could implement a solution but not currently confident enough in python to try and do something I could commit. I am currently using 1 minute increments but didn't know about the pandas agg() function. Appreciate the feedback! |
No problem Jesse. This should be implemented in the next week or two but if
you need help setting up the aggregate function, just let me know. ChatGPT
is also a huge help in this regard.
Robert Grzesik 347-635-3416
…On Wed, Jan 3, 2024 at 4:51 PM Jesse Jones ***@***.***> wrote:
@grzesir <https://github.com/grzesir> Thanks for the reply.
That would make sense if it's not implemented yet :D I was looking around
to see if I could implement a solution but not currently confident enough
in python to try and do something I could commit.
I am currently using 1 minute increments but didn't know about the pandas
agg() function. Appreciate the feedback!
—
Reply to this email directly, view it on GitHub
<#341 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAIYQK2XFHKFGUMRZO6Y2V3YMXHEZAVCNFSM6AAAAABBL462XKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNZWGAYTOMRYGA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
@grzesir ChatGPT has been a trainwreck LOL. I don't think it fully understands Pandas and the DataFrame's. Maybe I am just using it wrong. I have been playing with it all day and have just now gotten things working properly as I was needing them. It took some work, but having a final result is a good reward. How would one go about contributing to the lumibot docs page? I see a few things that are off (or didn't work). As a sign of appreciation for your library I would be happy to make some fixes and maybe add some code examples that I got working for future users. Example: https://lumibot.lumiwealth.com/backtesting.polygon.html
Should be:
Thanks. |
Hey Jesse, what prompt did you use with chatgpt? It’s a very simple set of
code to write. Simply tell chatgpt that you have a dataframe with ohlc data
in minutes and you need to aggregate it to 5 minute intervals.
As for the docs, we have a pretty big docs update coming out soon, just
waiting for approval from another dev on the team. That being said, maybe
we missed a few things. Some things that are getting updated are all the
Backtesting examples. Anything else that’s missing?
You can submit a pull request to update the docs if you’d like, or you can
also let me know here.
Robert Grzesik 347-635-3416
…On Wed, Jan 3, 2024 at 8:24 PM Jesse Jones ***@***.***> wrote:
@grzesir <https://github.com/grzesir> ChatGPT has been a trainwreck LOL.
I don't think it fully understands Pandas and the DataFame's. Maybe I am
just using it wrong.
I have been playing with it all day and have just not gotten things
working properly as I was needing them. It took some work, but having a
final result is a good reward.
How would one go about contributing to the lumibot docs page? I see a few
things that are off (or didn't work). As a sign of appreciation for your
library I would be happy to make some fixes and maybe add some code
examples that I got working for future users.
Example: https://lumibot.lumiwealth.com/backtesting.polygon.html
Here’s another example but for for stocks:
my_strat = MyStrategy(
broker=broker,
backtesting_start=backtesting_start,
backtesting_end=backtesting_end,
benchmark_asset=Asset(symbol="BTC", asset_type="crypto")
)
Should be:
my_strat = MyStrategy(
broker=broker,
backtesting_start=backtesting_start,
backtesting_end=backtesting_end,
benchmark_asset=Asset(symbol="SPY", asset_type="stock")
)
Thanks.
—
Reply to this email directly, view it on GitHub
<#341 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAIYQK37Z5JU5ZZSCPYSTG3YMYAE5AVCNFSM6AAAAABBL462XKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNZWGE4DINBQGA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
@grzesir I tried several different prompts. It's not that the output wasn't helpful, it was that chatgpt didn't seem to know how to properly call the DataFrame constructor with all the needed parameters. I ended up finding a solution more closely related to the examples on the docs, but just a bit different, which means I didn't even use the output from chatgpt. I also didn't include anything about ohlc, completely slipped my mind to include :/ I don't want to keep cluttering this submission up, but know I appreciate your timely and helpful responses. I will be jumping into the discord, can provide some of the feedback on issues I was having from the docs. Thanks! |
That makes sense, the bit about ohlc data is crucial to the prompt. If you
want you can post your code here and I can show you how to modify it to use
aggregate data
Robert Grzesik 347-635-3416
…On Wed, Jan 3, 2024 at 8:56 PM Jesse Jones ***@***.***> wrote:
@grzesir <https://github.com/grzesir> I tried several different prompts.
It's not that the output wasn't helpful, it was that chatgpt didn't seem to
know how to properly call the DataFrame constructor with all the needed
parameters. I ended up finding a solution more closely related to the
examples on the docs, but just a bit different, which means I didn't even
use the output from chatgpt.
I also didn't include anything about ohlc, completely slipped my mind to
include :/
I don't want to keep cluttering this submission up, but know I appreciate
your timely and helpful responses. I will be jumping into the discord, can
provide some of the feedback on issues I was having from the docs.
Thanks!
—
Reply to this email directly, view it on GitHub
<#341 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAIYQKZIYXV2CAP5RVCYRI3YMYD6LAVCNFSM6AAAAABBL462XKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNZWGIYDKMRZHA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
@grzesir Appreciate it. This is what I got working
The example here: https://lumibot.lumiwealth.com/strategy_methods.data/lumibot.strategies.strategy.Strategy.get_historical_prices_for_assets.html
Just didn't seem to work. It would throw the error asset has no df. Guessing it's a setup issue on my end. But I got it working one way or another :D |
This code works fine for me during backtesting. However, if you have issues
with it running live on Alpaca I can understand why: the markets are
currently closed and there is likely no data within the past 45
minutes. include_after_hours=False only applies to Interactive Brokers, not
Alpaca (but even if it did, I don't think it works the way you think it
does). There are 2 ways thats you can handle this:
1. Make sure that you only run your strategy during market hours. That
means removing code such as self.set_market("24/7") from initialize.
2. Get more than 45 bars of data (eg. 1080 minutes), which will get you
data most days even very late at night. Then truncate the data to only the
times you want using loc[] or iloc[], and aggregate afterwards.
Also, as a side note, it seems like you're trying to run your strategy live
immediately before back testing. I would strongly recommend that you back
test your strategy first before running live because you will not have to
deal with situations like this, and you can focus more directly on
improving your strategy from the very beginning
Robert Grzesik
347-635-3416
…On Wed, Jan 3, 2024 at 9:49 PM Jesse Jones ***@***.***> wrote:
@grzesir <https://github.com/grzesir> Appreciate it. This is what I got
working
# Get 3, 15 minute blocks of data for multiple symbols
TickersToWatch = ["SPY","AAPL"]
data = self.get_historical_prices_for_assets(TickersToWatch, 45, "minute", include_after_hours=False)
# Resample Bars data into 15 minute samples.
for i,v in data.items():
df = v.df
resampled_df = df.resample('15T').agg({
'open': 'first',
'high': 'max',
'low': 'min',
'close': 'last',
'volume': 'sum'
}).dropna()
print(resampled_df)
The example here:
https://lumibot.lumiwealth.com/strategy_methods.data/lumibot.strategies.strategy.Strategy.get_historical_prices_for_assets.html
# Get the data for AAPL and GOOG for the last 30 minutes
bars = self.get_historical_prices_for_assets(["AAPL", "GOOG"], 30, "minute")
for asset in bars:
self.log_message(asset.df)
Just didn't seem to work. It would throw the error asset has no df.
Guessing it's a setup issue on my end. But I got it working one way or
another :D
—
Reply to this email directly, view it on GitHub
<#341 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAIYQK3RF6AXRW3FMVE55NTYMYKB5AVCNFSM6AAAAABBL462XKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNZWGIZTOMZRGQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
@grzesir I am currently running backtesting using Polygon for the data. My plan is to run my strategy every 15 minutes during live market. starting with paper of course. Now that I am getting the data how I want it, I am working on building out the buy/sell logics. |
@grzesir fatal: unable to access 'https://github.com/Lumiwealth/lumibot.git/': The requested URL returned error: 403 |
There appears to be an error from get_historical_prices when specifying a timestep other than 'minute' 'day' etc.
outputs error
I followed the documentation here: https://lumibot.lumiwealth.com/strategy_methods.data/lumibot.strategies.strategy.Strategy.get_historical_prices.html
The text was updated successfully, but these errors were encountered: