@app.callback([dash.dependencies.Output('features-and-responses', 'data'), dash.dependencies.Output('features-and-responses', 'columns'), dash.dependencies.Output('blotter', 'data'), dash.dependencies.Output('blotter', 'columns'), dash.dependencies.Output('calendar-ledger', 'data'), dash.dependencies.Output('calendar-ledger', 'columns'), dash.dependencies.Output('trade-ledger', 'data'), dash.dependencies.Output('trade-ledger', 'columns')], [dash.dependencies.Input('ivv-hist', 'children'), dash.dependencies.Input('bonds-hist', 'children'), dash.dependencies.Input('lil-n', 'value'), dash.dependencies.Input('big-N', 'value'), dash.dependencies.Input('alpha', 'value'), dash.dependencies.Input('lot-size', 'value'), dash.dependencies.Input('starting-cash', 'value'), dash.dependencies.State('hist-data-range', 'start_date'), dash.dependencies.State('hist-data-range', 'end_date')], prevent_initial_call=True)
def calculate_backtest(ivv_hist, bonds_hist, n, N, alpha, lot_size, starting_cash, start_date, end_date):
    (features_and_responses, blotter, calendar_ledger, trade_ledger) = backtest(ivv_hist, bonds_hist, n, N, alpha, lot_size, start_date, end_date, starting_cash)
    features_and_responses_columns = [{'name': i, 'id': i} for i in features_and_responses.columns]
    features_and_responses = features_and_responses.to_dict('records')
    blotter = blotter.to_dict('records')
    blotter_columns = [dict(id='ID', name='ID'), dict(id='ls', name='long/short'), dict(id='submitted', name='Created'), dict(id='action', name='Action'), dict(id='size', name='Size'), dict(id='symbol', name='Symb'), dict(id='price', name='Order Price', type='numeric', format=FormatTemplate.money(2)), dict(id='type', name='Type'), dict(id='status', name='Status'), dict(id='fill_price', name='Fill Price', type='numeric', format=FormatTemplate.money(2)), dict(id='filled_or_cancelled', name='Filled/Cancelled')]
    calendar_ledger = calendar_ledger.to_dict('records')
    calendar_ledger_columns = [dict(id='Date', name='Date'), dict(id='position', name='position'), dict(id='ivv_close', name='IVV Close', type='numeric', format=FormatTemplate.money(2)), dict(id='cash', name='Cash', type='numeric', format=FormatTemplate.money(2)), dict(id='stock_value', name='Stock Value', type='numeric', format=FormatTemplate.money(2)), dict(id='total_value', name='Total Value', type='numeric', format=FormatTemplate.money(2))]
    trade_ledger = trade_ledger.to_dict('records')
    trade_ledger_columns = [dict(id='trade_id', name='ID'), dict(id='open_dt', name='Trade Opened'), dict(id='close_dt', name='Trade Closed'), dict(id='trading_days_open', name='Trading Days Open'), dict(id='buy_price', name='Entry Price', type='numeric', format=FormatTemplate.money(2)), dict(id='sell_price', name='Exit Price', type='numeric', format=FormatTemplate.money(2)), dict(id='benchmark_buy_price', name='Benchmark Buy Price', type='numeric', format=FormatTemplate.money(2)), dict(id='benchmark_sell_price', name='Benchmark sell Price', type='numeric', format=FormatTemplate.money(2)), dict(id='trade_rtn', name='Return on Trade', type='numeric', format=FormatTemplate.percentage(3)), dict(id='benchmark_rtn', name='Benchmark Return', type='numeric', format=FormatTemplate.percentage(3)), dict(id='trade_rtn_per_trading_day', name='Trade Rtn / trd day', type='numeric', format=FormatTemplate.percentage(3)), dict(id='benchmark_rtn_per_trading_day', name='Benchmark Rtn / trd day', type='numeric', format=FormatTemplate.percentage(3))]
    return (features_and_responses, features_and_responses_columns, blotter, blotter_columns, calendar_ledger, calendar_ledger_columns, trade_ledger, trade_ledger_columns)
