示例#1
0
        private double[] GetPrices(List <SecurityItem> secuList)
        {
            double[] prices = new double[_spotDataSource.Count];
            for (int i = 0, count = _spotDataSource.Count; i < count; i++)
            {
                var stock    = _spotDataSource[i];
                var secuItem = secuList.Find(p => p.SecuCode.Equals(stock.SecuCode) && p.SecuType == SecurityType.Stock);
                if (secuItem != null)
                {
                    var secuData = QuoteCenter.Instance.GetMarketData(secuItem);
                    stock.ELimitUpDownFlag = secuData.LimitUpDownFlag;
                    stock.ESuspendFlag     = secuData.SuspendFlag;

                    if (!FloatUtil.IsZero(secuData.CurrentPrice))
                    {
                        prices[i] = secuData.CurrentPrice;
                    }
                    else if (!FloatUtil.IsZero(secuData.PreClose))
                    {
                        prices[i] = secuData.PreClose;
                    }
                    else
                    {
                        prices[i] = secuData.LowLimitPrice;
                    }
                }
                else
                {
                    prices[i] = 0f;
                }
            }

            return(prices);
        }
示例#2
0
        private void ToolStripButton_CalcAmount_Click(object sender, EventArgs e)
        {
            StockTemplate template = GetSelectTemplate();

            if (template == null)
            {
                return;
            }

            if (_spotDataSource == null || _spotDataSource.Count == 0)
            {
                return;
            }

            //var invalidSecuItem = _spotDataSource.Where(p => FloatUtil.IsZero(p.SettingWeight) || p.Amount == 0).ToList();
            var invalidSecuItem = _spotDataSource.Where(p => FloatUtil.IsZero(p.SettingWeight)).ToList();

            if (invalidSecuItem != null && invalidSecuItem.Count() > 0)
            {
                if (MessageDialog.Warn(this, msgSecurityZeroWeight, MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.No)
                {
                    return;
                }
                else
                {
                    foreach (var item in invalidSecuItem)
                    {
                        _spotDataSource.Remove(item);
                    }
                }
            }

            ReCalculateAmount(template);
            SummaryTemplateStock();
            SwitchTemplateStockSave(true);

            this.secuGridView.Invalidate();
        }
 public static string ToKmphPreciseString(SpeedValue speed)
 {
     return(FloatUtil.IsZero(speed.GameUnits)
                ? Translation.GetString("Speed_limit_unlimited")
                : speed.ToKmphPrecise().ToString());
 }
示例#4
0
 /// <summary>
 /// Converts a possibly zero (no limit) custom speed limit to a game speed limit.
 /// </summary>
 /// <param name="customSpeedLimit">Custom speed limit which can be zero</param>
 /// <returns>Speed limit in game speed units</returns>
 public float ToGameSpeedLimit(float customSpeedLimit)
 {
     return(FloatUtil.IsZero(customSpeedLimit)
                ? MAX_SPEED
                : customSpeedLimit);
 }
示例#5
0
 public static string ToMphPreciseString(SpeedValue speed)
 {
     return(FloatUtil.IsZero(speed.GameUnits)
                ? Translation.SpeedLimits.Get("Unlimited")
                : speed.ToMphPrecise().ToString());
 }
示例#6
0
        private void ReCalculateAmount(StockTemplate template)
        {
            double[] weights     = _spotDataSource.Select(p => p.SettingWeight / 100).ToArray();
            double   totalWeight = weights.Sum();
            double   minusResult = 1.0 - totalWeight;

            double[] mweights = _spotDataSource.Select(p => p.MarketCapWeight / 100).ToArray();
            double   mtotal   = mweights.Sum();
            double   mDiff    = 1.0 - mtotal;

            //如果不为100%,则需要调整比例; 依据市值调整
            if (Math.Abs(minusResult) > 0.001 && mDiff > 0.001)
            {
                for (int i = 0, count = _spotDataSource.Count; i < count; i++)
                {
                    var stock = _spotDataSource[i];
                    weights[i] = stock.MarketCapWeight / mtotal;
                }
            }

            List <SecurityItem> secuList = GetSecurityItems(template);

            var    benchmarkItem = _securityInfoList.Find(p => p.SecuCode.Equals(template.Benchmark) && p.SecuType == SecurityType.Index);
            var    benchmarkData = QuoteCenter.Instance.GetMarketData(benchmarkItem);
            var    benchmark     = _benchmarkList.Find(p => p.BenchmarkId.Equals(benchmarkItem.SecuCode));
            double bmkPrice      = 0f;
            double totalValue    = 0f;

            if (!FloatUtil.IsZero(benchmarkData.CurrentPrice))
            {
                bmkPrice = benchmarkData.CurrentPrice;
            }
            else if (!FloatUtil.IsZero(benchmarkData.PreClose))
            {
                bmkPrice = benchmarkData.PreClose;
            }

            //指数基准当期总市值
            //上证50、沪深300、中证500每一个点数对应不同的价格
            totalValue = bmkPrice * benchmark.ContractMultiple;
            totalValue = totalValue * template.MarketCapOpt / 100;

            var prices  = GetPrices(secuList);
            var amounts = CalcUtil.CalcStockAmountPerCopyRound(totalValue, weights, prices, 0);
            var mktCaps = GetMarketCap(prices, amounts);

            switch (template.EWeightType)
            {
            case Model.EnumType.WeightType.ProportionalWeight:
            {
                double totalCap = mktCaps.Sum();
                for (int i = 0, count = _spotDataSource.Count; i < count; i++)
                {
                    var stock = _spotDataSource[i];
                    stock.Amount          = amounts[i];
                    stock.MarketCap       = mktCaps[i];
                    stock.MarketCapWeight = 100 * stock.MarketCap / totalCap;
                }
            }
            break;

            case Model.EnumType.WeightType.AmountWeight:
            {
                var    totalAmount = amounts.Sum();
                double totalCap    = mktCaps.Sum();
                for (int i = 0, count = _spotDataSource.Count; i < count; i++)
                {
                    var stock = _spotDataSource[i];
                    stock.Amount          = amounts[i];
                    stock.MarketCap       = mktCaps[i];
                    stock.MarketCapWeight = 100 * stock.MarketCap / totalCap;
                    stock.SettingWeight   = 100 * (double)stock.Amount / (double)totalAmount;
                }
            }
            break;

            default:
                break;
            }
        }