Skip to content

VectrBT CheatSheet

David Brazda edited this page Jun 4, 2024 · 11 revisions

Plotly

  1. MAKE_SUBPLOT Definovat layout
fig = vbt.make_subplots(rows=2, cols=1, shared_xaxes=True, 
                            # specs=[[{"secondary_y": True}], [{"secondary_y": False}]], 
                            # vertical_spacing=0.02, subplot_titles=("Price and Indicators", "Volume"))
  1. ADD_TRACE_KWARGS - definuje umisteni do subpotu
add_trace_kwargs=dict(secondary_y=False,row=1, col=1)
  1. TRACE_KWARGS - ostatni stylujici atributy pro dany trace
trace_kwargs=dict(name="LONGS",
                  line=dict(color="#ffe476"),
                  marker=dict(color="limegreen"),
                  fill=None,
                  connectgaps=True)

Cely příklad

    fig = vbt.make_subplots(rows=2, cols=1, shared_xaxes=True, 
                            specs=[[{"secondary_y": True}], [{"secondary_y": False}]], 
                            vertical_spacing=0.02, subplot_titles=("Price and Indicators", "Volume"))

    # Plotting the close price
    close.vbt.plot(fig=fig, add_trace_kwargs=dict(secondary_y=False,row=1, col=1), trace_kwargs=dict(line=dict(color="blue")))

Data

Resampling

h4_h1_open = h4_open.resample("1h")
h4_close.vbt.realign_closing("1h") #realign resmapled series to given resolution (1h) - it can be  compared
h4_open.vbt.realign_opening("1h")

Validate resampl

t2dataclose = t2data.close.rename("15MIN - realigned").vbt.realign_closing("1T")
fig = t1data.close.rename("1MIN").vbt.plot()
t2data.close.rename("15MIN").vbt.plot(fig=fig)
t2dataclose.vbt.plot(fig=fig)

Persisting

basic_data.to_parquet(partition_by="day", compression="gzip")  
day_data = vbt.ParquetData.pull("BAC", filters=[("group", "==", "2024-05-03")]) 
vbt.print_dir_tree("BTC-USD")#overeni directory structure

Discover

vbt.phelp(vbt.talib(“atr”).run) #parameters it accepts
vbt.pdir(pf) - get available properties and methods
vbt.pprint(basic_data) #to get correct shape, info about instance
Clone this wiki locally