You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This feature is closely related to the open feature request of in-house plotting (#207). Currently I use the teardown function to create custom plots with plotly. However, this makes it difficult to show detailed information as trades and metrics as the backtest result is not yet available. The default figures of blankly are limited in showing what's going on with the data, such as visualizing indicators.
The real problem is that I have never the state and the backtest result together at one location, making it difficult to plot everything I want in a complete overview.
How would you implement this?
# Example of how my teardown function looks like:# using the teardown function for ploting feels like misusing the purpose of this functiondefteardown(symbol, state: blankly.StrategyState):
# in the teardown I do something like this to show the candles and indicators. plotly.show(state)
strategy.add_bar_event(bar_event, symbol='MSFT', resolution='4h', teardown=teardown)
res=strategy.backtest(to='1y', initial_values={'USD': 10000})
# Option 1: res.state[symbol][resolution] # -> blankly.StrategyStateres.get_state(*args) # -> blankly.StrategyState# Option 2: defteardown(symbol, state: blankly.StrategyState, res: BacktestResult ):
# in the teardown I do something like this to show the candles and indicators. plotly.show(state, res)
Would you like to Contribute?
Yes, I would love to contribute to this feature request 🎉 (I do not understand the internals of blankly that well)
No, but please keep me posted 🎉
The text was updated successfully, but these errors were encountered:
A super super simple workaround to this is to not use the teardown function and instead do something like this:
importblanklyglobal_state=Nonedefprice_event(price, symbol, state: blankly.FuturesStrategyState):
passdefteardown(symbol, state: blankly.StrategyState):
# In the teardown just copy the state to the global state and store that for laterimportcopyglobalglobal_stateglobal_state=copy.copy(state)
if__name__=="__main__":
# Authenticate Binance Futures exchangeexchange=blankly.Binance()
# Use our strategy helper on binance futuresstrategy=blankly.Strategy(exchange)
strategy.add_price_event(price_event, symbol='BTC-USDT', resolution='1d', teardown=teardown)
results=strategy.backtest(to='1M', initial_values={'USDT': 1000000})
print("Now I have both the state and the results!")
print(global_state)
print(results)
^^^ Just keep the reference around for the state variable in global_state
Description of Feature Request
This feature is closely related to the open feature request of in-house plotting (#207). Currently I use the teardown function to create custom plots with plotly. However, this makes it difficult to show detailed information as trades and metrics as the backtest result is not yet available. The default figures of blankly are limited in showing what's going on with the data, such as visualizing indicators.
The real problem is that I have never the
state
and thebacktest result
together at one location, making it difficult to plot everything I want in a complete overview.How would you implement this?
Would you like to Contribute?
The text was updated successfully, but these errors were encountered: