Exemple #1
0
def get_accuracy(model_type, stock_name, start, stop, p_days, period,
                 dist_period):
    """

    :param model_type:
    :param stock_name:
    :param start:
    :param stop:
    :param p_days:
    :param period:
    :param dist_period:
    :return:
    """
    rw_data = get_raw_data(stock_name, start, stop)
    ft_data = add_feat(rw_data, p_days)
    new_ft_data = add_bucket(ft_data, dist_period)
    X_features = new_ft_data.columns.tolist()
    y_index = X_features.index('Tmrw_return')
    del X_features[y_index]
    z_index = X_features.index('expect_ret')
    del X_features[z_index]
    new_ft_data['Ticker'] = stock_name
    if model_type == "rf":
        t_index = X_features.index(yclass_label)
        del X_features[t_index]
        input_X = new_ft_data[X_features]
        input_Y = new_ft_data[yclass_label]
        accuracy, pred_table = fitting_forest(input_X,
                                              input_Y,
                                              period,
                                              n_estimators=100)
        return 100 * accuracy

    pred_table = calc_pred_data(new_ft_data, period, X_features)
    acc = acc_pred(pred_table)
    return acc
Exemple #2
0
    return pred_table


if __name__ == "__main__":

    stock_name = sys.argv[1]
    start = sys.argv[2]
    stop = sys.argv[3]
    p_days = int(sys.argv[4])
    period = int(sys.argv[5])
    dist_period = int(sys.argv[6])

    check_data_input(p_days, period, dist_period, start, stop)

    # Getting Raw data
    rw_data = get_raw_data(stock_name, start, stop)

    # Formating data to add 4*p_days features
    ft_data = add_feat(rw_data, p_days)

    # New format to add bucket
    new_ft_data = add_bucket(ft_data, dist_period)

    # Getting the feat array
    X_features = new_ft_data.columns.tolist()
    y_index = X_features.index('Tmrw_return')
    del X_features[y_index]
    z_index = X_features.index('expect_ret')
    del X_features[z_index]

    new_ft_data['Ticker'] = stock_name