3.5 MiB
3.5 MiB
In [1]:
from v2realbot.tools.loadbatch import load_batch from v2realbot.utils.utils import zoneNY import pandas as pd import numpy as np import vectorbtpro as vbt vbt.settings.set_theme("dark") vbt.settings['plotting']['layout']['width'] = 1280 vbt.settings.plotting.auto_rangebreaks = True # Set the option to display with pagination pd.set_option('display.notebook_repr_html', True) pd.set_option('display.max_rows', 10) # Number of rows per page
Activating profile profile1
Profile profile1 loaded successfully.
Current values: { 'AGG_EXCLUDED_TRADES': ['C', 'O', '4', 'B', '7', 'V', 'P', 'W', 'U', 'Z', 'F'], 'BT_DELAYS': { 'trigger_to_strat': 0.02, 'strat_to_sub': 0.023, 'sub_to_fill': 0.008, 'fill_to_not': 0.023, 'limit_order_offset': 0 }, 'BT_FILL_CONDITION_BUY_LIMIT': <FillCondition.SLOW: 'slow'>, 'BT_FILL_CONDITION_SELL_LIMIT': <FillCondition.SLOW: 'slow'>, 'BT_FILL_CONS_TRADES_REQUIRED': 2, 'BT_FILL_LOG_SURROUNDING_TRADES': 10, 'BT_FILL_PRICE_MARKET_ORDER_PREMIUM': 0.005, 'COUNT_API_REQUESTS': False, 'GROUP_TRADES_WITH_TIMESTAMP_LESS_THAN': 0.003, 'ILOG_SAVE_LEVEL_FROM': 1, 'LIVE_DATA_FEED': 'sip', 'NORMALIZED_TICK_BASE_PRICE': 30.0, 'OFFLINE_MODE': False, 'PROD_SERVER_HOSTNAMES': ['tradingeastcoast', 'David-MacBook-Pro.local'], 'QUIET_MODE': True, 'TEST_SERVER_HOSTNAMES': ['tradingtest'] }
config_handler.active_profile='profile1'
config handler initialized
Realtime Websocket connection will use FEED: sip and credential of ACCOUNT1
In [2]:
res, df = load_batch(batch_id="e44a5075", space_resolution_evenly=False, indicators_columns=["Rsi14"], main_session_only=True) if res < 0: print("Error" + str(res) + str(df)) df = df["bars"] df.info() df.head() #df.ptable() df
Resolution : 23
NOTE: DUPLICATES 100/3034 in bars. REMOVING.
Now there are 0/2934
<class 'pandas.core.frame.DataFrame'> DatetimeIndex: 2934 entries, 2024-03-11 09:30:00-04:00 to 2024-03-13 15:59:51-04:00 Data columns (total 8 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 Open 2934 non-null float64 1 High 2934 non-null float64 2 Low 2934 non-null float64 3 Close 2934 non-null float64 4 Volume 2934 non-null int64 5 Vwap 2934 non-null float64 6 updated 2934 non-null datetime64[ns, US/Eastern] 7 Rsi14 2934 non-null float64 dtypes: datetime64[ns, US/Eastern](1), float64(6), int64(1) memory usage: 270.8 KB
Out[2]:
<style scoped="">
.dataframe tbody tr th:only-of-type {
vertical-align: middle;
}
.dataframe tbody tr th {
vertical-align: top;
}
.dataframe thead th {
text-align: right;
}
</style>
| Open | High | Low | Close | Volume | Vwap | updated | Rsi14 | |
|---|---|---|---|---|---|---|---|---|
| time | ||||||||
| 2024-03-11 09:30:00-04:00 | 35.3900 | 35.440 | 35.2800 | 35.380 | 473759 | 35.425685 | 2024-03-11 09:30:23.673966885-04:00 | 0.0000 |
| 2024-03-11 09:30:23-04:00 | 35.3900 | 35.490 | 35.3895 | 35.475 | 14119 | 35.447393 | 2024-03-11 09:30:46.228593111-04:00 | 0.0000 |
| 2024-03-11 09:30:46-04:00 | 35.4750 | 35.480 | 35.4200 | 35.460 | 22169 | 35.448066 | 2024-03-11 09:31:09.993794918-04:00 | 0.0000 |
| 2024-03-11 09:31:09-04:00 | 35.4579 | 35.540 | 35.4400 | 35.535 | 29984 | 35.490282 | 2024-03-11 09:31:32.450469017-04:00 | 0.0000 |
| 2024-03-11 09:31:32-04:00 | 35.5350 | 35.595 | 35.5100 | 35.590 | 20348 | 35.560566 | 2024-03-11 09:31:55.688961983-04:00 | 0.0000 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 2024-03-13 15:58:19-04:00 | 36.1450 | 36.155 | 36.1300 | 36.145 | 120386 | 36.142679 | 2024-03-13 15:58:42.028856993-04:00 | 59.6001 |
| 2024-03-13 15:58:42-04:00 | 36.1500 | 36.150 | 36.1300 | 36.130 | 139068 | 36.139540 | 2024-03-13 15:59:05.012445927-04:00 | 58.2072 |
| 2024-03-13 15:59:05-04:00 | 36.1300 | 36.140 | 36.0900 | 36.090 | 545827 | 36.118307 | 2024-03-13 15:59:28.043910027-04:00 | 49.7763 |
| 2024-03-13 15:59:28-04:00 | 36.0950 | 36.110 | 36.0500 | 36.080 | 734354 | 36.072968 | 2024-03-13 15:59:51.012413979-04:00 | 37.3871 |
| 2024-03-13 15:59:51-04:00 | 36.0800 | 36.100 | 36.0650 | 36.070 | 321567 | 36.074857 | 2024-03-13 15:59:59.987827063-04:00 | 37.3871 |
2934 rows × 8 columns
FILTERING¶
In [209]:
#naloadujeme do vbt symbol as column basic_data = vbt.Data.from_data({"BAC": df}, tz_convert=zoneNY) start_date = pd.Timestamp('2024-03-12 09:30', tz=zoneNY) end_date = pd.Timestamp('2024-03-13 16:00', tz=zoneNY) #basic_data = basic_data.transform(lambda df: df[df.index.date == start_date.date()]) basic_data = basic_data.transform(lambda df: df[(df.index >= start_date) & (df.index <= end_date)]) basic_data.data["BAC"].info() filtered_data = basic_data.transform(lambda df: df[(df.index >= start_date) & (df.index <= end_date)]) # #range filtered_data = data[(data.index >= start_date) & (data.index <= end_date) filtered_data.data["BAC"].info() b= filtered_data.get().iloc[100:200] b.info() c = b[["Open","High"]] c.info() rsi14 = filtered_data.data["BAC"]["Rsi14"].rename("Rsi14") rsi14.vbt.plot().show() filtered_data.data["BAC"].vbt.ohlcv.plot().show()
<class 'pandas.core.frame.DataFrame'> DatetimeIndex: 1961 entries, 2024-03-12 09:30:00-04:00 to 2024-03-13 15:59:51-04:00 Data columns (total 8 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 Open 1961 non-null float64 1 High 1961 non-null float64 2 Low 1961 non-null float64 3 Close 1961 non-null float64 4 Volume 1961 non-null int64 5 Vwap 1961 non-null float64 6 updated 1961 non-null datetime64[ns, US/Eastern] 7 Rsi14 1961 non-null float64 dtypes: datetime64[ns, US/Eastern](1), float64(6), int64(1) memory usage: 137.9 KB <class 'pandas.core.frame.DataFrame'> DatetimeIndex: 1961 entries, 2024-03-12 09:30:00-04:00 to 2024-03-13 15:59:51-04:00 Data columns (total 8 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 Open 1961 non-null float64 1 High 1961 non-null float64 2 Low 1961 non-null float64 3 Close 1961 non-null float64 4 Volume 1961 non-null int64 5 Vwap 1961 non-null float64 6 updated 1961 non-null datetime64[ns, US/Eastern] 7 Rsi14 1961 non-null float64 dtypes: datetime64[ns, US/Eastern](1), float64(6), int64(1) memory usage: 137.9 KB <class 'pandas.core.frame.DataFrame'> DatetimeIndex: 100 entries, 2024-03-12 10:09:00-04:00 to 2024-03-12 10:47:24-04:00 Data columns (total 8 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 Open 100 non-null float64 1 High 100 non-null float64 2 Low 100 non-null float64 3 Close 100 non-null float64 4 Volume 100 non-null int64 5 Vwap 100 non-null float64 6 updated 100 non-null datetime64[ns, US/Eastern] 7 Rsi14 100 non-null float64 dtypes: datetime64[ns, US/Eastern](1), float64(6), int64(1) memory usage: 7.0 KB <class 'pandas.core.frame.DataFrame'> DatetimeIndex: 100 entries, 2024-03-12 10:09:00-04:00 to 2024-03-12 10:47:24-04:00 Data columns (total 2 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 Open 100 non-null float64 1 High 100 non-null float64 dtypes: float64(2) memory usage: 2.3 KB
In [210]:
run_rsi = vbt.talib_func("rsi") rsi_new = run_rsi(basic_data.vwap, timeperiod=15) rsi_new = rsi_new.fillna(0) print(rsi_new) print(dir(rsi_new)) rsi14 = basic_data.data["BAC"]["Rsi14"] print(rsi14) combined_df = pd.concat([rsi_new, rsi14], axis=1) combined_df plot_rsi = vbt.talib_plot_func("rsi") plot_rsi(rsi_new).show() plot_rsi(rsi14).show()
time
2024-03-12 09:30:00-04:00 0.000000
2024-03-12 09:30:23-04:00 0.000000
2024-03-12 09:30:47-04:00 0.000000
2024-03-12 09:31:11-04:00 0.000000
2024-03-12 09:31:34-04:00 0.000000
...
2024-03-13 15:58:19-04:00 59.600097
2024-03-13 15:58:42-04:00 58.207248
2024-03-13 15:59:05-04:00 49.776325
2024-03-13 15:59:28-04:00 37.387129
2024-03-13 15:59:51-04:00 38.075336
Name: Vwap, Length: 1961, dtype: float64
['T', '_AXIS_LEN', '_AXIS_ORDERS', '_AXIS_TO_AXIS_NUMBER', '_HANDLED_TYPES', '__abs__', '__add__', '__and__', '__annotations__', '__array__', '__array_priority__', '__array_ufunc__', '__bool__', '__class__', '__column_consortium_standard__', '__contains__', '__copy__', '__deepcopy__', '__delattr__', '__delitem__', '__dict__', '__dir__', '__divmod__', '__doc__', '__eq__', '__finalize__', '__float__', '__floordiv__', '__format__', '__ge__', '__getattr__', '__getattribute__', '__getitem__', '__getstate__', '__gt__', '__hash__', '__iadd__', '__iand__', '__ifloordiv__', '__imod__', '__imul__', '__init__', '__init_subclass__', '__int__', '__invert__', '__ior__', '__ipow__', '__isub__', '__iter__', '__itruediv__', '__ixor__', '__le__', '__len__', '__lt__', '__matmul__', '__mod__', '__module__', '__mul__', '__ne__', '__neg__', '__new__', '__nonzero__', '__or__', '__pandas_priority__', '__pos__', '__pow__', '__radd__', '__rand__', '__rdivmod__', '__reduce__', '__reduce_ex__', '__repr__', '__rfloordiv__', '__rmatmul__', '__rmod__', '__rmul__', '__ror__', '__round__', '__rpow__', '__rsub__', '__rtruediv__', '__rxor__', '__setattr__', '__setitem__', '__setstate__', '__sizeof__', '__str__', '__sub__', '__subclasshook__', '__truediv__', '__weakref__', '__xor__', '_accessors', '_accum_func', '_agg_examples_doc', '_agg_see_also_doc', '_align_for_op', '_align_frame', '_align_series', '_append', '_arith_method', '_as_manager', '_attrs', '_binop', '_can_hold_na', '_check_inplace_and_allows_duplicate_labels', '_check_is_chained_assignment_possible', '_check_label_or_level_ambiguity', '_check_setitem_copy', '_clear_item_cache', '_clip_with_one_bound', '_clip_with_scalar', '_cmp_method', '_consolidate', '_consolidate_inplace', '_construct_axes_dict', '_construct_result', '_constructor', '_constructor_expanddim', '_constructor_expanddim_from_mgr', '_constructor_from_mgr', '_data', '_deprecate_downcast', '_dir_additions', '_dir_deletions', '_drop_axis', '_drop_labels_or_levels', '_duplicated', '_expanddim_from_mgr', '_find_valid_index', '_flags', '_flex_method', '_from_mgr', '_get_axis', '_get_axis_name', '_get_axis_number', '_get_axis_resolvers', '_get_block_manager_axis', '_get_bool_data', '_get_cacher', '_get_cleaned_column_resolvers', '_get_index_resolvers', '_get_label_or_level_values', '_get_numeric_data', '_get_rows_with_mask', '_get_value', '_get_values_tuple', '_get_with', '_getitem_slice', '_gotitem', '_hidden_attrs', '_indexed_same', '_info_axis', '_info_axis_name', '_info_axis_number', '_init_dict', '_init_mgr', '_inplace_method', '_internal_names', '_internal_names_set', '_is_cached', '_is_copy', '_is_label_or_level_reference', '_is_label_reference', '_is_level_reference', '_is_mixed_type', '_is_view', '_is_view_after_cow_rules', '_item_cache', '_ixs', '_logical_func', '_logical_method', '_map_values', '_maybe_update_cacher', '_memory_usage', '_metadata', '_mgr', '_min_count_stat_function', '_name', '_needs_reindex_multi', '_pad_or_backfill', '_protect_consolidate', '_reduce', '_references', '_reindex_axes', '_reindex_indexer', '_reindex_multi', '_reindex_with_indexers', '_rename', '_replace_single', '_repr_data_resource_', '_repr_latex_', '_reset_cache', '_reset_cacher', '_set_as_cached', '_set_axis', '_set_axis_name', '_set_axis_nocheck', '_set_is_copy', '_set_labels', '_set_name', '_set_value', '_set_values', '_set_with', '_set_with_engine', '_shift_with_freq', '_slice', '_stat_function', '_stat_function_ddof', '_take_with_is_copy', '_to_latex_via_styler', '_typ', '_update_inplace', '_validate_dtype', '_values', '_where', 'abs', 'add', 'add_prefix', 'add_suffix', 'agg', 'aggregate', 'align', 'all', 'any', 'apply', 'argmax', 'argmin', 'argsort', 'array', 'asfreq', 'asof', 'astype', 'at', 'at_time', 'attrs', 'autocorr', 'axes', 'backfill', 'between', 'between_time', 'bfill', 'bool', 'case_when', 'clip', 'combine', 'combine_first', 'compare', 'convert_dtypes', 'copy', 'corr', 'count', 'cov', 'cummax', 'cummin', 'cumprod', 'cumsum', 'describe', 'diff', 'div', 'divide', 'divmod', 'dot', 'drop', 'drop_duplicates', 'droplevel', 'dropna', 'dtype', 'dtypes', 'duplicated', 'empty', 'eq', 'equals', 'ewm', 'expanding', 'explode', 'factorize', 'ffill', 'fillna', 'filter', 'first', 'first_valid_index', 'flags', 'floordiv', 'ge', 'get', 'groupby', 'gt', 'hasnans', 'head', 'hist', 'iat', 'idxmax', 'idxmin', 'iloc', 'index', 'infer_objects', 'info', 'interpolate', 'is_monotonic_decreasing', 'is_monotonic_increasing', 'is_unique', 'isin', 'isna', 'isnull', 'item', 'items', 'keys', 'kurt', 'kurtosis', 'last', 'last_valid_index', 'le', 'list', 'loc', 'lt', 'map', 'mask', 'max', 'mean', 'median', 'memory_usage', 'min', 'mod', 'mode', 'mul', 'multiply', 'name', 'nbytes', 'ndim', 'ne', 'nlargest', 'notna', 'notnull', 'nsmallest', 'nunique', 'pad', 'pct_change', 'pipe', 'plot', 'pop', 'pow', 'prod', 'product', 'quantile', 'radd', 'rank', 'ravel', 'rdiv', 'rdivmod', 'reindex', 'reindex_like', 'rename', 'rename_axis', 'reorder_levels', 'repeat', 'replace', 'resample', 'reset_index', 'rfloordiv', 'rmod', 'rmul', 'rolling', 'round', 'rpow', 'rsub', 'rtruediv', 'sample', 'searchsorted', 'sem', 'set_axis', 'set_flags', 'shape', 'shift', 'size', 'skew', 'sort_index', 'sort_values', 'squeeze', 'std', 'struct', 'sub', 'subtract', 'sum', 'swapaxes', 'swaplevel', 'tail', 'take', 'to_clipboard', 'to_csv', 'to_dict', 'to_excel', 'to_frame', 'to_hdf', 'to_json', 'to_latex', 'to_list', 'to_markdown', 'to_numpy', 'to_period', 'to_pickle', 'to_sql', 'to_string', 'to_timestamp', 'to_xarray', 'transform', 'transpose', 'truediv', 'truncate', 'tz_convert', 'tz_localize', 'unique', 'unstack', 'update', 'value_counts', 'values', 'var', 'vbt', 'view', 'where', 'xs']
time
2024-03-12 09:30:00-04:00 70.6588
2024-03-12 09:30:23-04:00 74.0781
2024-03-12 09:30:47-04:00 76.6184
2024-03-12 09:31:11-04:00 81.0538
2024-03-12 09:31:34-04:00 86.0863
...
2024-03-13 15:58:19-04:00 59.6001
2024-03-13 15:58:42-04:00 58.2072
2024-03-13 15:59:05-04:00 49.7763
2024-03-13 15:59:28-04:00 37.3871
2024-03-13 15:59:51-04:00 37.3871
Name: Rsi14, Length: 1961, dtype: float64
In [211]:
entries = rsi_new.vbt.crossed_below(30) entries
Out[211]:
time
2024-03-12 09:30:00-04:00 False
2024-03-12 09:30:23-04:00 False
2024-03-12 09:30:47-04:00 False
2024-03-12 09:31:11-04:00 False
2024-03-12 09:31:34-04:00 False
...
2024-03-13 15:58:19-04:00 False
2024-03-13 15:58:42-04:00 False
2024-03-13 15:59:05-04:00 False
2024-03-13 15:59:28-04:00 False
2024-03-13 15:59:51-04:00 False
Name: Vwap, Length: 1961, dtype: bool
In [212]:
exits = rsi_new.vbt.crossed_above(70) exits
Out[212]:
time
2024-03-12 09:30:00-04:00 False
2024-03-12 09:30:23-04:00 False
2024-03-12 09:30:47-04:00 False
2024-03-12 09:31:11-04:00 False
2024-03-12 09:31:34-04:00 False
...
2024-03-13 15:58:19-04:00 False
2024-03-13 15:58:42-04:00 False
2024-03-13 15:59:05-04:00 False
2024-03-13 15:59:28-04:00 False
2024-03-13 15:59:51-04:00 False
Name: Vwap, Length: 1961, dtype: bool
In [213]:
def plot_rsi(close, rsi, entries, exits): fig = vbt.make_subplots(rows=2, cols=1, shared_xaxes=True, specs=[[{"secondary_y": True}], [{"secondary_y": False}]]) basic_data.data["BAC"].vbt.ohlcv.plot(add_trace_kwargs=dict(row=1, col=1, secondary_y=True),fig=fig) rsi.vbt.plot(fig=fig, add_trace_kwargs=dict(row=1, col=1, secondary_y=False), trace_kwargs=dict(line=dict(color='grey', width=1.5))) #close.vbt.plot(fig=fig, add_trace_kwargs=dict(row=1, col=1, secondary_y=True)) entries.vbt.signals.plot_as_entries(y=close, fig=fig, add_trace_kwargs=dict(row=1, col=1, secondary_y=True)) exits.vbt.signals.plot_as_exits(y=close, fig=fig, add_trace_kwargs=dict(row=1, col=1, secondary_y=True)) return fig close = basic_data.get("Close") print(entries) plot_rsi(close, rsi_new, entries, exits).show() clean_entries, clean_exits = entries.vbt.signals.clean(exits) plot_rsi(close, rsi_new, clean_entries, clean_exits).show()
time
2024-03-12 09:30:00-04:00 False
2024-03-12 09:30:23-04:00 False
2024-03-12 09:30:47-04:00 False
2024-03-12 09:31:11-04:00 False
2024-03-12 09:31:34-04:00 False
...
2024-03-13 15:58:19-04:00 False
2024-03-13 15:58:42-04:00 False
2024-03-13 15:59:05-04:00 False
2024-03-13 15:59:28-04:00 False
2024-03-13 15:59:51-04:00 False
Name: Vwap, Length: 1961, dtype: bool
In [214]:
clean_entries.vbt.signals.total() clean_exits.vbt.signals.total()
Out[214]:
12
In [205]:
index = basic_data.wrapper.index #minutes from market open market_open_time = pd.to_timedelta('09:30:00') # Calculate the market open datetime for each day market_opens = index.normalize() + market_open_time minutes_from_open = (index - market_opens).total_seconds() / 60 # Ensuring the result is a Series minutes_from_open = pd.Series(minutes_from_open, index=index) #minutes_from_open.values
In [206]:
symbol_wrapper = basic_data.get_symbol_wrapper() @vbt.njit def elapsed_minutes_from_open_nb(time_in_ns): market_open_minutes = 570 # 9 hours * 60 minutes + 30 minutes current_minutes = vbt.dt_nb.hour_nb(time_in_ns) * 60 + vbt.dt_nb.minute_nb(time_in_ns) #print("current_minutes", current_minutes) # Calculate elapsed minutes since market open at 9:30 AM elapsed_minutes = current_minutes - market_open_minutes print( "elapsed_from_open", elapsed_minutes) return elapsed_minutes if elapsed_minutes >= 0 else 0 @vbt.njit def entry_place_func_nb(c, low, close, time_in_ns, rsi14, window_open, window_close): # if c.from_i == 0: # (1)! # c.out[0] = True # return -1 # print("ted") # print(c.from_i) #exit_i = c.from_i - c.wait # (2)! #exit_price = close[exit_i, c.col] # (3)! #hit_price = exit_price * (1 - th) market_open_minutes = 570 # 9 hours * 60 minutes + 30 minutes for out_i in range(len(c.out)): i = c.from_i + out_i current_minutes = vbt.dt_nb.hour_nb(time_in_ns[i]) * 60 + vbt.dt_nb.minute_nb(time_in_ns[i]) #print("current_minutes", current_minutes) # Calculate elapsed minutes since market open at 9:30 AM elapsed_from_open = current_minutes - market_open_minutes elapsed_from_open = elapsed_from_open if elapsed_from_open >= 0 else 0 #print( "elapsed_from_open", elapsed_from_open) #elapsed_from_open = elapsed_minutes_from_open_nb(time_in_ns) in_window = elapsed_from_open > window_open and elapsed_from_open < window_close #print("in_window", in_window) # if in_window: # print("in window") if in_window and rsi14[i] > 60: # and low[i, c.col] <= hit_price: # and hour == 9: # (4)! return out_i return -1 #whether the date changed # day_changed_nb( # ts1, # ts2 # ) # h_ns(ts1) int @vbt.njit def exit_place_func_nb(c, high, close, time_index, tp, sl): # (5)! entry_i = c.from_i - c.wait entry_price = close[entry_i, c.col] hit_price = entry_price * (1 + tp) stop_price = entry_price * (1 - sl) for out_i in range(len(c.out)): i = c.from_i + out_i last_bar_of_day = vbt.dt_nb.day_changed_nb(time_index[i], time_index[i + 1]) #print(next_day) if last_bar_of_day: #pokud je dalsi next day, tak zavirame posledni print("ted",out_i) return out_i if high[i, c.col] >= hit_price or close[i, c.col] <= stop_price : return out_i return -1 index = basic_data.wrapper.index #minutes from market open market_open_time = pd.to_timedelta('09:30:00') # Calculate the market open datetime for each day market_opens = index.normalize() + market_open_time minutes_from_open = (index - market_opens).total_seconds() / 60 print(minutes_from_open) #index 9:30 az 10:00 time_entry_window = ((index.time >= pd.Timestamp("09:30:00").time())& (index.time <= pd.Timestamp("14:00:00").time())) print(time_entry_window) print(rsi_new) rsi_entries = rsi_new.vbt.crossed_below(64) rsi_entries = rsi_entries < 40 rsi_entries_array = rsi_entries.vbt.to_1d_array() print(rsi_entries_array) entries, exits = vbt.pd_acc.signals.generate_both( # (6)! symbol_wrapper.shape, entry_place_func_nb=entry_place_func_nb, #timeindex to ns to numba entry_place_args=(vbt.Rep("low"), vbt.Rep("close"), vbt.dt.to_ns(basic_data.wrapper.index), vbt.Rep("rsi14"), 0, 380), # (7)! exit_place_func_nb=exit_place_func_nb, exit_place_args=(vbt.Rep("high"), vbt.Rep("close"), vbt.dt.to_ns(basic_data.wrapper.index), 0.001, 0.001), wrapper=symbol_wrapper, broadcast_named_args=dict( # (8)! high=basic_data.get("High"), low=basic_data.get("Low"), close=basic_data.get("Close"), rsi14=basic_data.get("Rsi14"), window_open=10, window_close=60 ), broadcast_kwargs=dict(post_func=np.asarray) # (9)! ) plot_rsi(close, rsi_new, entries, exits).show() # fig = basic_data.plot( # symbol="BAC", # ohlc_trace_kwargs=dict(opacity=0.5), # plot_volume=False # ) # #rsi_entries.vbt.plot(fig=fig) # entries.vbt.signals.plot_as_entries( # y=close, fig=fig) # exits.vbt.signals.plot_as_exits( # y=close, fig=fig) # fig.show() # (10)!
Index([ 0.0, 0.38333333333333336, 0.7833333333333333,
1.1833333333333333, 1.5666666666666667, 2.0,
2.3833333333333333, 2.7666666666666666, 3.15,
3.566666666666667,
...
386.4, 386.78333333333336, 387.1666666666667,
387.55, 387.93333333333334, 388.31666666666666,
388.7, 389.0833333333333, 389.46666666666664,
389.85],
dtype='float64', name='time', length=1961)
[ True True True ... False False False]
time
2024-03-12 09:30:00-04:00 0.000000
2024-03-12 09:30:23-04:00 0.000000
2024-03-12 09:30:47-04:00 0.000000
2024-03-12 09:31:11-04:00 0.000000
2024-03-12 09:31:34-04:00 0.000000
...
2024-03-13 15:58:19-04:00 59.600097
2024-03-13 15:58:42-04:00 58.207248
2024-03-13 15:59:05-04:00 49.776325
2024-03-13 15:59:28-04:00 37.387129
2024-03-13 15:59:51-04:00 38.075336
Name: Vwap, Length: 1961, dtype: float64
[ True True True ... True True True]