Compare commits

...

3 Commits

Author SHA1 Message Date
3152fcb0b5 daily fix 2024-10-17 09:30:05 +02:00
58b6bde651 fix 2024-10-16 20:36:01 +02:00
cc91d106c3 fix 2024-10-16 20:23:58 +02:00

View File

@ -1,5 +1,6 @@
- [FETCHING DATA](#fetching-data) - [FETCHING DATA](#fetching-data)
- [REINDEX to main session](#reindex-to-main-session) - [REINDEX to main session](#reindex-to-main-session)
- [indexing](#indexing)
- [DISCOVERY](#discovery) - [DISCOVERY](#discovery)
- [DATA/WRAPPER](#datawrapper) - [DATA/WRAPPER](#datawrapper)
- [create WRAPPER manually](#create-wrapper-manually) - [create WRAPPER manually](#create-wrapper-manually)
@ -10,8 +11,8 @@
- [SIGNALS](#signals) - [SIGNALS](#signals)
- [ENTRIES/EXITS time based](#entriesexits-time-based) - [ENTRIES/EXITS time based](#entriesexits-time-based)
- [STOPS](#stops) - [STOPS](#stops)
- [OHLCSTX module](#ohlcstx-module) - [OHLCSTX Module](#ohlcstx-module)
- [ENTRY WINDOW and FORCED EXIT WINDOW](#entry-window-and-forced-exit-window) - [Entry Window and Forced Exit Window](#entry-window-and-forced-exit-window)
- [END OF DAY EXITS](#end-of-day-exits) - [END OF DAY EXITS](#end-of-day-exits)
- [REGULAR EXITS](#regular-exits) - [REGULAR EXITS](#regular-exits)
- [DF/SR ACCESSORS](#dfsr-accessors) - [DF/SR ACCESSORS](#dfsr-accessors)
@ -95,7 +96,10 @@ testData = vbt.YFData.fetch(['MSFT'], start=start, end=end, timeframe=timeframe,
# of market hours) # of market hours)
testData = testData.transform(lambda x: x.reindex(market_klines)) testData = testData.transform(lambda x: x.reindex(market_klines))
``` ```
## indexing
```python
entries.vbt.xloc[slice("2024-08-01","2024-08-03")].obj.info()
```
# DISCOVERY # DISCOVERY
```python ```python
@ -235,8 +239,9 @@ mask.sum()
```python ```python
#create entries/exits based on open of first symbol #create entries/exits based on open of first symbol
entries = pd.DataFrame.vbt.signals.empty_like(data.open.iloc[:,0]) entries = pd.DataFrame.vbt.signals.empty_like(data.open.iloc[:,0])
exits = pd.DataFrame.vbt.signals.empty_like(entries)
#create entries/exits based on symbol level #OR create entries/exits based on symbol level if needed (for each columns)
symbol_wrapper = data.get_symbol_wrapper() symbol_wrapper = data.get_symbol_wrapper()
entries = symbol_wrapper.fill(False) entries = symbol_wrapper.fill(False)
exits = symbol_wrapper.fill(False) exits = symbol_wrapper.fill(False)
@ -257,7 +262,6 @@ exits.vbt.set(
) )
``` ```
## STOPS ## STOPS
[doc from_signal](http://5.161.179.223:8000/vbt-doc/api/portfolio/base/#vectorbtpro.portfolio.base.Portfolio.from_signals) [doc from_signal](http://5.161.179.223:8000/vbt-doc/api/portfolio/base/#vectorbtpro.portfolio.base.Portfolio.from_signals)
@ -268,14 +272,16 @@ price = close.vbt.wrapper.fill()
price[entries] = entry_price price[entries] = entry_price
price[exits] = exit_price price[exits] = exit_price
## OHLCSTX module ## OHLCSTX Module
- exit signal generator based on price and stop values - exit signal generator based on price and stop values
[doc](ttp://5.161.179.223:8000/vbt-doc/api/signals/generators/ohlcstx/index.html) [doc](ttp://5.161.179.223:8000/vbt-doc/api/signals/generators/ohlcstx/index.html)
## ENTRY WINDOW and FORCED EXIT WINDOW ## Entry Window and Forced Exit Window
Applying `entry window `range (denoted by minutes from the session start) to `entries` and applying `forced exit window` to `exits`. Applying `entry window `range (denoted by minutes from the session start) to `entries` and applying `forced exit window` to `exits`.
`create_mask_from_window` with param `use_cal=True` (default) uses market calendar data for each day to denote session start and end. When disabled it uses just fixed 9:30-16:00 for each day.
```python ```python
from ttools import create_mask_from_window from ttools import create_mask_from_window
@ -285,12 +291,12 @@ forced_exit_start = 387
forced_exit_end = 390 forced_exit_end = 390
#create mask based on main session that day #create mask based on main session that day
entry_window_opened = create_mask_from_window(entries, entry_window_opens, entry_window_closes) entry_window_opened = create_mask_from_window(entries, entry_window_opens, entry_window_closes, use_cal=True)
#limit entries to the window #limit entries to the window
entries = entries & entry_window_opened entries = entries & entry_window_opened
#create forced exits mask #create forced exits mask
forced_exits_window = create_mask_from_window(exits, forced_exit_start, forced_exit_end) forced_exits_window = create_mask_from_window(exits, forced_exit_start, forced_exit_end, use_cal=True)
#add forced_exits to exits #add forced_exits to exits
exits = exits | forced_exits_window exits = exits | forced_exits_window
@ -309,6 +315,10 @@ exits = t1data.get_symbol_wrapper().fill(False)
exits.loc[last_n_daily_rows.index] = True exits.loc[last_n_daily_rows.index] = True
#visualize #visualize
t1data.ohlcv.data["BAC"].lw.plot(right=[(t1data.close,"close",exits)], size="s") t1data.ohlcv.data["BAC"].lw.plot(right=[(t1data.close,"close",exits)], size="s")
#which is ALTERNATIVE to
exits = create_mask_from_window(t1data.close, 387, 390, use_cal=False)
t1data.ohlcv.data["BAC"].lw.plot(right=[(t1data.close,"close",exits)], size="s")
``` ```
## REGULAR EXITS ## REGULAR EXITS
Time based. Time based.
@ -327,11 +337,11 @@ exits.vbt.set(
# DF/SR ACCESSORS # DF/SR ACCESSORS
## Generic ## Generic
- for common taks ([docs](http://5.161.179.223:8000/vbt-doc/api/generic/accessors/index.html#vectorbtpro.generic.accessors.GenericAccessor)) For common taks ([docs](http://5.161.179.223:8000/vbt-doc/api/generic/accessors/index.html#vectorbtpro.generic.accessors.GenericAccessor))
`rolling_apply` - runs custom function over a rolling window of a fixed size (number of bars or frequency) * `rolling_apply` - runs custom function over a rolling window of a fixed size (number of bars or frequency)
`expanding_apply` - runs custome function over expanding the window from the start of the data to the current poin * `expanding_apply` - runs custome function over expanding the window from the start of the data to the current poin
```python ```python
from numba import njit from numba import njit
@ -340,6 +350,7 @@ hourly_anchored_expanding_mean = t1data.close.vbt.rolling_apply("1H", mean_nb) #
t1data.ohlcv.data["BAC"].lw.plot(right=[(t1data.close,"close"),(hourly_anchored_expanding_mean, "hourly_anchored_expanding_mean")], size="s") t1data.ohlcv.data["BAC"].lw.plot(right=[(t1data.close,"close"),(hourly_anchored_expanding_mean, "hourly_anchored_expanding_mean")], size="s")
#NOTE for anchored "1D" frequency - it measures timedelta that means requires 1 day between reseting (16:00 end of market, 9:30 start - not a full day, so it is enOugh to set 7H) #NOTE for anchored "1D" frequency - it measures timedelta that means requires 1 day between reseting (16:00 end of market, 9:30 start - not a full day, so it is enOugh to set 7H)
#HEATMAP OVERLAY
df['a'].vbt.overlay_with_heatmap(df['b']).show() df['a'].vbt.overlay_with_heatmap(df['b']).show()
``` ```
@ -523,6 +534,7 @@ t1data.ohlcv.data["BAC"].lw.plot(auto_scale=[mom_anch_d, mom])
```python ```python
#SPLITTER - splitting wrapper based on index #SPLITTER - splitting wrapper based on index
#http://5.161.179.223:8000/vbt-doc/tutorials/cross-validation/splitter/index.html#anchored #http://5.161.179.223:8000/vbt-doc/tutorials/cross-validation/splitter/index.html#anchored
#based on GROUPER
daily_splitter = vbt.Splitter.from_grouper(t1data.index, "D", split=None) #DOES contain last DAY daily_splitter = vbt.Splitter.from_grouper(t1data.index, "D", split=None) #DOES contain last DAY
daily_splitter = vbt.Splitter.from_ranges( #doesnt contain last DY daily_splitter = vbt.Splitter.from_ranges( #doesnt contain last DY
@ -533,6 +545,9 @@ daily_splitter = vbt.Splitter.from_ranges( #doesnt contain last DY
daily_splitter.stats() daily_splitter.stats()
daily_splitter.plot() daily_splitter.plot()
daily_splitter.coverage() daily_splitter.coverage()
daily_splitter.get_bounds(index_bounds=True) #shows the exact times
daily_splitter.get_bounds_arr()
daily_splitter.get_range_coverage(relative=True)
#TAKING and APPLY MANUALLY - run UDF on ALL takes and concatenates #TAKING and APPLY MANUALLY - run UDF on ALL takes and concatenates
taken = daily_splitter.take(t1data) taken = daily_splitter.take(t1data)