@app.callback([dash.dependencies.Output('bonds-hist', 'children'), dash.dependencies.Output('bonds-3d-graph', 'figure'), dash.dependencies.Output('bonds-3d-graph', 'style')], dash.dependencies.Input('run-backtest', 'n_clicks'), [dash.dependencies.State('hist-data-range', 'start_date'), dash.dependencies.State('hist-data-range', 'end_date'), dash.dependencies.State('big-N', 'value'), dash.dependencies.State('lil-n', 'value')], prevent_initial_call=True)
def update_bonds_hist(n_clicks, startDate, endDate, N, n):
    startDate = (pd.to_datetime(startDate).date() - timedelta(days=ceil(((N + n) * (365 / 252)))))
    startDate = startDate.strftime('%Y-%m-%d')
    data_years = list(range(pd.to_datetime(startDate).date().year, (pd.to_datetime(endDate).date().year + 1), 1))
    bonds_data = fetch_usdt_rates(data_years[0])
    if (len(data_years) > 1):
        for year in data_years[1:]:
            bonds_data = pd.concat([bonds_data, fetch_usdt_rates(year)], axis=0, ignore_index=True)
    bonds_data = bonds_data[(bonds_data.Date >= pd.to_datetime(startDate))]
    bonds_data = bonds_data[(bonds_data.Date <= pd.to_datetime(endDate))]
    fig = go.Figure(data=[go.Surface(z=bonds_data, y=bonds_data.Date, x=[to_years(cmt_colname) for cmt_colname in list(filter((lambda x: (' ' in x)), bonds_data.columns.values))])])
    fig.update_layout(scene=dict(xaxis_title='Maturity (years)', yaxis_title='Date', zaxis_title='APR (%)', zaxis=dict(ticksuffix='%')))
    bonds_data.reset_index(drop=True, inplace=True)
    return (bonds_data.to_json(), fig, {'display': 'block'})
@app.callback([dash.dependencies.Output('bonds-hist', 'children'), dash.dependencies.Output('bonds-3d-graph', 'figure'), dash.dependencies.Output('bonds-3d-graph', 'style')], dash.dependencies.Input('run-backtest', 'n_clicks'), [dash.dependencies.State('hist-data-range', 'start_date'), dash.dependencies.State('hist-data-range', 'end_date'), dash.dependencies.State('big-N', 'value'), dash.dependencies.State('lil-n', 'value')], prevent_initial_call=True)
def update_bonds_hist(n_clicks, startDate, endDate, N, n):
    startDate = (pd.to_datetime(startDate).date() - timedelta(days=ceil(((N + n) * (365 / 252)))))
    startDate = startDate.strftime('%Y-%m-%d')
    data_years = list(range(pd.to_datetime(startDate).date().year, (pd.to_datetime(endDate).date().year + 1), 1))
    bonds_data = fetch_usdt_rates(data_years[0])
    if (len(data_years) > 1):
        for year in data_years[1:]:
            bonds_data = pd.concat([bonds_data, fetch_usdt_rates(year)], axis=0, ignore_index=True)
    bonds_data = bonds_data[(bonds_data.Date >= pd.to_datetime(startDate))]
    bonds_data = bonds_data[(bonds_data.Date <= pd.to_datetime(endDate))]
    fig = go.Figure(data=[go.Surface(z=bonds_data, y=bonds_data.Date, x=[to_years(cmt_colname) for cmt_colname in list(filter((lambda x: (' ' in x)), bonds_data.columns.values))])])
    fig.update_layout(scene=dict(xaxis_title='Maturity (years)', yaxis_title='Date', zaxis_title='APR (%)', zaxis=dict(ticksuffix='%')))
    bonds_data.reset_index(drop=True, inplace=True)
    return (bonds_data.to_json(), fig, {'display': 'block'})