Beispiel #1
0
        /// <summary>
        /// 装载所有的交易费用数据
        /// </summary>
        /// <returns></returns>
        public List <AccountFeeInfo> LoadAllAccountFee()
        {
            List <AccountFeeInfo> feeInfos = new List <AccountFeeInfo>();

            string[] contents = File.ReadAllLines(path);
            for (int i = 0; i < contents.Length; i++)
            {
                AccountFeeInfo feeinfo = LoadAccountFeeInfo(contents[i]);
                feeInfos.Add(feeinfo);
            }
            return(feeInfos);
        }
Beispiel #2
0
        private AccountFeeInfo LoadAccountFeeInfo(string content)
        {
            string[]       arr     = content.Split(',');
            AccountFeeInfo feeInfo = new AccountFeeInfo();

            feeInfo.Code             = arr[0];
            feeInfo.VolumeMultiple   = int.Parse(arr[1]);
            feeInfo.MarginRatio      = double.Parse(arr[2]);
            feeInfo.CommissionCharge = double.Parse(arr[3]);
            feeInfo.FeeCalcType      = (CommissionChargeCalcType)Enum.Parse(typeof(CommissionChargeCalcType), arr[4]);
            return(feeInfo);
        }
Beispiel #3
0
 public static double CalcMoney_Close(OrderInfo order, AccountFeeInfo accountFee, int mount)
 {
     if (accountFee.FeeCalcType == CommissionChargeCalcType.Fix)
     {
         return((order.Price - accountFee.CommissionCharge) * accountFee.VolumeMultiple / accountFee.MarginRatio * mount);
     }
     else if (accountFee.FeeCalcType == CommissionChargeCalcType.Percent)
     {
         return((order.Price * accountFee.VolumeMultiple / accountFee.MarginRatio) * mount * (1 - accountFee.CommissionCharge));
     }
     return(0);
 }
Beispiel #4
0
 public AccountFee(List <AccountFeeInfo> fees)
 {
     for (int i = 0; i < fees.Count; i++)
     {
         AccountFeeInfo fee = fees[i];
         if (StringUtils.IsEmpty(fee.Code))
         {
             continue;
         }
         if (dic_Code_Fee.ContainsKey(fee.Code))
         {
             continue;
         }
         dic_Code_Fee.Add(fee.Code, fee);
     }
 }
        // [TestMethod]
        public void PrintAccountFee()
        {
            AccountFeeInfo        feeInfo1 = new AccountFeeInfo("m1705", 1, 1, 0, CommissionChargeCalcType.Fix);
            AccountFeeInfo        feeInfo2 = new AccountFeeInfo("m1709", 5, 5, 3, CommissionChargeCalcType.Fix);
            AccountFeeInfo        feeInfo3 = new AccountFeeInfo("m1701", 5, 5, 3, CommissionChargeCalcType.Fix);
            AccountFeeInfo        feeInfo4 = new AccountFeeInfo("m1707", 10, 5, 0.0001, CommissionChargeCalcType.Percent);
            AccountFeeInfo        feeInfo5 = new AccountFeeInfo("m1703", 10, 10, 0.0001, CommissionChargeCalcType.Percent);
            List <AccountFeeInfo> feeInfos = new List <AccountFeeInfo>();

            feeInfos.Add(feeInfo1);
            feeInfos.Add(feeInfo2);
            feeInfos.Add(feeInfo3);
            feeInfos.Add(feeInfo4);
            feeInfos.Add(feeInfo5);
            AssertUtils.PrintLineList(feeInfos);
        }
Beispiel #6
0
        private void ClosePosition(OrderInfo order, int mount)
        {
            string code = order.Instrumentid;

            if (order.Direction == OrderSide.Buy)
            {
                if (position_Code_Long.ContainsKey(code))
                {
                    PositionInfo currentPosition = position_Code_Long[code];
                    int          totalPosition   = currentPosition.Position - mount;
                    if (totalPosition == 0)
                    {
                        RemovePosition(currentPosition);
                    }
                    else
                    {
                        double avgPrice = (currentPosition.Position * currentPosition.PositionCost - order.Price * mount) / totalPosition;
                        currentPosition.Position     = totalPosition;
                        currentPosition.PositionCost = avgPrice;
                    }
                }
            }
            else
            {
                if (position_Code_Short.ContainsKey(code))
                {
                    PositionInfo currentPosition = position_Code_Short[code];
                    int          totalPosition   = currentPosition.Position - mount;
                    if (totalPosition == 0)
                    {
                        RemovePosition(currentPosition);
                    }
                    else
                    {
                        double avgPrice = (currentPosition.Position * currentPosition.PositionCost - order.Price * mount) / totalPosition;
                        currentPosition.Position     = totalPosition;
                        currentPosition.PositionCost = avgPrice;
                    }
                }
            }
            AccountFeeInfo feeInfo = accountFee.GetAccountFee(code);

            this.money += AccountFee.CalcMoney_Close(order, feeInfo, mount);
        }
Beispiel #7
0
        private void OpenPosition(OrderInfo order, int mount)
        {
            string code = order.Instrumentid;

            if (order.Direction == OrderSide.Buy)
            {
                if (position_Code_Long.ContainsKey(code))
                {
                    PositionInfo currentPosition = position_Code_Long[code];
                    int          totalPosition   = currentPosition.Position + mount;
                    double       avgPrice        = (currentPosition.Position * currentPosition.PositionCost + order.Price * mount) / totalPosition;
                    currentPosition.Position     = totalPosition;
                    currentPosition.PositionCost = avgPrice;
                }
                else
                {
                    PositionInfo position = new PositionInfo(code, PositionSide.Long, mount, order.Price);
                    AddPosition(position);
                }
            }
            else
            {
                if (position_Code_Short.ContainsKey(code))
                {
                    PositionInfo currentPosition = position_Code_Short[code];
                    int          totalPosition   = currentPosition.Position + mount;
                    double       avgPrice        = (currentPosition.Position * currentPosition.PositionCost + order.Price * mount) / totalPosition;
                    currentPosition.Position     = totalPosition;
                    currentPosition.PositionCost = avgPrice;
                }
                else
                {
                    PositionInfo position = new PositionInfo(code, PositionSide.Short, mount, order.Price);
                    AddPosition(position);
                }
            }
            AccountFeeInfo feeInfo = accountFee.GetAccountFee(code);

            this.money -= AccountFee.CalcMoney_Open(order, feeInfo, mount);
        }