Closed wojoeraf closed 2 years ago
@wojoeraf vectorbt doesn't care much if you trade stocks, crypto, or anything else. What it needs is an array of data, even without datetime-like index. But having a proper index with a frequency will let you compute annualization metrics. To trade stocks use size_granularity=1
, which will disable fractional size. You can set freq
in vbt.settings['array_wrapper']['freq']
and year_freq
in vbt.settings['returns']['year_freq']
.
@polakowo thanks, but where do I set size_granularity=1
? It is neither a parameter of the vbt.MA.run()
method nor of the plot()
method.
@wojoeraf size granularity belongs neither to indicators nor plotting, it's an argument of Portfolio.from_signals
and comparable simulation methods to instruct that any order size should be rounded to the next integer.
@polakowo Thanks so far for your help.
Can I be sure then, when I set vbt.settings['array_wrapper']['freq']
according to my data (e.g. 1h) and the size_granularity=1
for the Portfolio.from_signals
, that indicators are calculated and handled correctly (because the plots of the indicators still show the gaps in between)?
@polakowo I have a complete example adapted from the usage page:
I can't imagine, that the result is a correct one.
@wojoeraf fees of 0.1 is 10%. Furthermore you should remove gaps in data completely, there is no point in having nans.
@polakowo about fees, ok, thats my mistake ;) About that nan's, yes, I tried that after taking the screenshot (with drpona()), somehow even my index contains clean data without nans or gaps, the plotting always contains gaps.
@wojoeraf this isn't an issue, plotting will always show gaps.
@polakowo Ah ok, I see. Unfortunately then plotting e.g. for a moving average makes no sense since no MA is even visible, if the consecutive bars are less then the MA's length. Thanks for your help and quick responses
@wojoeraf MA should be computed from the series that contains no gaps. Plotting it shouldn't be a problem, just pass connectgaps=True
to whatever trace should connect gaps (look at trace_kwargs
argument in the documentation of the particular method and pass trace_kwargs=dict(connectgaps=True)
).
@polakowo Thanks for your consistent input. I'm kinda new to the python and Data Science world so I need to build up a lot of knowledge.
The connectgaps
is not a valid parameter, but I found a solution on the plotly pages:
This also works for indicators.
I have another question: When running
fast_ma, slow_ma = vbt.MA.run_combs(price, window=windows, r=2, short_names=['fast', 'slow'])
I have to give a column value when trying to plot e.g. the fast_ma: fast_ma.plot(0)
.
What does the columns represent in that case?
@wojoeraf it's the same columns as in fast_ma.ma
. If columns have multiple levels, you can provide each column as a tuple.
Hi there, great work here.
I'm trying to setup vectorbt for the use with stocks. I found some hints e.g. about freq and year_freq settings but I'm not getting it to work well. (Also on which classes to set those settings).
When plotting indicators either there are gaps like this...
...or if I use dropna() on the data it looks like this (which feels wrong)
A short guide on how to setup everything for the use of stocks in different timeframes (1 minute and higher) would help so much.
Thanks a lot!
Rafael