def setUp(self): self.stock_code = 'HK.09988' self.complete_data = pd.read_csv('./test/test_data/test_data.csv', index_col=None) self.input_data = self.complete_data.iloc[:100, :] self.test_data = self.complete_data.iloc[100:, :] self.kdj_cross = KDJCross({self.stock_code: self.input_data}, observation=100)
class KDJTestCase(unittest.TestCase): def setUp(self): self.stock_code = 'HK.09988' self.complete_data = pd.read_csv('./test/test_data/test_data.csv', index_col=None) self.input_data = self.complete_data.iloc[:100, :] self.test_data = self.complete_data.iloc[100:, :] self.kdj_cross = KDJCross({self.stock_code: self.input_data}, observation=100) def test_buy(self): # Success. K = 71.86 D = 71.021 J = 73.539 at Dec 23 2020 11:10 AM for index, row in self.test_data.iterrows(): latest_data = row.to_frame().transpose() latest_data.reset_index(drop=True, inplace=True) self.kdj_cross.parse_data(latest_data=latest_data) self.kdj_cross.buy(self.stock_code) self.assertEqual(True, True) def test_sell(self): for index, row in self.test_data.iterrows(): latest_data = row.to_frame().transpose() latest_data.reset_index(drop=True, inplace=True) self.kdj_cross.parse_data(latest_data=latest_data) self.kdj_cross.sell(self.stock_code) self.assertEqual(True, True)
def main(): # Initialization Connection futu_trade = trading_engine.FutuTrade() # Daily Update Data # daily_update_data(futu_trade=futu_trade, force_update=False) # Update ALl Data to Database # futu_trade.store_all_data_database() # Initialize Strategies stock_list = [ "HK.00001", "HK.00002", "HK.00003", "HK.00005", "HK.00006", "HK.00011", "HK.00012", "HK.00016", "HK.00017", "HK.00027", "HK.00066", "HK.00101", "HK.00175", "HK.00267", "HK.00288", "HK.00386", "HK.00388", "HK.00669", "HK.00688", "HK.00700", "HK.00762", "HK.00823", "HK.00857", "HK.00883", "HK.00939", "HK.00941", "HK.01038", "HK.01044", "HK.01093", "HK.01109", "HK.01113", "HK.01177", "HK.01299", "HK.01398", "HK.01810", "HK.01876", "HK.01928", "HK.01997", "HK.02007", "HK.02018", "HK.02020", "HK.02269", "HK.02313", "HK.02318", "HK.02319", "HK.02382", "HK.02388", "HK.02628", "HK.03328", "HK.03690", "HK.03988", "HK.09988" ] for stock_code in stock_list: futu_trade.update_1M_data(stock_code, force_update=False) input_data = futu_trade.get_1M_data(stock_list=stock_list) kdj_cross = KDJCross(input_data=input_data) futu_trade.cur_kline_subscription(input_data, stock_list=stock_list, strategy=kdj_cross, timeout=3600 * 12) futu_trade.display_quota()
def __init_strategy(strategy_name: str, input_data: dict) -> Strategies: strategies = { 'EMA_Ribbon': EMARibbon(input_data=input_data.copy()), 'KDJ_Cross': KDJCross(input_data=input_data.copy()), 'KDJ_MACD_Close': KDJMACDClose(input_data=input_data.copy()), 'MACD_Cross': MACDCross(input_data=input_data.copy()), 'RSI_Threshold': RSIThreshold(input_data=input_data.copy()), 'Short_Term_Band': ShortTermBand(input_data=input_data.copy()), 'Quant_Legendary': QuantLegendary(input_data=input_data.copy()) } # Default return simplest MACD Cross Strategy return strategies.get(strategy_name, MACDCross(input_data=input_data))