Example #1
0
        private SortedList <CSPrice> LoadDayPrices(int day)
        {
            SortedList <CSPrice> ret = new SortedList <CSPrice>(Comp_CSPrice);

            ret.AddRange(StorageLoader.LoadStorage(DateToDay.ToDate(day), CurrencyPair));
            return(ret);
        }
Example #2
0
        private int Test01_b(int nextDate, int date, CSChart csc)
        {
            for (int c = 0; c <
                 4
                 //10
                 //20
                 ; c++)
            {
                {
                    long dt     = date * 1000000L + 90000;
                    long nextDt = nextDate * 1000000L + 90000;

                    if (csc.GetPrice(dt).Mid < csc.GetPrice(nextDt).Mid)
                    {
                        break;
                    }
                }

                do
                {
                    nextDate = DateToDay.ToDate(DateToDay.ToDay(nextDate) + 1);
                }while ("土日".Contains(DateTimeUnit.FromDate(nextDate).GetWeekday()));
            }
            return(nextDate);
        }
Example #3
0
        private void Init()
        {
            int date = (int)(this.DateTime / 1000000L);

            if (this.Cache[date].HasPrice(this.DateTime))
            {
                Exac = this.Cache[date].GetPrice(this.DateTime);
            }
            else
            {
                int bkDate = date;

                // Prev
                {
                    if (this.Cache[date].HasPrevPrice(this.DateTime))
                    {
                        Prev = this.Cache[date].GetPrevPrice(this.DateTime);
                    }
                    else
                    {
                        for (int c = 0; c < EMPTY_DAY_MAX; c++)
                        {
                            date = DateToDay.toDate(DateToDay.toDay(date) - 1);

                            if (this.Cache[date].IsEmpty() == false)
                            {
                                Prev = this.Cache[date].GetLastPrice();
                                break;
                            }
                        }
                    }
                }

                date = bkDate;

                // Next
                {
                    if (this.Cache[date].HasNextPrice(this.DateTime))
                    {
                        Next = this.Cache[date].GetNextPrice(this.DateTime);
                    }
                    else
                    {
                        for (int c = 0; c < EMPTY_DAY_MAX; c++)
                        {
                            date = DateToDay.toDate(DateToDay.toDay(date) + 1);

                            if (this.Cache[date].IsEmpty() == false)
                            {
                                Next = this.Cache[date].GetFirstPrice();
                                break;
                            }
                        }
                    }
                }
            }
        }
Example #4
0
        private void Test01_a(int dateStart, int dateEnd)
        {
            for (int maDay = 5; maDay <= 30; maDay += 5)
            {
                List <Info> infos = new List <Info>();

                CSChartManager cscm = new CSChartManager();
                CSChart        csc  = cscm.GetCSChart("USDJPY");
                TTChart        ttc  = new TTChart(csc);
                MAChart        mac  = new MAChart(ttSec => ttc.GetPrice(ttSec).Mid, 60 * 24 * maDay, 60);

                for (int date = dateStart; date <= dateEnd;)
                {
                    int nextDate = date;

                    do
                    {
                        nextDate = DateToDay.ToDate(DateToDay.ToDay(nextDate) + 1);
                    }while ("土日".Contains(DateTimeUnit.FromDate(nextDate).GetWeekday()));

                    int bNextDate = Test01_b(nextDate, date, csc);

                    long dt      = date * 1000000L + 90000;
                    long bNextDt = bNextDate * 1000000L + 90000;

                    // ----

                    infos.Add(new Info()
                    {
                        MvAvgPrice   = mac.GetPrice(TTCommon.DateTimeToTTSec(dt)),
                        Price        = csc.GetPrice(dt).Mid,
                        NextDayPrice = csc.GetPrice(bNextDt).Mid,
                    });

                    // ----

                    date = nextDate;
                }

                using (CsvFileWriter writer = new CsvFileWriter(string.Format(@"C:\temp\maDay={0}.csv", maDay)))
                {
                    foreach (Info info in infos)
                    {
                        writer.WriteCell(info.Price.ToString("F9"));
                        writer.WriteCell(info.MvAvgPrice.ToString("F9"));
                        writer.WriteCell(info.NextDayPrice.ToString("F9"));
                        writer.WriteCell((info.MvAvgPrice / info.Price).ToString("F9"));
                        writer.WriteCell((info.NextDayPrice / info.Price).ToString("F9"));
                        writer.EndRow();
                    }
                }
            }
        }
Example #5
0
        public static void CheckDate(int date)
        {
            if (date < CSConsts.DATE_TIME_MIN / 1000000 || CSConsts.DATE_TIME_MAX / 1000000 < date)
            {
                throw new Exception("Out of range date: " + date);
            }

            if (DateToDay.ToDate(DateToDay.ToDay(date)) != date)
            {
                throw new Exception("Bad date: " + date);
            }
        }
Example #6
0
        public void FxCollected()
        {
            long dateTime = DateTimeToSec.Now.getDateTime();
            int  date     = (int)(dateTime / 1000000L);
            int  time     = (int)(dateTime % 1000000L);

            TryReload(date);

            if (time < 500)                                         // ? 日付更新から 5 min 未満 -> 昨日もリロードしておく
            {
                date = DateToDay.toDate(DateToDay.toDay(date) - 1); // 昨日
                TryReload(date);
            }
        }
Example #7
0
        public CSPrice GetPrice(long dateTime)
        {
            Validators.CheckDateTime(dateTime);

            int day = DateToDay.ToDay((int)(dateTime / 1000000));
            SortedList <CSPrice> prices = GetDayPrices(day);

            CSPrice[] matched = prices.GetMatchWithEdge(prices.GetFerret(new CSPrice()
            {
                DateTime = dateTime
            })).ToArray();

            if (matched.Length == 3)
            {
                return(matched[1]);
            }

            if (matched.Length != 2)
            {
                throw null;                 // 2bs -- 同じ日時のデータは無いはず!
            }
            if (matched[0] == null)
            {
                for (int c = 1; c <= Consts.MARGIN_DAY_MAX; c++)
                {
                    prices = GetDayPrices(day - c);

                    if (1 <= prices.Count)
                    {
                        matched[0] = prices.Get(prices.Count - 1);
                        break;
                    }
                }
            }
            if (matched[1] == null)
            {
                for (int c = 1; c <= Consts.MARGIN_DAY_MAX; c++)
                {
                    prices = GetDayPrices(day + c);

                    if (1 <= prices.Count)
                    {
                        matched[0] = prices.Get(0);
                        break;
                    }
                }
            }
            matched = matched.Where(v => v != null).ToArray();

            if (matched.Length == 0)
            {
                return new CSPrice()
                       {
                           DateTime = dateTime
                       }
            }
            ;

            if (matched.Length == 1)
            {
                return(matched[0]);
            }

            long sec1 = DateTimeToSec.ToSec(matched[0].DateTime);
            long sec2 = DateTimeToSec.ToSec(dateTime);
            long sec3 = DateTimeToSec.ToSec(matched[1].DateTime);

            double rate = (sec2 - sec1) * 1.0 / (sec3 - sec1);

            return(new CSPrice()
            {
                DateTime = dateTime,
                Hig = matched[0].Hig + rate * (matched[1].Hig - matched[0].Hig),
                Low = matched[0].Low + rate * (matched[1].Low - matched[0].Low),
                Ask = matched[0].Ask + rate * (matched[1].Ask - matched[0].Ask),
                Bid = matched[0].Bid + rate * (matched[1].Bid - matched[0].Bid),
            });
        }
    }