-
-
Notifications
You must be signed in to change notification settings - Fork 644
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
How to access algorithm time for intraday strategies? #156
Comments
I don't fully understand what you mean by accessing algorithm time. If you want to avoid vectorbt to execute some signals within a specific period, you should manually disable any signal that comes within this period. vectorbt consumes everything the user gives him. If you're using from_signals, you should set entries and exits to False. If from_orders, you should set the size to np.nan. If from_order_func, there is |
I'm using the event driven mode using the framework you demonstrate here as a model. I'm not sure how to use
|
@BlackArbsCEO you need to create a pd.Series that has the same number of data points as your price, and where each element is a boolean that says whether this time step should be executed = a mask. You can achieve this with pandas (see https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.between_time.html). |
ok thanks. what about the situations where you want to filter entries by timestamp but you want to be able to exit on any timestamp once your trade is open? For example you only want to enter during the London Session (7am GMT to 3pm GMT) but you want to be able to exit at any time when your exit criteria is met (example a stop loss or profit target is hit during the Tokyo Session). |
Then instead of passing the activity mask directly to Portfolio.from_order_func, pass it to the function that decides when to buy/sell (segment_prep_func_nb, for example) and define your logic depending upon the mask you provided. There isn't one way of doing it, you need to figure it out yourself and be creative. |
ok thanks for the insight. I'm just unfamiliar with this methodology within the event driven framework, that's why I asked about the algorithm time which is what I'm most used to. |
Hello @polakowo and @BlackArbsCEO, The way I am approaching this is by creating datetime64 arrays which match the row number of my input price data and have the number of columns that would meet my sweep of times for each parameter as shown below. My apply function and indicator factory then look like this:
You can see that I am setting my entry/exit time parameter arrays to is_array_like and bc_to_input as true. I am doing this simply so that each array is seen as an array rather than a huge number of parameters I need to run through my indicator factory. When I run my indicator however, I get an error that reads:
I cannot get to the bottom of the issue. If I do not set any parameter settings I quickly run out of memory since I'm assuming it's thinking each one of my time arrays is composed of parameters that i am trying to sweep through the indicator, which I'm not. The idea at the end would be that I would create my entry signals by writing some statement similar to: RMA_strat_indicator."some output".index.tz_localize(None) > RMA_strat_indicator.entry_st to try all different combinations of entry times but I cannot get to this point due to the error. Any help as always would be greatly appreciated as I learn vectorbt. Thank you:) |
@forLinDre I fear the issue is on vectorbt's end. I haven't really tested datetime and timedelta arrays as parameters. I know the exact place where the error comes from and how to solve it, but unfortunately there is no workaround in the current version that you could use to circumvent this. Please provide this array as a regular input before I sort this out. |
@polakowo I see. Do you possibly know how others are approaching this problem? It's very common for intraday trading to wait for the market to settle prior to initiating trades. Usually the first 15 minutes or so. All other parameters should be optimized around these specific start/end times. If I were to temporarily feed a single set of times as inputs as you suggest, how would you go about making this work? From my example above, I have switched my numpy time arrays from parameters to inputs. But now when I create my entry signals using "RMA_strat_indicator.RMA1.index.tz_localize(None) >= RMA_strat_indicator.entry_st" I get an error stating "ValueError: Unable to coerce to Series, length must be 2: given 790". My entry start indicator looks like this: |
@forLinDre if your times are the same for each day, you can map each to a timestamp (integer) and then reverse map once you are back in pandas. I can't tell what the problem with your latest statement is, |
@polakowo, I am comparing the columns pictured with their index. Can one do that? I have 2 columns because I currently have two custom_EWM_window2 parameter values. I will have more columns once start hyper-optimization. Columns I'm comparing to the index: Non-working expression with error (Unable to coerce to Series, length must be 2: given 790): So based on your statement, they have the same index but of course they wouldn't have the same number of columns since one is the row index. Can you please specify where you would recommend appending .vbt exactly and how this is going to perform broadcasting to create the comparison? I tried appending it as shown below but received an error stating datetimeindex object has no attribut 'vbt'. |
Convert left object to series with the same index as on the right. |
@polakowo thanks for the help... again. I'm still learning python so some of these do not yet come naturally to me. Appreciate your time! |
Hi mate did you manage to get your code working? If so could you share an example please |
Please let me know if you can guide me on a similar issue. |
Is there a function/method that allows us to access the algorithm time? For example if you only want to accept trades during certain periods during the market session.
The text was updated successfully, but these errors were encountered: