public void WriteTo(String fileOutPath, PeriodicMarketDataCollection spot, 
            PeriodicMarketDataCollection future, TradingDirection spotDirection)
        {
            EventPointsFinder target = new EventPointsFinder();
            List<EventPoint> eventPoints = target.GetEventPoints(spot, future, spotDirection);
            CsvFileWriter writer = new CsvFileWriter(fileOutPath);

            WriteHeader(writer);
            WriteBody(writer, eventPoints);

            logger.Info("Write {0} complete...", fileOutPath);

            writer.Close();
        }
Esempio n. 2
0
        List<DateTimeDoublePair> GetIndicators_Raw(
            DateTime targetDate,
            DayDataKtbAvg spotYesAvg,
            PeriodicMarketDataCollection spotData,
            DayDataKtbAvg futureYesAvg,
            PeriodicMarketDataCollection futureData)
        {
            List<DateTimeDoublePair> ret = new List<DateTimeDoublePair>();

            double spotAvgPrice = spotYesAvg.PriceAvg;
            double spotDuration = spotYesAvg.DurationAvg;

            double futureAvgPrice = futureYesAvg.PriceAvg;
            double futureDuration = futureYesAvg.DurationAvg;

            double kMinValue = -4;

            foreach (RawMarketData spotRmd in spotData.Rmds)
            {
                DateTime curDateTime = spotRmd.LastUpdatedTime;
                RawMarketData futureRmd = futureData.GetRmdData(curDateTime);

                if (RawMarketDataUtil.IsValidBidAskCurPrice(spotRmd) &&
                    RawMarketDataUtil.IsValidBidAskCurPrice(futureRmd))
                {
                    if (IsOverSpotBidAskSpread(spotRmd))
                    {
                        ret.Add(new DateTimeDoublePair(curDateTime, kMinValue));
                    }
                    else
                    {
                        double spotMidPrice = (spotRmd.AskPrice1 + spotRmd.BidPrice1) / 2;
                        double futureMidPrice = (futureRmd.AskPrice1 + futureRmd.BidPrice1) / 2;

                        double spotPart = (spotAvgPrice - spotMidPrice) / spotDuration;
                        double futurePart = 100 * (futureMidPrice - futureAvgPrice) / futureDuration;

                        double indicator = spotPart + futurePart;

                        ret.Add(new DateTimeDoublePair(curDateTime, indicator));
                    }
                }
                else
                {
                    ret.Add(new DateTimeDoublePair(curDateTime, double.NaN));
                }
            }
            return ret;
        }
Esempio n. 3
0
        public List<EventPoint> GetEventPoints(
            PeriodicMarketDataCollection spot, 
            PeriodicMarketDataCollection future,
            TradingDirection spotDirection)
        {
            List<EventPoint> eventPoints = new List<EventPoint>();

            for (int i = 0; i < spot.Rmds.Count - 1; ++i)
            {
                RawMarketData spotStartRmd = spot.Rmds[i];
                RawMarketData futureStartRmd = future.Rmds[i];

                Trace.Assert(spotStartRmd.LastUpdatedTime == futureStartRmd.LastUpdatedTime);

                if (!RawMarketDataUtil.IsValidBidAskCurPrice(spotStartRmd) ||
                    !RawMarketDataUtil.IsValidBidAskCurPrice(futureStartRmd))
                {
                    EventPoint ep = new EventPoint();
                    UpdateEventPoint(spotStartRmd.Code, futureStartRmd.Code, spotDirection,
                        spotStartRmd.LastUpdatedTime, null, ep);
                    eventPoints.Add(ep);
                }
                else
                {
                    PairTradingData tradingData = new PairTradingData(spotDirection);
                    tradingData.SetEnterPrices(spotStartRmd, futureStartRmd, spotDirection);

                    for (int j = i + 1; j < spot.Rmds.Count; ++j)
                    {
                        RawMarketData spotCurRmd = spot.Rmds[j];
                        RawMarketData futureCurRmd = future.Rmds[j];

                        if (!RawMarketDataUtil.IsValidBidAskCurPrice(spotCurRmd) ||
                            !RawMarketDataUtil.IsValidBidAskCurPrice(futureCurRmd))
                        {
                            continue;
                        }
                        tradingData.UpdateExitNowPnL(spotCurRmd, futureCurRmd, spotDirection);
                    }
                    EventPoint ep = new EventPoint();
                    UpdateEventPoint(spotStartRmd.Code, futureStartRmd.Code, spotDirection,
                        spotStartRmd.LastUpdatedTime, tradingData, ep);
                    eventPoints.Add(ep);
                }
            }
            return eventPoints;
        }
Esempio n. 4
0
        public List<DateTimeDoublePair> GetIndicators(DateTime targetDate)
        {
            // Load daydata_ktb_avg
            DayDataKtbAvg spotYesAvg =
                DayDataKtbAvgCollection.Ins().GetData(SPOT_10YR, DateUtil.GetYesterDay(targetDate));
            DayDataKtbAvg futureYesAvg =
                DayDataKtbAvgCollection.Ins().GetData(FUTURE_10YR, DateUtil.GetYesterDay(targetDate));

            // Load PeriodicData
            String spotOrigin = MarketDataConverter.GetSpotOrigin(targetDate.ToString("yyyy_MM_dd"));
            String spotDest = BASE_FOLDER + MarketDataConverter.GetDest(SPOT_10YR, spotOrigin);
            String futureOrigin = MarketDataConverter.GetFutureOrigin(targetDate.ToString("yyyy_MM_dd"));
            String futureDest = BASE_FOLDER + MarketDataConverter.GetDest(FUTURE_10YR, futureOrigin);

            PeriodicMarketDataCollection spotData = new PeriodicMarketDataCollection(spotDest);
            PeriodicMarketDataCollection futureData = new PeriodicMarketDataCollection(futureDest);

            // Calculate Indicator
            return GetIndicators_Raw(targetDate, spotYesAvg, spotData, futureYesAvg, futureData);
        }