示例#1
0
 private void FundsPredict()
 {
     foreach (Fund fund in funds)
     {
         double chip = Think.Predict(fund);
         double cost = chip * (double)fund.RealValue * 100;
         fundTable.Select($"Code = '{fund.Code}'").FirstOrDefault()["Buy"] = Math.Round(cost, 0);
     }
 }
示例#2
0
        private void FundsCalculate()
        {
            DateTime startTime = DateTime.Now.AddYears(-1);

            foreach (Fund fund in funds)
            {
                Think.Calculate(startTime, fund);
            }
        }
示例#3
0
        private void ChartDarw(Fund fund)
        {
            chartFundCode = fund.Code;
            tabControl1.TabPages[3].Text = fund.Name;
            chart1.Series["line1"].Points.Clear();
            chart1.Series["line2"].Points.Clear();
            chart1.Series["line3"].Points.Clear();
            chart1.Series["line4"].Points.Clear();
            chart1.Series["line5"].Points.Clear();

            int    x1 = 0;
            double y1 = Think.EquationCalculate(fund.Coefs[1], fund.Coefs[0], x1);
            int    x2 = fund.ThinkEndIndex - fund.ThinkStartIndex;
            double y2 = Think.EquationCalculate(fund.Coefs[1], fund.Coefs[0], x2);

            chart1.Series["line4"].Points.AddXY(x1, y1);
            chart1.Series["line4"].Points.AddXY(x2, y2);
            for (int i = fund.ThinkStartIndex; i < fund.ThinkEndIndex; i++)
            {
                chart1.Series["line1"].Points.AddXY(i - fund.ThinkStartIndex, fund.HistoryList[i].Item2);
                if (fund.IncFlags[i - fund.ThinkStartIndex] == 1)
                {
                    chart1.Series["line2"].Points.AddXY(i - fund.ThinkStartIndex, fund.HistoryList[i].Item2);
                }
                else if (fund.IncFlags[i - fund.ThinkStartIndex] == -1)
                {
                    chart1.Series["line3"].Points.AddXY(i - fund.ThinkStartIndex, fund.HistoryList[i].Item2);
                }

                //if (fund.Tages[i - fund.ThinkStartIndex] == 1)
                //{
                //    chart1.Series["line5"].Points.AddXY(i - fund.ThinkStartIndex, fund.HistoryList[i].Item2);
                //}
            }
            chart1.Series["line1"].Points.AddXY(fund.ThinkEndIndex - fund.ThinkStartIndex, fund.RealValue); //实时的加到最后
            TabPage page = tabControl1.TabPages[3];

            tabControl1.SelectedTab = page;
            //tabControl1.TabPages.Remove(page);
            //tabControl1.TabPages.Add(page);
        }
示例#4
0
        /// <summary>
        /// 基金实时更新
        /// </summary>
        private void fundsRealUpdate()
        {
            foreach (var fund in funds)
            {
                double realVal;
                double realInc;
                if (GetFundIncNow(fund.Code, out realVal, out realInc))
                {
                    fund.RealValue    = realVal;
                    fund.RealIncrease = realInc;

                    double equation = Think.EquationCalculate(fund.Coefs[1], fund.Coefs[0], fund.ThinkEndIndex - fund.ThinkStartIndex);
                    double reg      = (realVal - equation) / equation;
                    fund.RealSigma = (reg - fund.μInc) / fund.σInc;

                    //double chip = Think.Predict(fund);
                    //double cost = chip * (double)fund.RealValue * 100;
                    //fund.RealCost = cost;
                }
            }
        }
示例#5
0
        /// <summary>
        /// 收益率计算
        /// </summary>
        /// <param name="fund"></param>
        /// <param name="startTime"></param>
        /// <param name="endTimeStart"></param>
        /// <param name="endTimeEnd"></param>
        /// <returns></returns>
        public double YieldRate(Fund fund, DateTime startTime, DateTime endTimeStart, DateTime endTimeEnd)
        {
            //fund.CreateHistoryList();
            double money      = 100;
            double costSum    = 0.0; //花费
            double earnSum    = 0.0; //收益
            double chipSum    = 0.0;
            double chipSumMax = double.MinValue;
            double chipSumMin = double.MaxValue;
            double moneyMax   = double.MinValue;
            double moneyMin   = double.MaxValue;
            double valueNow   = 0.0;
            //Think.Calculate(startTime, DateTime.Now, fund, out needFundValues, out fundPointsFinal, out t1, out t2);
            DateTime endTime = DateTime.Now;

            for (endTime = endTimeStart; endTime < endTimeEnd; endTime = endTime.AddDays(1))
            {
                Console.WriteLine(endTime);
                Think.Calculate(startTime, endTime, fund);
                if (!fund.HistoryDic.Keys.Contains(endTime))
                {
                    continue;
                }
                int index = fund.HistoryList.FindIndex(x => x.Item1 > endTime);
                if (index < 0)
                {
                    break;
                }
                valueNow = fund.HistoryList[index].Item2;
                double chip = Think.Predict(fund, valueNow, index - 1);

                if (chip == 0)
                {
                    continue;                                       //没有变动
                }
                double cost = chip * fund.HistoryList[index].Item2; //花费
                if (chip > 0)
                {                                                   //买入
                  //if (money - cost < 0)
                  //{
                  //    cost = money;
                  //    chip = cost / fund.HistoryList[index].Item2;
                  //}

                    money   -= cost;
                    costSum += cost;
                }
                else if (chip < 0)
                { //卖出
                    //if (chipSum + chip < 0) chip = -chipSum;
                    cost     = chip * fund.HistoryList[index].Item2;
                    earnSum -= cost;
                    money   -= cost;
                }

                //记录最大最小值
                if (money > moneyMax)
                {
                    moneyMax = money;
                }
                if (money < moneyMin)
                {
                    moneyMin = money;
                }
                chipSum += chip;
                if (chipSum > chipSumMax)
                {
                    chipSumMax = chipSum;
                }
                if (chipSum < chipSumMin)
                {
                    chipSumMin = chipSum;
                }
            }

            double rate = ((earnSum + chipSum * valueNow) / costSum - 1) * 100; //总收益率(%)

            return(rate);
        }