param = {'num_leaves': 31, 'min_data_in_leaf': 20, 'objective': 'binary', 'learning_rate': 0.06, "boosting": "gbdt", "metric": 'None', "verbosity": -1} trn_data = lgb.Dataset(trn, trn_label) val_data = lgb.Dataset(val, val_label) num_round = 666 # clf = lgb.train(param, trn_data, num_round, valid_sets=[trn_data, val_data], verbose_eval=100, # early_stopping_rounds=300, feval=win_score_eval) clf = lgb.train(param, trn_data, num_round) # oof_lgb = clf.predict(val, num_iteration=clf.best_iteration) test_lgb = clf.predict(test, num_iteration=clf.best_iteration)thresh_hold = 0.5 oof_test_final = test_lgb >= thresh_hold print(metrics.accuracy_score(test_label, oof_test_final)) print(metrics.confusion_matrix(test_label, oof_test_final)) tp = np.sum(((oof_test_final == 1) & (test_label == 1))) pp = np.sum(oof_test_final == 1) print('accuracy1:%.3f'% (tp/(pp)))test_postive_idx = np.argwhere(oof_test_final == True).reshape(-1) # test_postive_idx = list(range(len(oof_test_final))) test_all_idx = np.argwhere(np.array(test_data_idx)).reshape(-1) stock_info['trade_date_id'] = stock_info['trade_date'].map(date_map) stock_info['trade_date_id'] = stock_info['trade_date_id'] + 1tmp_col = ['ts_code', 'trade_date', 'trade_date_id', 'open', 'high', 'low', 'close', 'ma5', 'ma13', 'ma21', 'label_final', 'name'] stock_info.iloc[test_all_idx[test_postive_idx]] tmp_df = stock_info[tmp_col].iloc[test_all_idx[test_postive_idx]].reset_index() tmp_df['label_prob'] = test_lgb[test_postive_idx] tmp_df['is_limit_up'] = tmp_df['close'] == tmp_df['high'] buy_df = tmp_df[(tmp_df['is_limit_up']==False)].reset_index() buy_df.drop(['index', 'level_0'], axis=1, inplace=True)buy_df['buy_flag'] = 1 stock_info_copy['sell_flag'] = 0tmp_idx = (index_df['trade_date'] == test_date_min+1) close1 = index_df[tmp_idx]['close'].values[0] test_date_max = 20220829 tmp_idx = (index_df['trade_date'] == test_date_max) close2 = index_df[tmp_idx]['close'].values[0]tmp_idx = (stock_info_copy['trade_date'] >= test_date_min) & (stock_info_copy['trade_date'] <= test_date_max) tmp_df = stock_info_copy[tmp_idx].reset_index(drop=True)from imp import reload import Account reload(Account) money_init = 200000 account = Account.Account(money_init, max_hold_period=20, stop_loss_rate=-0.07, stop_profit_rate=0.12) account.BackTest(buy_df, tmp_df, index_df, buy_price='open')tmp_df2 = buy_df[['ts_code', 'trade_date', 'label_prob', 'label_final']] tmp_df2 = tmp_df2.rename(columns={'trade_date':'buy_date'}) tmp_df = account.info tmp_df['buy_date'] = tmp_df['buy_date'].apply(lambda x: int(x)) tmp_df = tmp_df.merge(tmp_df2, on=['ts_code', 'buy_date'], how='left')最终的tmp_df是什么?tmp_df[tmp_df['label_final']==1]又选取了什么股票?
时间: 2023-06-26 15:09:04 浏览: 60
根据代码逐行分析,tmp_df 是一个 DataFrame,包含了股票的信息以及回测结果。其中,选取了 label_final 为 1 的股票,也就是模型预测为涨的股票,并且过滤掉了当天涨停的股票。最终买入的股票信息保存在 buy_df 中,回测时将其与 stock_info_copy、index_df 进行合并,得到了回测的结果,并将买入的股票信息与回测结果合并,生成了最终的 tmp_df。
相关问题
-param:JOB_NAME=job_ads_fin_wip_account_allot_d -param:ETL_FILE=/19_ADS_FIN/ETL/job_ads_fin_wip_account_allot_d.kjb -param:MIN_START_DATE=20230701 -param:MIN_END_DATE=20230702 -param:MAX_START_DATE=20230709 -param:MAX_END_DATE=20230710 -param:INCR_STEP=1M
这看起来像是一组作业参数的设置。这些参数用于指定一个名为"job_ads_fin_wip_account_allot_d"的作业的执行配置。
下面是每个参数的说明:
- JOB_NAME:作业的名称,设定为"job_ads_fin_wip_account_allot_d"。
- ETL_FILE:ETL文件的路径,设定为"/19_ADS_FIN/ETL/job_ads_fin_wip_account_allot_d.kjb"。
- MIN_START_DATE:最小开始日期,设定为"20230701"。
- MIN_END_DATE:最小结束日期,设定为"20230702"。
- MAX_START_DATE:最大开始日期,设定为"20230709"。
- MAX_END_DATE:最大结束日期,设定为"20230710"。
- INCR_STEP:增量步长,设定为"1M"。
这些参数可能会在作业执行过程中被使用,用于指定作业的输入、输出、日期范围等信息。
class NeuralNetwork: def __init__(self, layers_strcuture, print_cost = False): self.layers_strcuture = layers_strcuture self.layers_num = len(layers_strcuture) self.param_layers_num = self.layers_num - 1 self.learning_rate = 0.0618 self.num_iterations = 2000 self.x = None self.y = None self.w = dict() self.b = dict() self.costs = [] self.print_cost = print_cost self.init_w_and_b() def set_learning_rate(self,learning_rate): self.learning_rate=learning_rate def set_num_iterations(self, num_iterations): self.num_iterations = num_iterations def set_xy(self, input, expected_output): self.x = input self.y = expected_output
这段代码定义了一个名为NeuralNetwork的类,包含了类的构造函数__init__()和一些其他的方法。该类的构造函数__init__()接受一个参数layers_structure,表示神经网络的结构,即每一层的神经元数量。该类还包含了一些其他的属性和方法,包括:
- layers_num: 表示神经网络的层数
- param_layers_num: 表示神经网络的参数层数,即除去输入层和输出层的层数
- learning_rate: 表示神经网络的学习率
- num_iterations: 表示神经网络的迭代次数
- x: 表示输入数据
- y: 表示期望输出数据
- w: 表示神经网络的权重参数
- b: 表示神经网络的偏置参数
- costs: 表示每次迭代的损失值
- print_cost: 表示是否打印每次迭代的损失值
该类还包含了一些其他方法,包括set_learning_rate()、set_num_iterations()和set_xy()等,用于设置神经网络的学习率、迭代次数和输入数据等。这些方法可以在实例化该类后进行调用。