@app.callback([dash.dependencies.Output('features-and-responses', 'data'), dash.dependencies.Output('features-and-responses', 'columns'), dash.dependencies.Output('blotter', 'data'), dash.dependencies.Output('blotter', 'columns'), dash.dependencies.Output('calendar-ledger', 'data'), dash.dependencies.Output('calendar-ledger', 'columns'), dash.dependencies.Output('trade-ledger', 'data'), dash.dependencies.Output('trade-ledger', 'columns')], [dash.dependencies.Input('ivv-hist', 'children'), dash.dependencies.Input('bonds-hist', 'children'), dash.dependencies.Input('lil-n', 'value'), dash.dependencies.Input('big-N', 'value'), dash.dependencies.Input('alpha', 'value'), dash.dependencies.Input('lot-size', 'value'), dash.dependencies.Input('starting-cash', 'value'), dash.dependencies.State('hist-data-range', 'start_date'), dash.dependencies.State('hist-data-range', 'end_date')], prevent_initial_call=True)
def calculate_backtest(ivv_hist, bonds_hist, n, N, alpha, lot_size, starting_cash, start_date, end_date):
    (features_and_responses, blotter, calendar_ledger, trade_ledger) = backtest(ivv_hist, bonds_hist, n, N, alpha, lot_size, start_date, end_date, starting_cash)
    features_and_responses_columns = [{'name': i, 'id': i} for i in features_and_responses.columns]
    features_and_responses = features_and_responses.to_dict('records')
    blotter = blotter.to_dict('records')
    blotter_columns = [dict(id='ID', name='ID'), dict(id='ls', name='long/short'), dict(id='submitted', name='Created'), dict(id='action', name='Action'), dict(id='size', name='Size'), dict(id='symbol', name='Symb'), dict(id='price', name='Order Price', type='numeric', format=FormatTemplate.money(2)), dict(id='type', name='Type'), dict(id='status', name='Status'), dict(id='fill_price', name='Fill Price', type='numeric', format=FormatTemplate.money(2)), dict(id='filled_or_cancelled', name='Filled/Cancelled')]
    calendar_ledger = calendar_ledger.to_dict('records')
    calendar_ledger_columns = [dict(id='Date', name='Date'), dict(id='position', name='position'), dict(id='ivv_close', name='IVV Close', type='numeric', format=FormatTemplate.money(2)), dict(id='cash', name='Cash', type='numeric', format=FormatTemplate.money(2)), dict(id='stock_value', name='Stock Value', type='numeric', format=FormatTemplate.money(2)), dict(id='total_value', name='Total Value', type='numeric', format=FormatTemplate.money(2))]
    trade_ledger = trade_ledger.to_dict('records')
    trade_ledger_columns = [dict(id='trade_id', name='ID'), dict(id='open_dt', name='Trade Opened'), dict(id='close_dt', name='Trade Closed'), dict(id='trading_days_open', name='Trading Days Open'), dict(id='buy_price', name='Entry Price', type='numeric', format=FormatTemplate.money(2)), dict(id='sell_price', name='Exit Price', type='numeric', format=FormatTemplate.money(2)), dict(id='benchmark_buy_price', name='Benchmark Buy Price', type='numeric', format=FormatTemplate.money(2)), dict(id='benchmark_sell_price', name='Benchmark sell Price', type='numeric', format=FormatTemplate.money(2)), dict(id='trade_rtn', name='Return on Trade', type='numeric', format=FormatTemplate.percentage(3)), dict(id='benchmark_rtn', name='Benchmark Return', type='numeric', format=FormatTemplate.percentage(3)), dict(id='trade_rtn_per_trading_day', name='Trade Rtn / trd day', type='numeric', format=FormatTemplate.percentage(3)), dict(id='benchmark_rtn_per_trading_day', name='Benchmark Rtn / trd day', type='numeric', format=FormatTemplate.percentage(3))]
    return (features_and_responses, features_and_responses_columns, blotter, blotter_columns, calendar_ledger, calendar_ledger_columns, trade_ledger, trade_ledger_columns)