Exemple #1
0
        public void Initial(string startDate, string EndDate, int company, bool IsOTC = false)
        {
            DataList.Clear();
            RevenueList.Clear();
            List <string[]> temp    = new List <string[]>();
            string          command = "";

            #region  使否為上櫃股是資料
            if (IsOTC)
            {
                command = @"SELECT [company],[Column1],[Column16],[Column17],[Column18],[Column19],[Column76],[Column77],[Column95],[Column101],[Column75],[Column65],[Column15]
                                FROM [OverTheCounter].[dbo].[standard_analysis] where company =" + company + @"and [Column1] between '" + startDate + @"' and 
                                '" + EndDate + "' order by Column1";
            }
            else
            {
                command = @"SELECT [company],[Column1],[Column16],[Column17],[Column18],[Column19],[Column76],[Column77],[Column95],[Column101],[Column75],[Column65],[Column15]
                                FROM [StockDatabase].[dbo].[standard_analysis] where company =" + company + @"and [Column1] between '" + startDate + @"' and 
                                '" + EndDate + "' order by Column1";
            }

            gd.GetData(command, ref temp);

            for (int i = 0; i < temp.Count; i++)
            {
                DataList.Add(new BasicData(temp[i]));
            }


            if (IsOTC)
            {
                command = @"SELECT [company],[Column1],[Column2],[Column4],[Column5] FROM  [OverTheCounter].[dbo].[_monthRevenue] where company=" + company +
                          @" and [Column1] between '" + startDate + @"' and  '" + EndDate + @"' order by [Column1]";
            }
            else
            {
                command = @"SELECT [company],[Column1],[Column2],[Column4],[Column5] FROM [StockDatabase].[dbo].[_monthRevenue] where company=" + company +
                          @" and [Column1] between '" + startDate + @"' and  '" + EndDate + @"' order by [Column1]";
            }
            #endregion

            temp = new List <string[]>();

            gd.GetData(command, ref temp);

            for (int i = 0; i < temp.Count; i++)
            {
                RevenueList.Add(new MonthRevenue(temp[i]));
            }
        }
