stock_x = pandas.get_stock_hist_data_cache(code, date) if stock_x is None or stock_x.empty: return pd.Series([code, date, 0.0, 0.0], index=stock_name_list) stock_y = pd.Series(stock_x["close"].values) stock_x_next = stock_x.iloc[len(stock_x) - 1] stock_x = stock_x.drop(stock_x.index[len(stock_x) - 1]) stock_y = stock_y.drop(stock_y.index[0]) stock_x.drop('close', axis=1, inplace=True) stock_x_next.drop(labels=['close'], inplace=True) model = linear_model.LinearRegression() model.fit(stock_x.values, stock_y) next_close = model.predict([stock_x_next.values]) if len(next_close) == 1: next_close = next_close[0] sklearn_score = model.score(stock_x.values, stock_y) return pd.Series([code, date, next_close, sklearn_score * 100], index=stock_name_list) calculate_stock_sklearn_index = CalculateStockSklearnIndex() if __name__ == '__main__': tmp_datetime = executor.run_with_args(calculate_stock_sklearn_index.run)
from model.ts_today_all import ts_today_all class CalculatePeriodWaveIndex: @staticmethod def run(date): data = ts_today_all.select(date) statistics = data.apply(lambda row: stockstats.calculate_wave( code=row['code'], date=row['date'], max_point=5), axis=1) statistics.drop('date', axis=1, inplace=True) statistics = pd.merge(data, statistics, on=['code'], how='left') statistics["up_rate"] = stockstats.calculate_up_rate( trade=statistics["trade"], wave_mean=statistics["wave_mean"], wave_crest=statistics["wave_crest"]) period_wave_index.delete(date) period_wave_index.insert(statistics) calculate_period_wave_index = CalculatePeriodWaveIndex() # main函数入口 if __name__ == '__main__': # 使用方法传递。 tmp_datetime = executor.run_with_args(calculate_period_wave_index.run)
appendix={'date': date.strftime("%Y%m%d")}) class DownloadIndex: @staticmethod def run(date): tushare.download_data(svc_name='get_index', primary_keys=["date", "code"], appendix={'date': date.strftime("%Y%m%d")}) class DownloadTodayAll: @staticmethod def run(date): tushare.download_data(svc_name='get_today_all', primary_keys=["date", "code"], appendix={'date': date.strftime("%Y%m%d")}) del_his_cache_data = DelHisCacheData() download_top_list = DownloadTopList() download_index = DownloadIndex() download_today_all = DownloadTodayAll() if __name__ == '__main__': executor.run_with_args(del_his_cache_data.run) executor.run_with_args(download_top_list.run) executor.run_with_args(download_index.run) time.sleep(5) # 停止5秒 executor.run_with_args(download_today_all.run)
statistics = data.apply(lambda row: stockstats.calculate_wave( code=row['code'], date=row['date'], max_point=3, ), axis=1) statistics.drop('date', axis=1, inplace=True) statistics = pd.merge(data, statistics, on=['code'], how='left') statistics = statistics[statistics["trade"] > statistics["wave_base"]] statistics = statistics[statistics["trade"] < statistics["wave_crest"]] statistics["up_rate"] = stockstats.calculate_up_rate( wave_mean=statistics["wave_mean"], trade=statistics["trade"], wave_crest=statistics["wave_crest"]) statistics["buy"] = 1 statistics["sell"] = 0 statistics["today_trade"] = statistics["trade"] statistics["income"] = 0 statistics = statistics.rename(columns={'date': 'buy_date'}) stock_statistics_buy.insert(statistics) calculate_stock_statistics_buy = CalculateStockStatisticsBuy() if __name__ == '__main__': executor.run_with_args(calculate_stock_statistics_buy.run)
date=row['date'], ), axis=1 ) statistics.drop('date', axis=1, inplace=True) return pd.merge(data, statistics, on=['code'], how='left') class StockStatisticsFilter: @staticmethod def filter(date): stock_statistics.delete(date) data = ss_stock_statistics.select( date=date, min_kdjk=80, min_kdjd=70, min_kdjj=90, min_rsi_6=50, min_cci=100 ) stock_statistics.insert(data) stock_statistics_filter = StockStatisticsFilter() stock_stats_index_calculator = StockStatsIndexCalculator() if __name__ == '__main__': executor.run_with_args(stock_stats_index_calculator.run) executor.run_with_args(stock_statistics_filter.filter)
download_deposit_rate_job = DownloadDepositRateJob() download_loan_rate_job = DownloadLoanRateJob() download_rrr_job = DownloadRrrJob() download_money_supply_job = DownloadMoneySupplyJob() download_money_supply_bal_job = DownloadMoneySupplyBalJob() download_gdp_year_job = DownloadGdpYearJob() download_gdp_quarter_job = DownloadGdpQuarterJob() download_gdp_for_job = DownloadGdpForJob() download_gdp_pull_job = DownloadGdpPullJob() download_gdp_contrib_job = DownloadGdpContribJob() download_cpi_job = DownloadCpiJob() download_ppi_job = DownloadPpiJob() download_stock_basics_job = DownloadStockBasicsJob() if __name__ == '__main__': mysql.create_new_schema_if_necessary() executor.run_with_args(download_deposit_rate_job.run) executor.run_with_args(download_loan_rate_job.run) executor.run_with_args(download_rrr_job.run) executor.run_with_args(download_money_supply_job.run) executor.run_with_args(download_money_supply_bal_job.run) executor.run_with_args(download_gdp_year_job.run) executor.run_with_args(download_gdp_quarter_job.run) executor.run_with_args(download_gdp_for_job.run) executor.run_with_args(download_gdp_pull_job.run) executor.run_with_args(download_gdp_contrib_job.run) executor.run_with_args(download_cpi_job.run) executor.run_with_args(download_ppi_job.run) executor.run_with_args(download_stock_basics_job.run)
stock_data_list = [code, date] stock = pandas.get_stock_hist_data_cache(code, date) stock_data_list.append( numpy.get_valid_ele(stock.tail(1)['close'].to_list(), 0)) stock_stats = stockstats.StockDataFrame.retype(stock) stock_data_list.append( numpy.get_valid_ele(stock_stats["cci"].tail(1).to_list(), 0)) stock_data_list.append( numpy.get_valid_ele(stock_stats["kdjj"].tail(1).to_list(), 0)) stock_data_list.append( numpy.get_valid_ele(stock_stats["rsi_6"].tail(1).to_list(), 0)) sell_indicator = self.get_sell_indicator(stock_data_list[3], stock_data_list[4], stock_data_list[5]) stock_data_list.append(sell_indicator) stock_data_list.append(1 - sell_indicator) return pd.Series(stock_data_list, index=stock_name_list) @staticmethod def get_sell_indicator(kdjj, rsi_6, cci): return 1 if kdjj > 80 and rsi_6 > 55 or cci > 100 else 0 calculate_stock_statistics_sell = CalculateStockStatisticsSell() if __name__ == '__main__': tmp_datetime = executor.run_with_args(calculate_stock_statistics_sell.run)