Beispiel #1
0
        internal void Add(VolumeNecessaryDetail volumeNecessaryDetail)
        {
            int index = this.VolumeNecessaryDetails.FindIndex(delegate(VolumeNecessaryDetail item) { return(item.From > volumeNecessaryDetail.From); });

            if (index == -1)
            {
                this.VolumeNecessaryDetails.Add(volumeNecessaryDetail);
            }
            else
            {
                this.VolumeNecessaryDetails.Insert(index, volumeNecessaryDetail);
            }
        }
Beispiel #2
0
        internal void Update(VolumeNecessaryDetail volumeNecessaryDetail)
        {
            int index = this.VolumeNecessaryDetails.FindIndex(delegate(VolumeNecessaryDetail item) { return(item.Id == volumeNecessaryDetail.Id); });

            if (index == -1)
            {
                this.Add(volumeNecessaryDetail);
            }
            else
            {
                this.VolumeNecessaryDetails[index] = volumeNecessaryDetail;
            }
        }
Beispiel #3
0
        internal decimal CalculateNecessary(decimal marginRate, decimal defaultMargin, decimal netLot, bool useDayMargin)
        {
            if (this.VolumeNecessaryDetails.Count == 0)
            {
                return(marginRate * defaultMargin * netLot);
            }

            if (this.Option == VolumeNecessaryOption.Flat)
            {
                VolumeNecessaryDetail volumeNecessaryDetail = this.VolumeNecessaryDetails.FindLast(delegate(VolumeNecessaryDetail item) { return(netLot > item.From); });
                decimal margin = volumeNecessaryDetail == null ? defaultMargin : (useDayMargin ? volumeNecessaryDetail.MarginD : volumeNecessaryDetail.MarginO);
                return(marginRate * margin * netLot);
            }
            else if (this.Option == VolumeNecessaryOption.Progessive)
            {
                decimal necessary = marginRate * defaultMargin * Math.Min(netLot, this.VolumeNecessaryDetails[0].From);

                int index = 0;
                while (index < this.VolumeNecessaryDetails.Count && netLot > this.VolumeNecessaryDetails[index].From)
                {
                    decimal margin = useDayMargin ? this.VolumeNecessaryDetails[index].MarginD : this.VolumeNecessaryDetails[index].MarginO;
                    decimal lot    = netLot - this.VolumeNecessaryDetails[index].From;
                    if (index < this.VolumeNecessaryDetails.Count - 1)
                    {
                        lot = Math.Min(lot, (this.VolumeNecessaryDetails[index + 1].From - this.VolumeNecessaryDetails[index].From));
                    }
                    necessary += marginRate * margin * lot;

                    index++;
                }

                return(necessary);
            }
            else
            {
                throw new NotSupportedException(string.Format("Option = {0} is not supported", this.Option));
            }
        }
Beispiel #4
0
 internal void Remove(VolumeNecessaryDetail volumeNecessaryDetail)
 {
     this.VolumeNecessaryDetails.Remove(volumeNecessaryDetail);
 }