Esempio n. 1
0
 private bool checkCodeTradeinDb(string code, DateTime tradeTimestamp)
 {
     var db = new dataEntities();
     var rowstat = (from pr in db.ri_data
                     where pr.Code == code && pr.TradeTimestamp == tradeTimestamp
                     select pr).Count();
     if (rowstat ==0)
     {
         return false;
     }
     else
     {
         return true;
     }
 }
Esempio n. 2
0
 private List<PriceTime> UploaddatafromDb(DateTime startdate,DateTime enddate,int timeframe)
 {
     var Pricelist = new List<PriceTime>();
     DateTime TimeStartConvert = DateTime.Now;
     var i = 0;
     var db = new dataEntities();
     List<PriceTime> tempprices = new List<PriceTime>((from pr in db.temp_upload
                                        where pr.Date < enddate.Date && pr.Date > startdate.Date
                                        select new PriceTime{Date = (DateTime) (pr.Datetime),Volume = (double) pr.Qty, Price = (double) pr.VWAP}).ToList().OrderBy(t=>t.Date));
     List<PriceTime> prices = new List<PriceTime>();
     for (int j = 0; j < tempprices.Count; j=(j+1)*timeframe)
     {
         double price = 0;
         double volume = 0;
         int k = 0;
         while ((j+k<tempprices.Count)&&(k<timeframe))
         //for (int k = 0; k < timeframe; k++)
         {
             volume = volume + tempprices[j + k].Volume;
             price = price+tempprices[j + k].Volume * tempprices[j + k].Price;
             k++;
         }
         prices.Add(new PriceTime { Date = tempprices[j].Date, Volume = volume, Price = price / volume });
     }
     DateTime TimeEndConvert = DateTime.Now;
     LogTextBox.AppendText("\r\n" + TimeEndConvert.ToLongTimeString() + ": " + "Prices uploaded. Total items: " + prices.Count().ToString());
     return prices;
 }
Esempio n. 3
0
        private void button3_Click(object sender, EventArgs e)
        {
            var sizeStart = (int)SizeOfPriceWindow.Value;
            var sizeEnd = (int)SizeOfPriceWindowEnd.Value;
            var vsize = (int)SizeOfVolumeWindow.Value * 100;
            var vsizeEnd = (int)SizeOfVolumeWindowEnd.Value * 100;
            var sizestep = 100;
            var vsizestep = 500;
            int timeframe = (int)timeframeupdown.Value;
            int timeframe2 = (int)timeframeUpDown2.Value;

            if (!PricesUploaded.Checked)
            {
                pricelist = PricesFromDb.Checked ? UploaddatafromDb(dateTimeStartUploadPrices.Value.Date, dateTimeEndUploadPrices.Value.Date, 1) : Uploaddatafromfile();
                PricesUploaded.Checked = true;
            }

            if (!StatReady.Checked)
            {
                stat = calculateAdap3Time(pricelist, (int)numberofpoints.Value, (int)numberofpointsEnd.Value,(int)timeframeupdown.Value, NumberPointPrice, NumberPointVol);
                if (StattoDB.Checked)
                {
                    var db = new dataEntities();
                    var i = 0;
                    foreach (string key in stat.Keys)
                    {
                        db.stats.Add(new stat
                        {
                            Code = key,
                            Count = stat[key].Count,
                            Up2win = stat[key].pos2window,
                            // Down2win = stat[key].neg2window,
                            Up4win = stat[key].pos4window,
                            // Down4win = stat[key].neg4window
                        });
                        i++;
                        if (i % 500 == 0) SaveDBChanges(db);
                    }
                    SaveDBChanges(db);
                    db.Dispose();
                }
            }
            var pricelistControl = PricesFromDb.Checked ? UploaddatafromDb(dateTimeStartControlPrices.Value.Date, dateTimeEndControlPrices.Value.Date,1) : Uploaddatafromfile();

               // checkAlgorithm2(pricelistControl, stat, sizeStart, sizeEnd, sizestep, vsize, vsizeEnd, vsizestep, (int)numberofpoints.Value, (int)numberofpointsEnd.Value, (int)timeframeupdown.Value);
            var t = 1;// stat.Where(t => t.Value > 1);
        }
Esempio n. 4
0
        private void button2_Click(object sender, EventArgs e)
        {
            var db = new dataEntities();
            string lastupdate = (from pr in db.temp_upload
                                 select pr.Datetime).Max().Value.ToString();

            label6.Text = lastupdate;
        }
Esempio n. 5
0
 private static void SaveDBChanges(dataEntities db)
 {
     try
     {
         db.SaveChanges();
     }
     catch (DbEntityValidationException er)
     {
         foreach (var eve in er.EntityValidationErrors)
         {
             Console.WriteLine(
                 "Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                 eve.Entry.Entity.GetType().Name, eve.Entry.State);
             foreach (var ve in eve.ValidationErrors)
             {
                 Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                   ve.PropertyName, ve.ErrorMessage);
             }
         }
         throw;
     }
 }
Esempio n. 6
0
 private static PriceTime GetPriceByTimeFrameFromDB(DateTime startdate, int timeframe,int shift =0)
 {
     var db = new dataEntities();
     var enddate = startdate.AddMinutes(-timeframe*(shift+1));//45 46 47 48 49   50 51 52 53 54   55
     startdate = startdate.AddMinutes(-timeframe*shift);//             50
     var list = (db.temp_upload.Where(pr => pr.Datetime > enddate && pr.Datetime <= startdate).Select(pr => new PriceTime {Date = (DateTime) (pr.Datetime), Volume = (double) pr.Qty, Price = (double) pr.VWAP})).ToList();
     var tempprices = new List<PriceTime>(list.OrderBy(t => t.Date));
     double price = 0;
     double volume = 0;
     foreach (PriceTime t in tempprices)
     {
         volume = volume + t.Volume;
         price = price + t.Volume * t.Price;
     }
     return new PriceTime {Date = startdate, Volume = volume, Price = price/volume};
 }
Esempio n. 7
0
        private static PriceTime GetPriceByTimeFrameFromArray(List<PriceTime>  pricelist,int startpos, int timeframe, int shift = 0)
        {
            var db = new dataEntities();
            var endpos = startpos-timeframe * (shift + 1)+1;//45 46 47 48 49   50 51 52 53 54   55
            startpos = startpos -timeframe * shift;//             50
              //  var list = (db.temp_upload.Where(pr => pr.Datetime > enddate && pr.Datetime <= startdate).Select(pr => new PriceTime { Date = (DateTime)(pr.Datetime), Volume = (double)pr.Qty, Price = (double)pr.VWAP })).ToList();
              //  var tempprices = new List<PriceTime>(list.OrderBy(t => t.Date));
            double price = 0;
            double volume = 0;

            for (var i = endpos; i <= startpos;i++ ){
                volume = volume + pricelist[i].Volume;
                price = price + pricelist[i].Volume * pricelist[i].Price;
                }
            return new PriceTime { Date = pricelist[startpos].Date, Volume = volume, Price = price / volume };
        }