Esempio n. 1
0
 private void CloseAllPositions(Signal signal, DateTime ts, SystemState systemState, Func <Signal, StockPricesData, int, float> openPriceSelector)
 {
     while (systemState.PositionsActive.Count > 0)
     {
         float closePrice = CalculatePrice(systemState.PositionsActive[0].Stock.FullName, systemState.PositionsActive[0].DataRange, systemState.PositionsActive[0].IntradayInterval, signal, ts, openPriceSelector);
         systemState.Close(0, ts, closePrice, _commission.Calculate(systemState.PositionsActive[0].Stock.Type, systemState.PositionsActive[0].Volume, closePrice));
     }
 }
Esempio n. 2
0
		/// <summary>
		///   計算所有傭金規則
		/// </summary>
		/// <param name="order">ITradeOrder 介面</param>
		/// <returns>返回值: double[](0=佣金, 1=手續費)</returns>
		protected double[] CalculateCommissions(ITradeOrder order) {
			double[] dValues = new double[2]; 
			if (__cCommissions != null) {
				int iCount = __cCommissions.Count;
				for (int i = 0; i < iCount; i++) {
					ICommission cCommission = __cCommissions[i];
					int iIndex = ((int) cCommission.RuleType) - 128;  //佣金起始為 128(減去 128 可得到陣列的索引值)
					
					dValues[iIndex] += cCommission.Calculate(order);
				}
			}
			return dValues;
		}
Esempio n. 3
0
        public float Calculate(SystemState systemState, StockType stockType, float price)
        {
            float res = (float)Math.Floor(systemState.Cash / price);

            if (res <= 0)
            {
                return(0);
            }
            float commission = _commission.Calculate(stockType, res, price);

            if (res * price + commission <= systemState.Cash)
            {
                return(res);
            }
            return(res - (float)Math.Ceiling(commission / price));
        }
Esempio n. 4
0
 public static float CalculateCommission(this SystemState systemState, ICommission commission, StockType stockType, float volume, float price)
 {
     return(commission.Calculate(stockType, volume, price));
 }