@app.callback([dash.dependencies.Output('alpha-beta', 'figure'), dash.dependencies.Output('strategy-alpha', 'children'), dash.dependencies.Output('strategy-beta', 'children'), dash.dependencies.Output('strategy-gmrr', 'children'), dash.dependencies.Output('strategy-trades-per-yr', 'children'), dash.dependencies.Output('strategy-vol', 'children'), dash.dependencies.Output('strategy-sharpe', 'children')], dash.dependencies.Input('trade-ledger', 'data'), prevent_initial_call=True)
def update_performance_metrics(trade_ledger):
    trade_ledger = pd.DataFrame(trade_ledger)
    trade_ledger = trade_ledger[1:]
    X = trade_ledger['benchmark_rtn_per_trading_day'].values.reshape((- 1), 1)
    linreg_model = linear_model.LinearRegression()
    linreg_model.fit(X, trade_ledger['trade_rtn_per_trading_day'])
    x_range = np.linspace(X.min(), X.max(), 100)
    y_range = linreg_model.predict(x_range.reshape((- 1), 1))
    fig = px.scatter(trade_ledger, title='Performance against Benchmark', x='benchmark_rtn_per_trading_day', y='trade_rtn_per_trading_day')
    fig.add_traces(go.Scatter(x=x_range, y=y_range, name='OLS Fit'))
    alpha = (str(round((linreg_model.intercept_ * 100), 3)) + '% / trade')
    beta = round(linreg_model.coef_[0], 3)
    gmrr = (((trade_ledger['trade_rtn_per_trading_day'] + 1).product() ** (1 / len(trade_ledger))) - 1)
    avg_trades_per_yr = round(trade_ledger['open_dt'].groupby(pd.DatetimeIndex(trade_ledger['open_dt']).year).agg('count').mean(), 0)
    vol = stdev(trade_ledger['trade_rtn_per_trading_day'])
    sharpe = round((gmrr / vol), 3)
    gmrr_str = (str(round(gmrr, 3)) + '% / trade')
    vol_str = (str(round(vol, 3)) + '% / trade')
    return (fig, alpha, beta, gmrr_str, avg_trades_per_yr, vol_str, sharpe)
@app.callback([dash.dependencies.Output('alpha-beta', 'figure'), dash.dependencies.Output('strategy-alpha', 'children'), dash.dependencies.Output('strategy-beta', 'children'), dash.dependencies.Output('strategy-gmrr', 'children'), dash.dependencies.Output('strategy-trades-per-yr', 'children'), dash.dependencies.Output('strategy-vol', 'children'), dash.dependencies.Output('strategy-sharpe', 'children')], dash.dependencies.Input('trade-ledger', 'data'), prevent_initial_call=True)
def update_performance_metrics(trade_ledger):
    trade_ledger = pd.DataFrame(trade_ledger)
    trade_ledger = trade_ledger[1:]
    X = trade_ledger['benchmark_rtn_per_trading_day'].values.reshape((- 1), 1)
    linreg_model = linear_model.LinearRegression()
    linreg_model.fit(X, trade_ledger['trade_rtn_per_trading_day'])
    x_range = np.linspace(X.min(), X.max(), 100)
    y_range = linreg_model.predict(x_range.reshape((- 1), 1))
    fig = px.scatter(trade_ledger, title='Performance against Benchmark', x='benchmark_rtn_per_trading_day', y='trade_rtn_per_trading_day')
    fig.add_traces(go.Scatter(x=x_range, y=y_range, name='OLS Fit'))
    alpha = (str(round((linreg_model.intercept_ * 100), 3)) + '% / trade')
    beta = round(linreg_model.coef_[0], 3)
    gmrr = (((trade_ledger['trade_rtn_per_trading_day'] + 1).product() ** (1 / len(trade_ledger))) - 1)
    avg_trades_per_yr = round(trade_ledger['open_dt'].groupby(pd.DatetimeIndex(trade_ledger['open_dt']).year).agg('count').mean(), 0)
    vol = stdev(trade_ledger['trade_rtn_per_trading_day'])
    sharpe = round((gmrr / vol), 3)
    gmrr_str = (str(round(gmrr, 3)) + '% / trade')
    vol_str = (str(round(vol, 3)) + '% / trade')
    return (fig, alpha, beta, gmrr_str, avg_trades_per_yr, vol_str, sharpe)