Exemple #2
0
        public void Initial(string startDate, string EndDate, int company)
        {
            bargin.Clear();
            barginReward.Clear();

            #region 初始化籌碼
            List <string[]> temp    = new List <string[]>();
            string          command = @"SELECT [company],[date],[ForeignInvestorNetBuySell],[InvestmentTrustNetBuySell],[DealerNetBuySell]
                ,[ForeignInvestorAccumulateBuySell],[InvestmentTrustAccumulateBuySell],[DealerAccumulateBuySell],[AllAccumulateBuySell],[marginloan]
                ,[stockloan],[marginloanUseRatio],[stockloanUseRatio],[MarginStockRatio] FROM [StockDatabaseWithTech].[dbo].[BargainData] where [Index] > "
                                      + company + "00000000 and [Index] <" + (company + 1) +
                                      "00000000 and [date] between '" + startDate + @"' and '" + EndDate + "' order by [date] ";

            gd.GetData(command, ref temp);

            for (int i = 0; i < temp.Count; i++)
            {
                bargin.Add(new Bargin(temp[i]));
            }
            #endregion

            #region 籌碼報酬初始化
            temp = new List <string[]>();

            command = @"SELECT [company],[date],[ForeignInvestorNetBuySell],[InvestmentTrustNetBuySell],[DealerNetBuySell]
            ,[ForeignInvestorBuySellDay],[InvestmentTrustBuySellDay],[DealerBuySellDay],[AllBuySellDay],[ForeignInvestorReward],[InvestmentTrustReward]
            ,[DealerReward],[AllReward] FROM [StockDatabaseWithTech].[dbo].[BargainRewardData] where [Index] > "
                      + company + "00000000 and [Index] <" + (company + 1) +
                      "00000000 and [date] between '" + startDate + @"' and '" + EndDate + "' order by [date] ";

            gd.GetData(command, ref temp);

            for (int i = 0; i < temp.Count; i++)
            {
                barginReward.Add(new BarginReward(temp[i]));
            }
            #endregion

            Initial_AcculateForeignInvestorNetBuySell(5, 10, 20, 120);
            Initial_AcculateInvestmentTrustNetBuySell(5, 10, 20, 120);
            Initial_AcculateAverageDealerNetBuySell(5, 10, 20, 120);
            Initial_MaxForeignInvestorNetBuySell(5, 10, 20, 40);
            Initial_MaxInvestmentTrustNetBuySell(5, 10, 20, 40);
            Initial_MaxDealerNetBuySell(5, 10, 20, 40);
            Initial_MinForeignInvestorNetBuySell(5, 10, 20, 40);
            Initial_MinInvestmentTrustNetBuySell(5, 10, 20, 40);
            Initial_MinDealerNetBuySell(5, 10, 20, 40);
        }
        public void StartToRun(string company = "3008", string startdate = "2012-01-01", string enddate = "2013-09-30")
        {
            string command = @"SELECT [Time],[_" + company + "] FROM [StockDatabase].[dbo].[technical_analysis] where [MyIndex]=209 and [Time] between '" + startdate + "' and '" + enddate + "' order by [Time]";

            gd.GetData(command, ref _company.closePrice);

            command = @"SELECT [Time],[_" + company + "] FROM [StockDatabase].[dbo].[technical_analysis] where [MyIndex]=213 and [Time] between '" + startdate + "' and '" + enddate + "' order by [Time]";

            gd.GetData(command, ref _company.HighPrice);

            command = @"SELECT [Time],[_" + company + "] FROM [StockDatabase].[dbo].[technical_analysis] where [MyIndex]=210 and [Time] between '" + startdate + "' and '" + enddate + "' order by [Time]";

            gd.GetData(command, ref _company.LowPrcie);

            _company.Initial_HighLowPrice();
            _company.KD_Line();
            _company.Initial_MACD();


            for (int i = 40; i < _company.closePrice.Count - 1; i++)
            {
                double J = 3 * _company.D_Line[i] - 2 * _company.D_Line[i];

                if (_company.D_Line[i - 1] > _company.K_Line[i - 1] && _company.K_Line[i] > _company.D_Line[i] && _company.K_Line[i - 1] < 20 &&
                    !hasbuy)
                {
                    sp.BuyStock(int.Parse(company), double.Parse(_company.closePrice[i][1])
                                , _company.closePrice[i][0]);
                    hasbuy = true;
                }

                if ((_company.D_Line[i] > 80 || _company.K_Line[i] > 80 ||
                     (_company.D_Line[i - 1] < _company.K_Line[i - 1] && _company.K_Line[i] < _company.D_Line[i] &&
                      _company.K_Line[i] > 70) || (_company.D_Line[i - 1] < _company.K_Line[i - 1] && _company.K_Line[i] < _company.D_Line[i] &&
                                                   _company.K_Line[i] < 30)
                     ) && hasbuy)
                {
                    sp.SellStock(int.Parse(company), double.Parse(_company.closePrice[i][1])
                                 , _company.closePrice[i][0]);
                    hasbuy = false;
                }
            }

            double tempp;

            tempp = sp.ProfitAndLoss();
        }
Exemple #4
0
        public void getData()
        {
            string command;

            command = @"SELECT [date],[ClosePrice],[Reward],[OpenPrice],[MaxPrice],[MinPrice]
                        FROM [StockDatabase].[dbo].[FutureDayDate] where [date] between '" + startDate + "' and '" + endDate + "' order by [date]";
            gd.GetData(command, ref data);
        }
        public void RiseLimit()
        {
            bool canbuy = true;

            string command = @"SELECT [Time],[_2330]
             FROM [StockDatabase].[dbo].[technical_analysis]
  
                where [MyIndex]=201 and [Time] between '2012-01-01' and '2013-09-30' order by [Time]";

            gd.GetData(command, ref ClosePrice);

            command = @"SELECT [Time],[_2330]
                        FROM [StockDatabase].[dbo].[technical_analysis]
  
                        where [MyIndex]=210  and [Time] between '2012-01-01' and '2013-09-30' order by [Time]";

            gd.GetData(command, ref RewardRatio);

            for (int i = 0; i < ClosePrice.Count; i++)
            {
                if (double.Parse(ClosePrice[i][1]) > 6 && canbuy)
                {
                    canbuy = false;
                    sp.BuyStock(3576, double.Parse(RewardRatio [i][1]), RewardRatio [i][0]);
                    Console.WriteLine(RewardRatio [i][1] + "    " + ClosePrice[i][1]);
                }

                if (!canbuy)
                {
                    Console.WriteLine(RewardRatio [i][1] + "    " + ClosePrice[i][1]);
                }

                if (double.Parse(ClosePrice[i][1]) < 1 && !canbuy)
                {
                    canbuy = true;
                    sp.SellStock(3576, double.Parse(RewardRatio [i][1]), RewardRatio [i][0]);
                    Console.WriteLine(RewardRatio [i][1] + "    " + ClosePrice[i][1]);
                }
            }

            sp.ProfitAndLoss();
            sp.clear();
        }
