예제 #1
0
파일: PT_report.py 프로젝트: yssource/quant
def GenBTReport(bt_file_path, file_name='strat_pnl_hist'):
    r = Reader()
    t = Trader()
    r.load_order_file(bt_file_path)
    for i in range(r.get_ordersize()):
        o = r.read_border(i)
        if o.price > 0 and abs(o.size) > 0:
            t.RegisterOneTrade(o.ticker, o.size if o.side == 1 else -o.size,
                               o.price)
    t.PlotStratPnl(file_name)
    return t.GenDFReport(), t.GenStratReport()
예제 #2
0
파일: PT_report.py 프로젝트: yssource/quant
def TradeReport(date_prefix, trade_path, cancel_path, file_name=''):
    trader = Trader()
    command = 'cat ' + date_prefix + 'log/order.log | grep Filled > ' + trade_path + '; cat ' + date_prefix + 'log/order_night.log | grep Filled >> ' + trade_path
    command_result = subprocess.Popen(command,
                                      shell=True,
                                      stdout=subprocess.PIPE,
                                      stderr=subprocess.STDOUT)
    command = 'cat ' + date_prefix + 'log/order.log | grep Cancelled > ' + cancel_path + '; cat ' + date_prefix + 'log/order_night.log | grep Cancelled >> ' + cancel_path
    command_result = subprocess.Popen(command,
                                      shell=True,
                                      stdout=subprocess.PIPE,
                                      stderr=subprocess.STDOUT)
    time.sleep(3)
    trade_details = []
    with open(trade_path) as f:
        ei = ExchangeInfo()
        for l in f:
            temp = []
            ei.construct(l)
            temp.append(
                datetime.datetime.fromtimestamp(float(
                    ei.time_str)).strftime("%Y-%m-%d %H:%M:%S"))
            temp.append(ei.ticker)
            temp.append("Buy" if ei.side == 0 else "Sell")
            temp.append(ei.trade_price)
            temp.append(ei.trade_size)
            trade_details.append(temp)
            trader.RegisterOneTrade(
                ei.ticker,
                int(ei.trade_size) if ei.side == 0 else -int(ei.trade_size),
                float(ei.trade_price))
    #print('printint')
    df = trader.GenDFReport()
    trader.PlotStratPnl(file_name=file_name)
    #print(df)
    #trader.Summary()
    df.insert(len(df.columns), 'cancelled', 0)
    with open(cancel_path) as f:
        ei = ExchangeInfo()
        for l in f:
            ei.construct(l)
            if ei.ticker not in df.index:
                df.loc[ei.ticker] = 0
            df.loc[ei.ticker, 'cancelled'] = df.loc[ei.ticker, 'cancelled'] + 1
    return df, trader.GenStratReport(), pd.DataFrame(
        trade_details, columns=['time', 'ticker', 'Side', 'price', 'size'])