Beispiel #1
0
 public SimAccount()
 {
     log_data            = new LogData();
     performance_data    = new PerformanceData();
     order_data          = new OrderData();
     holding_data        = new HoldingData();
     total_pl_list       = new List <double>();
     total_pl_ratio_list = new List <double>();
 }
Beispiel #2
0
 private void process_execution(double exec_price, int order_serial_num, int i, string dt)
 {
     calc_fee(order_data.order_size[order_serial_num], exec_price, order_data.order_type[order_serial_num] == "limit" ? "maker" : "taker");
     if (holding_data.holding_side == "")
     {
         if (order_data.order_side[order_serial_num] == "buy")
         {
             performance_data.num_buy++;
         }
         else
         {
             performance_data.num_sell++;
         }
         holding_data.update_holding(order_data.order_side[order_serial_num], exec_price, order_data.order_size[order_serial_num], i);
         log_data.add_log_data(i, dt, "New Entry:" + order_data.order_type[order_serial_num], holding_data, order_data, performance_data);
     }
     else if (holding_data.holding_side == order_data.order_side[order_serial_num])
     {
         var ave_price = Math.Round(((holding_data.holding_price * holding_data.holding_size) + (exec_price * order_data.order_size[order_serial_num])) / (order_data.order_size[order_serial_num] + holding_data.holding_size), 1);
         holding_data.update_holding(holding_data.holding_side, ave_price, order_data.order_size[order_serial_num] + holding_data.holding_size, i);
         log_data.add_log_data(i, dt, "Additional Entry.", holding_data, order_data, performance_data);
     }
     else if (holding_data.holding_size > order_data.order_size[order_serial_num])
     {
         calc_executed_pl(exec_price, order_data.order_size[order_serial_num], i);
         holding_data.update_holding(holding_data.holding_side, holding_data.holding_price, holding_data.holding_size - order_data.order_size[order_serial_num], i);
         log_data.add_log_data(i, dt, "Exit Order (h>o)", holding_data, order_data, performance_data);
     }
     else if (holding_data.holding_size == order_data.order_size[order_serial_num])
     {
         calc_executed_pl(exec_price, order_data.order_size[order_serial_num], i);
         //initialize_holding_data();
         holding_data = new HoldingData();
         log_data.add_log_data(i, dt, "Exit Order (h=o)", holding_data, order_data, performance_data);
     }
     else if (holding_data.holding_size < order_data.order_size[order_serial_num])
     {
         if (order_data.order_side[order_serial_num] == "buy")
         {
             performance_data.num_buy++;
         }
         else
         {
             performance_data.num_sell++;
         }
         calc_executed_pl(exec_price, holding_data.holding_size, i);
         holding_data.update_holding(order_data.order_side[order_serial_num], exec_price, order_data.order_size[order_serial_num] - holding_data.holding_size, i);
         log_data.add_log_data(i, dt, "'Exit & Entry Order (h<o)", holding_data, order_data, performance_data);
     }
     else
     {
         Console.WriteLine("Unknown situation in process execution !");
     }
 }
Beispiel #3
0
 public SimAccount()
 {
     log_data            = new LogData();
     performance_data    = new PerformanceData();
     order_data          = new OrderData();
     holding_data        = new HoldingData();
     total_pl_list       = new List <double>();
     total_pl_ratio_list = new List <double>();
     margin_required     = 0.0;
     leverage            = 0.0;
     start_ind           = 0;
     end_ind             = 0;
 }
Beispiel #4
0
 public void add_log_data(int i, string dt, string action, HoldingData hd, OrderData od, PerformanceData pd)
 {
     total_pl_log.Add(pd.total_pl);
     if (od.order_serial_list.Count > 0)
     {
         log_data_table.Rows.Add(pd.total_pl, pd.total_fee, dt, i, od.order_side[od.order_serial_list.Last()], od.order_type[od.order_serial_list.Last()],
                                 od.order_size[od.order_serial_list.Last()], od.order_price[od.order_serial_list.Last()], od.order_message[od.order_serial_list.Last()], hd.holding_side, hd.holding_price, hd.holding_size,
                                 action);
     }
     else
     {
         log_data_table.Rows.Add(pd.total_pl, pd.total_fee, dt, i, "", "", 0, 0, "", hd.holding_side, hd.holding_price, hd.holding_size, action);
     }
 }
Beispiel #5
0
 public void last_day(int i, string dt, double close)
 {
     if (holding_data.holding_side != "")
     {
         calc_executed_pl(close, holding_data.holding_size, i);
         holding_data = new HoldingData();
         order_data   = new OrderData();
         performance_data.unrealized_pl  = 0;
         performance_data.total_pl       = performance_data.realized_pl + performance_data.unrealized_pl - performance_data.total_fee;
         performance_data.total_pl_ratio = performance_data.total_pl / close;
         if (performance_data.num_trade > 0)
         {
             performance_data.win_rate = Math.Round(Convert.ToDouble(performance_data.num_win) / Convert.ToDouble(performance_data.num_trade), 4);
         }
         total_pl_list.Add(performance_data.total_pl);
         total_pl_ratio_list.Add(performance_data.total_pl_ratio);
     }
 }