Exemple #6
0
        void GetCompany(ref List <string> company)
        {
            string command = "";

            if (IsOTC)
            {
                command = @"SELECT [company] FROM [OverTheCounter].[dbo].[standard_analysis] 
                      group by [company]  order by [company] ";
            }
            else
            {
                command = @"SELECT [company] FROM [StockDatabase].[dbo].[standard_analysis] 
                      group by [company]  order by [company] ";
            }

            GetDataFromDatabase gd = new GetDataFromDatabase();

            gd.GetData(command, ref company);
        }
Exemple #7
0
        public void Initial(string startDate, string EndDate, int company, bool IsOTC = false)
        {
            TechData.Clear();
            TaiwanIndex.Clear();

            #region 初始化股票
            List <string[]> temp = new List <string[]>();

            string command = "";

            #region 初始化command 看是否抓取上櫃公司資料
            if (IsOTC)
            {
                command = @"SELECT [company],[date],[OpenPrice],[HighestPrice] ,[LowestPrice],[ClosePrice] ,[RewardRatio] ,[Yield] ,[Volume]
                        FROM [OverTheCounter].[dbo].[TechData] where [Index] > "
                          + company + "00000000 and [Index] <" + (company + 1) +
                          "00000000 and [date] between '" + startDate + @"' and '" + EndDate + "' order by [date] ";
            }
            else
            {
                command = @"SELECT [company],[date],[OpenPrice],[HighestPrice] ,[LowestPrice],[ClosePrice] ,[RewardRatio] ,[Yield] ,[Volume]
                        FROM [StockDatabaseWithTech].[dbo].[TechData] where [Index] > "
                          + company + "00000000 and [Index] <" + (company + 1) +
                          "00000000 and [date] between '" + startDate + @"' and '" + EndDate + "' order by [date] ";
            }
            #endregion


            gd.GetData(command, ref temp);
            for (int i = 0; i < temp.Count; i++)
            {
                TechData.Add(new TechnologicalData(temp[i]));
            }

            #endregion

            #region 初始化指數
            if (TechData.Count == 0)
            {
                return;
            }
            string sDate = TechData[0].date.ToString().Split(' ')[0].Replace("/", "-");
            command = @"SELECT [date],[OpenPrice],[MaxPrice],[MinPrice] ,[ClosePrice] FROM [StockDatabase].[dbo].[FutureDayDate]
                    where [date] between '" + sDate + "' and '" + EndDate + "' order by [date]";
            gd.GetData(command, ref temp);

            double LastClose = 0;// double.Parse(temp[0][4]);

            for (int i = 0; i < temp.Count; i++)
            {
                TaiwanIndex.Add(new TaiwanStockIndex(temp[i], LastClose));
                LastClose = double.Parse(temp[i][4]);
            }
            #endregion

            #region 資料遺漏在大盤刪除
            for (int i = 0; i < TechData.Count; i++)
            {
            }
            #endregion

            Initial_AveragePrice(5, 12, 20, 60, 120);
            Initial_AverageVolume(5, 10, 20, 40);
            Initial_MaxClosePrice(5, 10, 20, 60, 120);
            Initial_MinClosePrice(5, 10, 20, 60, 240);
            Initial_MaxVolume(5, 10, 20, 40);
            Initial_MinVolume(5, 10, 20, 40);
            Initial_Acculation(3, 5, 10, 20, 40);
        }
        public void StartToRun()
        {
            gd.GetData(command, ref temp);
            double [] TheBest = new double [10];
            double    tempp;

            int[] longday  = new int[10];
            int[] shortday = new int[10];
            bool  CanBuy   = true;
            int   number   = 2062;

            //for (int k = 1;  k< 100; k++)
            //{
            //for (int j = k+1; j < 100; j++)
            //{
            AverageLine _2330 = new AverageLine();

            _2330.Initial(5, 20, temp);

            for (int i = _2330.longTermDays + 1; i < temp.Count; i++)
            {
                if (_2330.LongTermLine[i - 1] > _2330.ShortTermLine[i - 1] && _2330.ShortTermLine[i] > _2330.LongTermLine[i] && CanBuy)
                {
                    CanBuy = false;
                    sp.BuyStock(number, double.Parse(temp[i][1]), temp[i][0]);
                }
                //if ((_2330.ShortTermSlope[i - 1] < 0 && _2330.ShortTermSlope[i] > 0) && (_2330.ShortTermLine[i] < _2330.LongTermLine[i]) && CanBuy)
                //{
                //    CanBuy = false;
                //    sp.BuyStock(2330, double.Parse(temp[i][1]), temp[i][0]);
                //}

                if ((_2330.LongTermLine[i - 1] < _2330.ShortTermLine[i - 1] && _2330.ShortTermLine[i] < _2330.LongTermLine[i]) ||
                    (_2330.LongTermLine[i - 1] < _2330.ShortTermLine[i - 1] && _2330.ShortTermLine[i] == _2330.LongTermLine[i]
                    ) &&
                    !CanBuy)
                {
                    CanBuy = true;
                    sp.SellStock(number, double.Parse(temp[i][1]), temp[i][0]);
                }

                //if ((_2330.ShortTermSlope[i - 1] > 0 && _2330.ShortTermSlope[i] < 0) && (_2330.ShortTermLine[i] > _2330.LongTermLine[i]) && !CanBuy)
                //{
                //    CanBuy = true;
                //    sp.SellStock(2330, double.Parse(temp[i][1]), temp[i][0]);
                //}
            }

            //for (int jj = 0; jj < _2330.ShortTermLine.Length; jj++)
            //{
            //    Console.WriteLine(_2330.PriceAndDate[jj][0]+"   "+  _2330.ShortTermLine[jj] + "       " + _2330.LongTermLine[jj]);
            //}

            tempp = sp.ProfitAndLoss();
            // sp.clear(true);

            //#region
            //if (TheBest[0] < tempp)
            //{
            //    sp.clear(true);
            //    TheBest[0] = tempp;
            //    shortday[0] = k;
            //    longday[0] = j;
            //}
            //else if (TheBest[1] < tempp)
            //{
            //    TheBest[1] = tempp;
            //    shortday[1] = k;
            //    longday[1] = j;
            //}
            //else if (TheBest[2] < tempp)
            //{
            //    TheBest[2] = tempp;
            //    shortday[2] = k;
            //    longday[2] = j;
            //}
            //else if (TheBest[3] < tempp)
            //{
            //    TheBest[3] = tempp;
            //    shortday[3] = k;
            //    longday[3] = j;
            //}
            //else if (TheBest[4] < tempp)
            //{
            //    TheBest[4] = tempp;
            //    shortday[4] = k;
            //    longday[4] = j;
            //}
            //else if (TheBest[5] < tempp)
            //{
            //    TheBest[5] = tempp;
            //    shortday[5] = k;
            //    longday[5] = j;
            //}
            //else if (TheBest[6] < tempp)
            //{
            //    TheBest[6] = tempp;
            //    shortday[6] = k;
            //    longday[6] = j;
            //}
            //else if (TheBest[7] < tempp)
            //{
            //    TheBest[7] = tempp;
            //    shortday[7] = k;
            //    longday[7] = j;
            //}
            //else if (TheBest[8] < tempp)
            //{
            //    TheBest[8] = tempp;
            //    shortday[8] = k;
            //    longday[8] = j;
            //}
            //else if (TheBest[9] < tempp)
            //{
            //    TheBest[9] = tempp;
            //    shortday[9] = k;
            //    longday[9] = j;
            //}
            //#endregion

            sp.clear();
            //}
            //}

            Console.WriteLine(TheBest + "  " + shortday + " " + longday);

            //StreamWriter sw = new StreamWriter(@"C:\Users\user\Desktop\股票\股票venture\平均線 結果\黃金交叉死亡交叉.txt");

            //for (int i = 0; i < TheBest.Length; i++)
            //{
            //    sw.WriteLine(TheBest[i] + "  " + shortday[i] + "   " + longday[i]);
            //}
            //sw.Close();
        }