Comments (10)
You need to incorporate your schedule into your time series, which is done quite easily with pandas. To work 8 hours a day, just place signals only within those hours each day and generate an exit signal at the last tick of the day.
So, for example:
trading_time_idx = price.between_time('9:00','17:00',include_end=False).index
# restrict to trading time
entries[~entries.index.isin(trading_time_idx)] = False
entries[entries.index.isin(trading_time_idx)] &= True
exits[~exits.index.isin(trading_time_idx)] = False
exits[exits.index.isin(trading_time_idx)] &= True
# close position at last tick
exits.loc[exits.groupby(exits.index.date).last().index] = True
from vectorbt.
Sorry for the delay, I had to make some changes to the code to make it work.
You can find an example here.Cannot find the example anymore
Hey @Aqua-4 I found it here: https://github.com/polakowo/vectorbt/blob/master/examples/TradingSessions.ipynb
from vectorbt.
This is very helpful.
Thanks!
from vectorbt.
Does vectorbt reset the indicators at the beginning of the new trading session or after it detects large gap in the market data?
from vectorbt.
There is no detection or whatever, vectorbt receives a column (e.g. year of data) and resets only after reaching the end of the column. If you want to compute metrics per trading session you need to split this big column into many smaller columns, each per session. I can give you an example if this is what you want to achieve.
from vectorbt.
If you could give me an example that would be great. I'm working mostly with level2 data that I record myself so there is gaps in it.
I want to reset my indicators at the beginning of each trading day, so I guess splitting days into separate columns would work
Thanks
from vectorbt.
If it’s ok I’ll post an example on Saturday as I hasn’t been near my computer all this time.
from vectorbt.
Great. Thanks!
from vectorbt.
Sorry for the delay, I had to make some changes to the code to make it work.
You can find an example here.
from vectorbt.
Sorry for the delay, I had to make some changes to the code to make it work.
You can find an example here.
Cannot find the example anymore
from vectorbt.
Related Issues (20)
- tp_stop with accumulate gives wrong result
- Data mismatch
- Incorrect Position Size Allocation Across Multiple Assets HOT 3
- For the same precision data, there is an accuracy error in the results.
- Issues with combining multiple plots into subplots in 1 figure HOT 1
- Plotting Error: Subplot 'trade_pnl' raised an exception HOT 1
- Getting Daily PNL Portfolio Change
- What is the difference in the documentation of vectorbt PRO vs the open source vectorbt?
- What is the benchmark plotted in pf.plot().show()?
- How to use run_combs in combination with other signals?
- Questions about backtesting
- StopLoss group_by
- Plots missing "close" curve
- Import Errors HOT 5
- Plotting with custom benchmark_rets got error (VectorBT used undefined attribute 'obj')
- Datetime support with from_order_func HOT 2
- Dockerfile changes to run /apps/candlestick-patterns app
- Multiprocessing Error When Creating Portofiolio
- Pandas MultiIndex on axis 0 HOT 1
- Closing all positions at the end of the day HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vectorbt.