Compare commits
3 Commits
c49f7e1ed6
...
3152fcb0b5
| Author | SHA1 | Date | |
|---|---|---|---|
| 3152fcb0b5 | |||
| 58b6bde651 | |||
| cc91d106c3 |
@ -1,5 +1,6 @@
|
||||
- [FETCHING DATA](#fetching-data)
|
||||
- [REINDEX to main session](#reindex-to-main-session)
|
||||
- [indexing](#indexing)
|
||||
- [DISCOVERY](#discovery)
|
||||
- [DATA/WRAPPER](#datawrapper)
|
||||
- [create WRAPPER manually](#create-wrapper-manually)
|
||||
@ -10,8 +11,8 @@
|
||||
- [SIGNALS](#signals)
|
||||
- [ENTRIES/EXITS time based](#entriesexits-time-based)
|
||||
- [STOPS](#stops)
|
||||
- [OHLCSTX module](#ohlcstx-module)
|
||||
- [ENTRY WINDOW and FORCED EXIT WINDOW](#entry-window-and-forced-exit-window)
|
||||
- [OHLCSTX Module](#ohlcstx-module)
|
||||
- [Entry Window and Forced Exit Window](#entry-window-and-forced-exit-window)
|
||||
- [END OF DAY EXITS](#end-of-day-exits)
|
||||
- [REGULAR EXITS](#regular-exits)
|
||||
- [DF/SR ACCESSORS](#dfsr-accessors)
|
||||
@ -95,7 +96,10 @@ testData = vbt.YFData.fetch(['MSFT'], start=start, end=end, timeframe=timeframe,
|
||||
# of market hours)
|
||||
testData = testData.transform(lambda x: x.reindex(market_klines))
|
||||
```
|
||||
|
||||
## indexing
|
||||
```python
|
||||
entries.vbt.xloc[slice("2024-08-01","2024-08-03")].obj.info()
|
||||
```
|
||||
# DISCOVERY
|
||||
|
||||
```python
|
||||
@ -235,8 +239,9 @@ mask.sum()
|
||||
```python
|
||||
#create entries/exits based on open of first symbol
|
||||
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()
|
||||
entries = symbol_wrapper.fill(False)
|
||||
exits = symbol_wrapper.fill(False)
|
||||
@ -257,7 +262,6 @@ exits.vbt.set(
|
||||
)
|
||||
```
|
||||
|
||||
|
||||
## STOPS
|
||||
[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[exits] = exit_price
|
||||
|
||||
## OHLCSTX module
|
||||
## OHLCSTX Module
|
||||
- exit signal generator based on price and stop values
|
||||
[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`.
|
||||
|
||||
`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
|
||||
from ttools import create_mask_from_window
|
||||
|
||||
@ -285,12 +291,12 @@ forced_exit_start = 387
|
||||
forced_exit_end = 390
|
||||
|
||||
#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
|
||||
entries = entries & entry_window_opened
|
||||
|
||||
#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
|
||||
exits = exits | forced_exits_window
|
||||
@ -309,6 +315,10 @@ exits = t1data.get_symbol_wrapper().fill(False)
|
||||
exits.loc[last_n_daily_rows.index] = True
|
||||
#visualize
|
||||
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
|
||||
Time based.
|
||||
@ -327,11 +337,11 @@ exits.vbt.set(
|
||||
# DF/SR ACCESSORS
|
||||
|
||||
## 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
|
||||
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")
|
||||
#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()
|
||||
```
|
||||
|
||||
@ -523,6 +534,7 @@ t1data.ohlcv.data["BAC"].lw.plot(auto_scale=[mom_anch_d, mom])
|
||||
```python
|
||||
#SPLITTER - splitting wrapper based on index
|
||||
#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_ranges( #doesnt contain last DY
|
||||
@ -533,6 +545,9 @@ daily_splitter = vbt.Splitter.from_ranges( #doesnt contain last DY
|
||||
daily_splitter.stats()
|
||||
daily_splitter.plot()
|
||||
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
|
||||
taken = daily_splitter.take(t1data)
|
||||
|
||||
Reference in New Issue
Block a user