Exemple #1
0
    print_summary_heading()

    for k in run_dict.keys():
        values = extract_print_values(run_dict, k, trading_days)
        print_values(values)


def backtest_main():
    start_time = time()
    bt = Backtester(update_stats=False)
    run_dict = run_back_set(bt)
    trading_days = len(bt.backtest_trading_dates)
    print_summary(trading_days, run_dict)

    log('')
    log('Done.')
    calc_runtime(start_time, True)


if __name__ == "__main__":

    log_fnm = "test" + get_current_day_and_time() + ".log"
    open_logfile(LOGPATH, log_fnm)

    if is_holiday() == True:
        log('Today is not a trading day!', True)
        log('', True)
        log('Done', True)
    else:
        backtest_main()
df.average = df.average / days
# regions = df[df.average >= per_day_limit].region.values
regions = [16 * a + b for a in range(7, 13) for b in range(7, 13)]
dataset = dataset[dataset.region.isin(regions)]
dataset = dataset[['createdAt', 'region', 'ride_count']]
dataset = dataset[dataset.createdAt >= train_start_date]
regions = dataset.region.unique()
mean = dataset.ride_count.mean()
std = dataset.ride_count.std()
dataset = dataset.groupby('region', as_index=False)

targets = pd.DataFrame()
targets['createdAt'] = dataset.get_group(regions[0])['createdAt']
targets = pd.DataFrame()
targets['createdAt'] = dataset.get_group(regions[0])['createdAt']
targets['is_holiday'] = targets.createdAt.apply(lambda x: util.is_holiday(x))
targets['is_holiday'] = (targets['is_holiday'] - targets['is_holiday'].min()
                         ) / (targets['is_holiday'].max() -
                              targets['is_holiday'].min())
# Set Day of week
targets['weekdaynum'] = targets.createdAt.apply(datetime.datetime.weekday)
targets['weekdaynum'] = (targets['weekdaynum'] - targets['weekdaynum'].min()
                         ) / (targets['weekdaynum'].max() -
                              targets['weekdaynum'].min())
# Set time interval number
targets['timeslot'] = targets.createdAt.apply(lambda x:
                                              (x.hour * 2 + x.minute / 30))
targets['sin_time'] = targets.timeslot.apply(
    lambda x: math.sin(2 * math.pi * x / (24 * (60 / agg_interval))))
targets['cos_time'] = targets.timeslot.apply(
    lambda x: math.cos(2 * math.pi * x / (24 * (60 / agg_interval))))