Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could be cool to do in-house plots. #207

Open
SamsTheGreatest opened this issue Sep 29, 2022 · 4 comments
Open

Could be cool to do in-house plots. #207

SamsTheGreatest opened this issue Sep 29, 2022 · 4 comments
Labels
enhancement New feature or request

Comments

@SamsTheGreatest
Copy link

SamsTheGreatest commented Sep 29, 2022

Hej!

I think it is very useful to debug algos using something more than equity curves and metrics. Other frameworks like Vectorbt use Plotly for this, you guys chose tradingview (questionably quality right now). As I usually use Jupyter notebooks for everything, here is my suggestion right now before you can make a smooth integration with Tradingview:

from plotly.subplots import make_subplots
import plotly.graph_objects as go

def plot_results(result,symbol=None):
    if symbol is None:
        symbol = list(result.history.keys())[0]
    
    history = result.history[symbol]
    returns = result.get_returns()
    trades = result.trades['created'].copy()
    trades = {k:np.array([_[k] for _ in trades]) for k in ['time','side','price']}
    
    fig = make_subplots(rows=1, cols=1,shared_xaxes=True,vertical_spacing=None)
    
    fig.add_trace(
        go.Candlestick(
            x=pd.to_datetime(history.time,unit='s'),
            open=history.open,
            high=history.high,
            low=history.low,
            close=history.close),
         col=1,row=1
    )
    fig.update_layout(xaxis_rangeslider_visible=False)

    fig.add_trace(
        go.Scatter(
            x=pd.to_datetime(trades['time'],unit='s'),
            y=trades['price'],
            mode='markers',
            marker=dict(size=10,color=np.where(trades['side']=='buy','green','red'),symbol=np.where(trades['side']=='buy','triangle-up','triangle-down') ,line=dict(color='black',width=1)),
            ),
        col=1,row=1,
    )
    return fig
@EmersonDove
Copy link
Member

This is neat, thanks for the implementation. We were thinking about ways to improve visual debugging for the models with different charting libraries so this might come in handy.

@bfan1256
Copy link
Contributor

Hey @SamsTheGreatest , thanks for the help here. Yes, we've been actively looking for a better solution compared to the Blankly Platform as we currently are working with an external data provider for the TradingView charts and they are just not producing the right data. As a result, I think the best approach that the team is taking is considering a desktop rendition of the platform that enables you to read directly from the underlying CSV and backtest results themselves while still keeping and maintaining the features of the platform, with additional syncing capabilities if you do work in a team.

That way you get the best of the TradingView experience on the right data :D.
We're also considering adding a blankly.viz API soon that enables you to easily and quickly add lines at various price targets, plot additional data and markers as needed, hopefully a future where you can adjust hyperparameters purely based on a dashboard.

@SamsTheGreatest
Copy link
Author

SamsTheGreatest commented Sep 30, 2022

Sounds like a solid plan, really enjoying the development you guys made, you must keep on it! On a side note, if for now I want to plot custom variables, is it possible to access state.variables after the backtest to plot them? It seems like the backtest result does not include the final state?

@bfan1256
Copy link
Contributor

The best way is to use global variables that are defined outside of the strategy (so anything that is outside of your strategy will still be stored and you can interact with them inside your strategy as well.

@EmersonDove EmersonDove added the enhancement New feature or request label Oct 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants