Skip to content

Instantly share code, notes, and snippets.

@natyrix
Created October 15, 2022 22:36
Show Gist options
  • Save natyrix/40c62bea3e6a6ca526231f8e3d394f35 to your computer and use it in GitHub Desktop.
Save natyrix/40c62bea3e6a6ca526231f8e3d394f35 to your computer and use it in GitHub Desktop.
def plot_fast_and_slow(self):
fig = self.price.vbt.plot(trace_kwargs=dict(name='Close'))
self.calc_fast_ma.ma.vbt.plot(trace_kwargs=dict(name='Fast MA'), fig=fig)
self.calc_slow_ma.ma.vbt.plot(trace_kwargs=dict(name='Slow MA'), fig=fig)
self.pf.positions.plot(close_trace_kwargs=dict(visible=False), fig=fig)
# vbt.save('fig.png', fig)
with open('./images/vectorbt/fast_and_slow_plot.png','wb') as f:
f.write(fig.to_image(format='png'))
with open('./images/vectorbt/fast_and_slow_plot.png','rb') as f:
if self.is_experiment:
mlflow.log_artifact("./images/vectorbt/fast_and_slow_plot.png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment