예제 #1
0
 def insert_history(self, quotes):
     try:
         conn = MyDB().get_db()
         c = conn.cursor()
         c.executemany(
             'INSERT OR REPLACE INTO ohlc(symbol, business_date, open, high, low, close, volume) VALUES(?,?,?,?,?,?,?)',
             quotes)
     except Exception as err:
         self.logger.error('error dayo. {0}'.format(err))
         if conn: conn.rollback()
     finally:
         if conn:
             conn.commit()
             conn.close
 def save_history(self, backtest_history):
     try:
         mylock.lock.acquire()
         conn = MyDB().get_db()
         c = conn.cursor()
         c.executemany(
             """
                     insert or replace into backtest_history
                     (
                         symbol,
                         strategy_id,
                         strategy_option,
                         business_date,
                         open,
                         high,
                         low,
                         close,
                         volume,
                         sma,
                         upper_sigma1,
                         lower_sigma1,
                         upper_sigma2,
                         lower_sigma2,
                         vol_sma,
                         vol_upper_sigma1,
                         vol_lower_sigma1,
                         order_create_date,
                         order_type,
                         order_vol, 
                         order_price,
                         call_order_date,
                         call_order_type,
                         call_order_vol,
                         call_order_price,
                         execution_order_date,
                         execution_order_type,
                         execution_order_status,
                         execution_order_vol,
                         execution_order_price,
                         position,
                         cash,
                         pos_vol,
                         pos_price,
                         total_value,
                         profit_value,
                         profit_rate,
                         leverage
                     )
                     values
                     ( 
                          ?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                     )
                 """, backtest_history)
     except Exception as err:
         if conn:
             conn.rollback()
             self.logger.error(err)
     finally:
         if conn:
             conn.commit()
             conn.close
         mylock.lock.release()
 def save_simulate_result(
         self, symbol, strategy_id, strategy_option, start_date, end_date,
         market_start_date, market_end_date, backtest_period,
         trading_period, average_period_per_trade, initial_assets,
         last_assets, rate_of_return, win_count, loss_count, win_value,
         loss_value, win_rate, payoffratio, expected_rate,
         expected_rate_per_1day, long_win_count, long_loss_count,
         long_win_value, long_loss_value, long_win_rate, long_payoffratio,
         long_expected_rate, long_expected_rate_per_1day, short_win_count,
         short_loss_count, short_win_value, short_loss_value,
         short_win_rate, short_payoffratio, short_expected_rate,
         short_expected_rate_per_1day, regist_date):
     try:
         mylock.lock.acquire()
         conn = MyDB().get_db()
         c = conn.cursor()
         c.execute(
             """
                     insert or replace into backtest_result 
                     (
                      symbol
                     ,strategy_id
                     ,strategy_option
                     ,start_date
                     ,end_date
                     ,market_start_date
                     ,market_end_date
                     ,backtest_period
                     ,trading_period
                     ,average_period_per_trade
                     ,initial_assets
                     ,last_assets
                     ,rate_of_return
                     ,win_count
                     ,loss_count
                     ,win_value
                     ,loss_value
                     ,win_rate
                     ,payoffratio
                     ,expected_rate
                     ,expected_rate_per_1day
                     ,long_win_count
                     ,long_loss_count
                     ,long_win_value
                     ,long_loss_value
                     ,long_win_rate
                     ,long_payoffratio
                     ,long_expected_rate
                     ,long_expected_rate_per_1day
                     ,short_win_count
                     ,short_loss_count
                     ,short_win_value
                     ,short_loss_value
                     ,short_win_rate
                     ,short_payoffratio
                     ,short_expected_rate
                     ,short_expected_rate_per_1day
                     ,regist_date
                 )
                 values
                 ( 
                          ?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                         ,?
                     )
                 """,
             (symbol, strategy_id, strategy_option, start_date, end_date,
              market_start_date, market_end_date, backtest_period,
              trading_period, average_period_per_trade, initial_assets,
              last_assets, rate_of_return, win_count, loss_count, win_value,
              loss_value, win_rate, payoffratio, expected_rate,
              expected_rate_per_1day, long_win_count, long_loss_count,
              long_win_value, long_loss_value, long_win_rate,
              long_payoffratio, long_expected_rate,
              long_expected_rate_per_1day, short_win_count,
              short_loss_count, short_win_value, short_loss_value,
              short_win_rate, short_payoffratio, short_expected_rate,
              short_expected_rate_per_1day, regist_date))
     except Exception as err:
         if conn:
             conn.rollback()
             self.logger.error(err)
     finally:
         if conn:
             conn.commit()
             conn.close
         mylock.lock.release()