Пример #1
0
        private static (double, double) TakeNthElemValue(List <Stock> list, Coefficient coef)
        {
            var query = (from st in list
                         let norm = st.NormalizedCoefficientsValues[coef]
                                    where norm != null
                                    orderby norm.Value
                                    select norm.Value).ToList();

            if (query.Count == 0)
            {
                return(0, 0);
            }
            return(query[(int)Math.Round((double)s_fromPercent * query.Count / 100)], query.Take((int)Math.Round(
                                                                                                     (double)s_toPercent * query.Count / 100)).Last());
        }
Пример #2
0
        /// <summary>
        /// Анализирует показатели акций, превращая их в одно число, используя метрики
        /// </summary>
        /// <param name="stList">Список акций</param>
        public static void Analyze(StockList stList)
        {
            var list = stList.StList.ToList();

            foreach (var st in list)
            {
                foreach (var coef in Coefficient.CoefficientList)
                {
                    st.NormalizedCoefficientsValues[coef] = coef.Normalize(st[coef]);
                }
            }

            Dictionary <Coefficient, double> leftBorders  = new Dictionary <Coefficient, double>(Coefficient.CoefficientList.Count);
            Dictionary <Coefficient, double> rightBorders = new Dictionary <Coefficient, double>(Coefficient.CoefficientList.Count);

            foreach (var coef in Coefficient.CoefficientList)
            {
                var borders = TakeNthElemValue(list, coef);
                leftBorders[coef]  = borders.Item1;
                rightBorders[coef] = borders.Item2;
            }

            string data = "Название акции;Market;";

            using (var sWrite = new StreamWriter(OutputFileName, true, Encoding.UTF8))
            {
                // Write the metrics names
                foreach (var str in Coefficient.MetricsList)
                {
                    data += str.ToString() + ';';
                }
                data += ";";
                foreach (var str in Coefficient.CoefficientList.Select(c => c.Name))
                {
                    data += str + ';';
                }
                sWrite.WriteLine(data);

                foreach (Stock st in list)
                {
                    data = $"{st.Name.Replace(';', '.')};{st.Market.Location.ToString()};";

                    foreach (var metric in Coefficient.MetricsList)
                    {
                        st.MetricsValues[metric] = 0;
                        foreach (var coef in Coefficient.CoefficientList)
                        {
                            var compactVal = Compact(st.NormalizedCoefficientsValues[coef], leftBorders[coef],
                                                     rightBorders[coef]);
                            st.MetricsValues[metric] += Coefficient.SignedSqr(compactVal) *
                                                        coef.MetricWeight[metric];
                        }
                        data += st.MetricsValues[metric].ToString(CultureInfo.InvariantCulture) + ';';
                    }

                    data += ';';
                    foreach (var param in st.NormalizedCoefficientsValues.Keys)
                    {
                        data += st.NormalizedCoefficientsValues[param].ToString() + ';';
                    }
                    sWrite.WriteLine(data);
                }
            }

            SetRatings(stList, list);
        }
Пример #3
0
 public void CalculateCoef(Coefficient coef)
 {
     this[coef] = coef.CalculateCoef(CoefficientsValues);
 }
Пример #4
0
 public double?this[Coefficient coef]
 {
     get => CoefficientsValues[coef];
Пример #5
0
 public bool Equals(Coefficient coef)
 {
     return(Name == coef.Name);
 }