예제 #1
0
	public MarketInfo(MarketInfo marketInfo)
	{
		this.productId = marketInfo.productId;
		this.useIos = marketInfo.useIos;
		this.iosId = marketInfo.iosId;
		this.useAndroid = marketInfo.useAndroid;
		this.androidId = marketInfo.androidId;
		this.price = marketInfo.price;
	}
예제 #2
0
	public ZFGood()
	{
		this.ID = "item_";
		this.marketInfo = new MarketInfo();
		this.virtualInfo = new VirtualInfo();
	}
예제 #3
0
 public int AddMarket(MarketInfo model)
 {
     return(_marketBll.AddMarket(model));
 }
예제 #4
0
        public static List <string> GetMarketData(string mainMarket, Dictionary <string, MarketInfo> marketInfos, PTMagicConfiguration systemConfiguration, LogHelper log)
        {
            List <string> result = new List <string>();

            string lastMarket = "";

            Newtonsoft.Json.Linq.JObject lastTicker = null;
            try {
                string baseUrl = "https://bittrex.com/api/v2.0/pub/markets/GetMarketSummaries";

                log.DoLogInfo("Bittrex - Getting market data...");
                Dictionary <string, dynamic> jsonObject = GetJsonFromURL(baseUrl, log, "");
                if (jsonObject.Count > 0)
                {
                    if (jsonObject["success"])
                    {
                        log.DoLogInfo("Bittrex - Market data received for " + jsonObject["result"].Count.ToString() + " currencies");

                        double mainCurrencyPrice = 1;
                        if (!mainMarket.Equals("USDT", StringComparison.InvariantCultureIgnoreCase))
                        {
                            mainCurrencyPrice = Bittrex.GetMainCurrencyPrice(mainMarket, systemConfiguration, log);
                        }

                        if (mainCurrencyPrice > 0)
                        {
                            Dictionary <string, Market> markets = new Dictionary <string, Market>();
                            foreach (Newtonsoft.Json.Linq.JObject currencyTicker in jsonObject["result"])
                            {
                                string marketName = currencyTicker["Summary"]["MarketName"].ToString();
                                if (marketName.StartsWith(mainMarket, StringComparison.InvariantCultureIgnoreCase))
                                {
                                    // Set last values in case any error occurs
                                    lastMarket = marketName;
                                    lastTicker = currencyTicker;

                                    Market market = new Market();
                                    market.Position = markets.Count + 1;
                                    market.Name     = marketName;
                                    market.Symbol   = currencyTicker["Summary"]["MarketName"].ToString();
                                    if (currencyTicker["Summary"]["Last"].Type == Newtonsoft.Json.Linq.JTokenType.Float)
                                    {
                                        market.Price = (double)currencyTicker["Summary"]["Last"];
                                    }
                                    if (currencyTicker["Summary"]["BaseVolume"].Type == Newtonsoft.Json.Linq.JTokenType.Float)
                                    {
                                        market.Volume24h = (double)currencyTicker["Summary"]["BaseVolume"];
                                    }
                                    market.MainCurrencyPriceUSD = mainCurrencyPrice;

                                    markets.Add(market.Name, market);

                                    result.Add(market.Name);

                                    // Save market info
                                    MarketInfo marketInfo = null;
                                    if (marketInfos.ContainsKey(marketName))
                                    {
                                        marketInfo = marketInfos[marketName];
                                    }

                                    if (marketInfo == null)
                                    {
                                        marketInfo      = new MarketInfo();
                                        marketInfo.Name = marketName;
                                        marketInfos.Add(marketName, marketInfo);
                                    }
                                    if (currencyTicker["Summary"]["Created"].Type == Newtonsoft.Json.Linq.JTokenType.Date)
                                    {
                                        marketInfo.FirstSeen = (DateTime)currencyTicker["Summary"]["Created"];
                                    }
                                    marketInfo.LastSeen = DateTime.Now.ToUniversalTime();
                                }
                            }

                            BaseAnalyzer.SaveMarketInfosToFile(marketInfos, systemConfiguration, log);

                            Bittrex.CheckForMarketDataRecreation(mainMarket, markets, systemConfiguration, log);

                            DateTime fileDateTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, 0).ToUniversalTime();

                            FileHelper.WriteTextToFile(Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + Constants.PTMagicPathData + Path.DirectorySeparatorChar + Constants.PTMagicPathExchange + Path.DirectorySeparatorChar, "MarketData_" + fileDateTime.ToString("yyyy-MM-dd_HH.mm") + ".json", JsonConvert.SerializeObject(markets), fileDateTime, fileDateTime);

                            log.DoLogInfo("Bittrex - Market data saved for " + markets.Count.ToString() + " markets with " + mainMarket + ".");

                            FileHelper.CleanupFiles(Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + Constants.PTMagicPathData + Path.DirectorySeparatorChar + Constants.PTMagicPathExchange + Path.DirectorySeparatorChar, systemConfiguration.AnalyzerSettings.MarketAnalyzer.StoreDataMaxHours);
                            log.DoLogInfo("Bittrex - Market data cleaned.");
                        }
                        else
                        {
                            log.DoLogError("Bittrex - Failed to get main market price for " + mainMarket + ".");
                            result = null;
                        }
                    }
                }
            } catch (Exception ex) {
                log.DoLogCritical("Exception while getting data for '" + lastMarket + "': " + ex.Message, ex);
                result = null;
            }

            return(result);
        }
예제 #5
0
        public void MoneynessDeltaTest()
        {
            var startDate    = new Date(2018, 03, 02);
            var maturityDate = new Date(2018, 04, 27);

            var call = new VanillaOption(startDate,
                                         maturityDate,
                                         OptionExercise.American,
                                         OptionType.Call,
                                         1.05,
                                         InstrumentType.Stock,
                                         CalendarImpl.Get("chn"),
                                         new Act365(),
                                         CurrencyCode.CNY,
                                         CurrencyCode.CNY,
                                         new[] { maturityDate },
                                         new[] { maturityDate },
                                         12,
                                         null,
                                         null,
                                         0,
                                         true,
                                         8000);

            #region construct market
            var historiclIndexRates = HistoricalDataLoadHelper.HistoricalIndexRates;
            var curveConvention     = new CurveConvention("fr007CurveConvention",
                                                          "CNY",
                                                          "ModifiedFollowing",
                                                          "Chn",
                                                          "Act365",
                                                          "Continuous",
                                                          "CubicHermiteMonotic");

            var fr007CurveName      = "Fr007";
            var fr007RateDefinition = new[]
            {
                new RateMktData("1D", 0.05, "Spot", "None", fr007CurveName),
                new RateMktData("5Y", 0.05, "Spot", "None", fr007CurveName),
            };

            var dividendCurveName      = "Dividend";
            var dividendRateDefinition = new[]
            {
                new RateMktData("1D", 0, "Spot", "None", dividendCurveName),
                new RateMktData("5Y", 0, "Spot", "None", dividendCurveName),
            };

            var curveDefinition = new[]
            {
                new InstrumentCurveDefinition(fr007CurveName, curveConvention, fr007RateDefinition, "SpotCurve"),
                new InstrumentCurveDefinition(dividendCurveName, curveConvention, dividendRateDefinition, "SpotCurve"),
            };

            var       volSurf    = new[] { new VolSurfMktData("VolSurf", 0.3), };
            var       marketInfo = new MarketInfo("tmpMarket", "2018-03-02", curveDefinition, historiclIndexRates, null, null, volSurf);
            QdpMarket qdpMarket;
            MarketFunctions.BuildMarket(marketInfo, out qdpMarket);

            var valuationDate = new Date(2018, 3, 2);

            //flat vol surface

            var surface1 = qdpMarket.GetData <VolSurfMktData>("VolSurf").ToImpliedVolSurface(valuationDate);
            // market with flat vol surface
            var market = new MarketCondition(
                x => x.ValuationDate.Value  = valuationDate,
                x => x.DiscountCurve.Value  = qdpMarket.GetData <CurveData>("Fr007").YieldCurve,
                x => x.DividendCurves.Value = new Dictionary <string, IYieldCurve> {
                { "", qdpMarket.GetData <CurveData>("Dividend").YieldCurve }
            },
                x => x.VolSurfaces.Value = new Dictionary <string, IVolSurface> {
                { "", surface1 }
            },
                x => x.SpotPrices.Value = new Dictionary <string, double> {
                { "", 8000 }
            }
                );

            //a real vol surface, same as stock 600000 of 2018-03-02 in OTC system
            var maturities = new Date[]
            {
                (new Term("1W")).Next(startDate),
                (new Term("2W")).Next(startDate),
                (new Term("1M")).Next(startDate)
            };

            var strikes = new double[]
            {
                0.9,
                0.95,
                1.0,
                1.05,
                1.1
            };

            var vols = new double[3, 5];
            for (var i = 0; i < vols.GetLength(0); ++i)
            {
                for (var j = 0; j < vols.GetLength(1); ++j)
                {
                    vols[i, j] = 0.3;
                }
            }

            vols[2, 2] = 0.4;


            var surface2 = new ImpliedVolSurface(valuationDate, maturities, strikes, vols, Interpolation2D.BiLinear);
            // market with flat vol surface
            var market2 = new MarketCondition(
                x => x.ValuationDate.Value  = valuationDate,
                x => x.DiscountCurve.Value  = qdpMarket.GetData <CurveData>("Fr007").YieldCurve,
                x => x.DividendCurves.Value = new Dictionary <string, IYieldCurve> {
                { "", qdpMarket.GetData <CurveData>("Dividend").YieldCurve }
            },
                x => x.VolSurfaces.Value = new Dictionary <string, IVolSurface> {
                { "", surface2 }
            },
                x => x.SpotPrices.Value = new Dictionary <string, double> {
                { "", 8000 }
            }
                );
            #endregion

            var engine = new AnalyticalVanillaEuropeanOptionEngine();

            //result of a flat vol surface of 0.3, which is the same as pricing result in OTC-926
            var result = engine.Calculate(call, market, PricingRequest.All);

            //result of real vol surface, which is the same as scenario analysis in OTC-926
            var result2 = engine.Calculate(call, market2, PricingRequest.All);
        }
예제 #6
0
파일: CdsTest.cs 프로젝트: stepinto163/Qdp
        public void TestCdsCalibration()
        {
            var historiclIndexRates = HistoricalDataLoadHelper.HistoricalIndexRates;

            const string fr007CurveName       = "Swap_Fr007";
            var          fr007CurveConvention = new CurveConvention(
                "fr007CurveConvention",
                "CNY",
                "None",
                "Chn_ib",
                "Act365",
                "Continuous",
                "CubicHermiteMonotic");
            var rateDefinition = new[]
            {
                new RateMktData("1D", 0.026, "Spot", "None", fr007CurveName),
                new RateMktData("20Y", 0.026, "Spot", "None", fr007CurveName)
            };

            var fr007CurveDefinition = new InstrumentCurveDefinition(fr007CurveName, fr007CurveConvention, rateDefinition, "SpotCurve");
            var curveDefinition      = new[]
            {
                fr007CurveDefinition
            };

            const string spcCurveName       = "spc_testCurve";
            var          spcCurveConvention = new CurveConvention("spcCurveConvention",
                                                                  "CNY",
                                                                  "None",
                                                                  "Chn_ib",
                                                                  "Act365",
                                                                  "Continuous",
                                                                  "CubicHermiteMonotic");
            var cdsSpreads = new[]
            {
                new RateMktData("2015-06-20", 0.001535, "Spc", "CreditDefaultSwap", spcCurveName),
                new RateMktData("2015-12-20", 0.001901, "Spc", "CreditDefaultSwap", spcCurveName),
                new RateMktData("2016-12-20", 0.003131, "Spc", "CreditDefaultSwap", spcCurveName),
                new RateMktData("2017-12-20", 0.004749, "Spc", "CreditDefaultSwap", spcCurveName),
                new RateMktData("2018-12-20", 0.007395, "Spc", "CreditDefaultSwap", spcCurveName),
                new RateMktData("2019-12-20", 0.0096833, "Spc", "CreditDefaultSwap", spcCurveName),
                new RateMktData("2021-12-20", 0.01339, "Spc", "CreditDefaultSwap", spcCurveName),
                new RateMktData("2024-12-20", 0.015116, "Spc", "CreditDefaultSwap", spcCurveName)
            };

            var spcCurveDefinitions = new[]
            {
                new InstrumentCurveDefinition(spcCurveName, spcCurveConvention, cdsSpreads, "SpotCurve", fr007CurveDefinition)
            };

            var marketInfo = new MarketInfo("tmpMarket", "2014-12-16", curveDefinition, historiclIndexRates)
            {
                SpcCurveDefinitions = spcCurveDefinitions
            };
            QdpMarket market;
            var       result = MarketFunctions.BuildMarket(marketInfo, out market);

            var spcCurve  = market.GetData <CurveData>(spcCurveName).YieldCurve;
            var keyPoints = spcCurve.KeyPoints;

            Assert.AreEqual(keyPoints[0].Item2, 1.0);
            Assert.AreEqual(keyPoints[1].Item2, 0.99868359032, 1.0e-9);
            Assert.AreEqual(keyPoints[2].Item2, 0.99680057341, 1.0e-9);
            Assert.AreEqual(keyPoints[3].Item2, 0.98952113745, 1.0e-9);
            Assert.AreEqual(keyPoints[4].Item2, 0.97616083777, 1.0e-9);
            Assert.AreEqual(keyPoints[5].Item2, 0.95048151684, 1.0e-9);
            Assert.AreEqual(keyPoints[6].Item2, 0.91939248365, 1.0e-9);
            Assert.AreEqual(keyPoints[7].Item2, 0.84740619752, 1.0e-9);
            Assert.AreEqual(keyPoints[8].Item2, 0.76457411556, 1.0e-9);

            var cdsInfo = new CreditDefaultSwapInfo()
            {
                StartDate             = "2014-09-22",
                MaturityDate          = "2019-12-20",
                Notional              = 10000000,
                BusinessDayConvention = "ModifiedFollowing",
                Calendar              = "Chn_ib",
                Coupon                 = 0.01,
                Currency               = "CNY",
                DayCount               = "Act365",
                Frequency              = "Quarterly",
                SwapDirection          = "Payer",
                RecoveryRate           = 0.4,
                Stub                   = "ShortEnd",
                NumIntegrationInterval = 100,
                ValuationParameters    = new CdsValuationParameters(fr007CurveName, spcCurveName)
            };
            var cdsVf         = new CreditDefaultSwapVf(cdsInfo);
            var pricingResult = cdsVf.ValueTrade(market, PricingRequest.Pv | PricingRequest.Ai);

            Assert.AreEqual(pricingResult.Pv, -38365.7413, 1e-4);
            Assert.AreEqual(pricingResult.Ai, -23287.6712, 1e-4);
        }
예제 #7
0
 public ZFCurrencyPack()
 {
     this.marketInfo = new MarketInfo();
 }
예제 #8
0
 private double Ro(int time)
 {
     return(MarketInfo.Ro(time));
 }
예제 #9
0
        private IMarketCondition TestMarket(String referenceDate = "2015-03-19",
                                            Double vol           = 0.28, Double volNew = 0.30, Double spot = 1.0, Double spotNew = 2.0, Double rho = 0.5,
                                            string asset1        = null, string asset2 = null)
        {
            var historiclIndexRates = HistoricalDataLoadHelper.HistoricalIndexRates;

            var curveConvention = new CurveConvention("fr007CurveConvention",
                                                      "CNY",
                                                      "ModifiedFollowing",
                                                      "Chn",
                                                      "Act365",
                                                      "Continuous",
                                                      "CubicHermiteMonotic");

            var fr007CurveName      = "Fr007";
            var fr007RateDefinition = new[]
            {
                new RateMktData("1D", 0.035, "Spot", "None", fr007CurveName),
                new RateMktData("5Y", 0.035, "Spot", "None", fr007CurveName),
            };

            var dividendCurveName      = "Dividend";
            var dividendRateDefinition = new[]
            {
                new RateMktData("1D", 0.0, "Spot", "None", dividendCurveName),
                new RateMktData("5Y", 0.0, "Spot", "None", dividendCurveName),
            };

            var curveDefinition = new[]
            {
                new InstrumentCurveDefinition(fr007CurveName, curveConvention, fr007RateDefinition, "SpotCurve"),
                new InstrumentCurveDefinition(dividendCurveName, curveConvention, dividendRateDefinition, "SpotCurve"),
            };

            var volSurf = new[] { new VolSurfMktData("VolSurf", vol), new VolSurfMktData("VolSurfNew", volNew), };
            var corr    = new[] { new CorrSurfMktData("Correlation", rho), };


            var       marketInfo = new MarketInfo("tmpMarket", referenceDate, curveDefinition, historiclIndexRates, null, null, volSurf, corr);
            QdpMarket market;

            MarketFunctions.BuildMarket(marketInfo, out market);

            var impliedVol  = market.GetData <VolSurfMktData>("VolSurf").ToImpliedVolSurface(market.ReferenceDate);
            var impliedVol2 = market.GetData <VolSurfMktData>("VolSurfNew").ToImpliedVolSurface(market.ReferenceDate);
            var corre       = market.GetData <CorrSurfMktData>("Correlation").ToImpliedVolSurface(market.ReferenceDate);

            return(new MarketCondition(
                       x => x.ValuationDate.Value = market.ReferenceDate,
                       x => x.DiscountCurve.Value = market.GetData <CurveData>("Fr007").YieldCurve,
                       x => x.DividendCurves.Value = new Dictionary <string, IYieldCurve> {
                { asset1, market.GetData <CurveData>("Dividend").YieldCurve }, { asset2, market.GetData <CurveData>("Dividend").YieldCurve }
            },
                       x => x.VolSurfaces.Value = new Dictionary <string, IVolSurface> {
                { asset1, impliedVol }, { asset2, impliedVol2 }
            },
                       x => x.SpotPrices.Value = new Dictionary <string, double> {
                { asset1, spot }, { asset2, spotNew }
            },
                       x => x.Correlations.Value = new Dictionary <string, IVolSurface> {
                { asset1, corre }
            }
                       ));
        }
예제 #10
0
 public GenericResponse(bool wasSuccess, MarketInfo info) : this(wasSuccess, info, -1)
 {
 }
예제 #11
0
 public GenericResponse(bool wasSuccess, MarketInfo info, int rCode)
 {
     _success    = wasSuccess;
     _marketInfo = info;
     _code       = rCode;
 }
예제 #12
0
        protected RootParsingObject CreateJson(MarketInfo market_info)
        {
            //var market_info = new MarketInfo();
            var root     = new RootParsingObject();
            var listings = new List <Listing>();

            //market_info.ftpFolder = AfewStoreParser.NAME;
            //market_info.website = AfewStoreParser.SITEURL;
            //market_info.currency = AfewStoreParser.CURRENCY;
            //market_info.start_parse_date = DateTime.Now;
            //market_info.end_parse_date = DateTime.Now;
            //market_info.delivery_to_usa = AfewStoreParser.DELIVERY_TO_USA;
            //market_info.photo_parameters.is_watermark_image = false;
            //market_info.photo_parameters.background_color = "white";
            //market_info.currently_language = "en";

            int i = 0;

            foreach (var sneaker in catalog.sneakers)
            {
                var listing = new Listing();

                //id murmurhash
                Encoding encoding = new UTF8Encoding();
                if (sneaker.link != null)
                {
                    byte[] input = encoding.GetBytes(sneaker.link);
                    using (MemoryStream stream = new MemoryStream(input))
                    {
                        listing.id = MurMurHash3.Hash(stream);
                        if (listing.id < 0)
                        {
                            listing.id = listing.id * -1;
                        }
                    }
                }
                else
                {
                    byte[] input = encoding.GetBytes(sneaker.title);
                    using (MemoryStream stream = new MemoryStream(input))
                    {
                        listing.id = MurMurHash3.Hash(stream);
                        if (listing.id < 0)
                        {
                            listing.id = listing.id * -1;
                        }
                    }
                }


                listing.url        = sneaker.link;
                listing.sku        = sneaker.sku;
                listing.title      = sneaker.title;
                listing.brand      = sneaker.brand;
                listing.colorbrand = sneaker.color;
                listing.category   = Helper.ConvertCategoryRusToEng(sneaker.category);
                //if (String.IsNullOrWhiteSpace(listing.category)) Program.Logger.Warn("Wrong category: " + sneaker.category + " sku: " +sneaker.sku);
                listing.sex       = Helper.ConvertSexRusToEng(sneaker.sex);
                listing.price     = sneaker.price;
                listing.old_price = sneaker.oldPrice;
                listing.images    = sneaker.images;
                listing.sizes     = Helper.GetSizeListUs(sneaker.sizes);
                i++;
                listing.position = i;

                listings.Add(listing);
            }

            root.market_info = market_info;
            root.listings    = listings;

            return(root);
            //throw new NotImplementedException();
        }
예제 #13
0
 public StockListStruct(MarketInfo.MarketType market_code, ushort record_offset, ushort record_count)
 {
     header = new ReqHead((ushort)0x0524, (ushort)20); // 20  = size of StockListStruct
     block =MarketInfo.get_block_from_market_type(market_code);
     unknown1 = 0;
     unknown2 = 0;
     offset = record_offset;
     count = record_count;
 }
예제 #14
0
 public StockListReq(MarketInfo.MarketType market_code)
     : this(market_code, 0, 200, 0)
 {
 }
예제 #15
0
 public StockListReq(MarketInfo.MarketType market_code, ushort record_offset, ushort record_count, ushort record_total)
 {
 }
예제 #16
0
        private IMarketCondition TestMarket_generic(string referenceDate,
                                                    double flatRiskFreeRate, double flatCreditRate,
                                                    double vol, double spotPrice, double cbDirtyPrice)
        {
            var compoundConvention = "Annual";   //quite close for most bonds
            //var compoundConvention = "Quarterly"; //fails
            //var compoundConvention = "BiMonthly"; //fails
            //var compoundConvention = "SubTriple"; //too big, 96.15
            //var compoundConvention = "SemiAnnual"; //too big  96.1506

            //var compoundConvention = "Continuous"; //bad, too small
            var curveTrait = "SpotCurve";
            var rateTrait  = "Spot";

            var curveConvention = new CurveConvention("curveConvention",
                                                      "CNY",
                                                      "ModifiedFollowing",
                                                      "Chn_ib",
                                                      "Act365",
                                                      compoundConvention,
                                                      "Linear");
            var curveDefinitions = new List <InstrumentCurveDefinition>();
            // 1 - discount curve
            var rfCurveName = "Fr007";
            var rates       = new[]
            {
                new RateMktData("1D", flatRiskFreeRate, rateTrait, "None", rfCurveName),
                new RateMktData("2Y", flatRiskFreeRate, rateTrait, "None", rfCurveName),
                new RateMktData("3Y", flatRiskFreeRate, rateTrait, "None", rfCurveName),
                new RateMktData("15Y", flatRiskFreeRate, rateTrait, "None", rfCurveName),
            };

            var fr007Curve = new InstrumentCurveDefinition(
                rfCurveName,
                curveConvention,
                rates,
                curveTrait);

            curveDefinitions.Add(fr007Curve);

            var creditCurveName = "bondCreditCurve";
            var rates2          = new[]
            {
                new RateMktData("1D", flatCreditRate, rateTrait, "None", creditCurveName),
                new RateMktData("2Y", flatCreditRate, rateTrait, "None", creditCurveName),
                new RateMktData("3Y", flatCreditRate, rateTrait, "None", creditCurveName),
                new RateMktData("15Y", flatCreditRate, rateTrait, "None", creditCurveName),
            };
            var bondCreditCurve = new InstrumentCurveDefinition(
                creditCurveName,
                curveConvention,
                rates2,
                curveTrait);

            curveDefinitions.Add(bondCreditCurve);

            //assuming zero, almost useless for China
            var dCurveName = "dividendCurve";
            var rates3     = new[]
            {
                new RateMktData("1D", 0, rateTrait, "None", dCurveName),
                new RateMktData("15Y", 0, rateTrait, "None", dCurveName),
            };
            var dividendCurve = new InstrumentCurveDefinition(
                dCurveName,
                curveConvention,
                rates3,
                curveTrait);

            curveDefinitions.Add(dividendCurve);

            var volName = "VolSurf";
            var volSurf = new[] { new VolSurfMktData(volName, vol), };

            var marketInfo = new MarketInfo("TestMarket")
            {
                ReferenceDate         = referenceDate,
                YieldCurveDefinitions = curveDefinitions.ToArray(),
                VolSurfMktDatas       = volSurf,
                HistoricalIndexRates  = HistoricalDataLoadHelper.HistoricalIndexRates
            };

            MarketFunctions.BuildMarket(marketInfo, out QdpMarket market);
            var volsurf = market.GetData <VolSurfMktData>(volName).ToImpliedVolSurface(market.ReferenceDate);

            return(new MarketCondition(x => x.ValuationDate.Value = market.ReferenceDate,
                                       x => x.DiscountCurve.Value = market.GetData <CurveData>(creditCurveName).YieldCurve,
                                       x => x.FixingCurve.Value = market.GetData <CurveData>(creditCurveName).YieldCurve,
                                       x => x.RiskfreeCurve.Value = market.GetData <CurveData>(rfCurveName).YieldCurve,
                                       x => x.DividendCurves.Value = new Dictionary <string, IYieldCurve> {
                { "", market.GetData <CurveData>(dCurveName).YieldCurve }
            },
                                       x => x.VolSurfaces.Value = new Dictionary <string, IVolSurface> {
                { "", volsurf }
            },
                                       x => x.SpotPrices.Value = new Dictionary <string, double> {
                { "", spotPrice }
            },
                                       x => x.MktQuote.Value = new Dictionary <string, Tuple <PriceQuoteType, double> > {
                { "010002", Tuple.Create(PriceQuoteType.Dirty, cbDirtyPrice) }
            },
                                       x => x.HistoricalIndexRates.Value = new Dictionary <IndexType, SortedDictionary <Date, double> >()
                                       ));
        }
예제 #17
0
	public ZFCurrencyPack(ZFCurrencyPack currencyPack)
	{
		this.ID = currencyPack.ID;
		this.name = currencyPack.name;
		this.description = currencyPack.description;
		this.currency_itemId = currencyPack.currency_itemId;
		this.currency_amount = currencyPack.currency_amount;
		this.marketInfo = new MarketInfo(currencyPack.marketInfo);
	}
예제 #18
0
        private IMarketCondition TestMarket()
        {
            var referenceDate   = "2017-10-18";
            var curveConvention = new CurveConvention("curveConvention",
                                                      "CNY",
                                                      "ModifiedFollowing",
                                                      "Chn_ib",
                                                      "Act365",
                                                      "Continuous",
                                                      "Linear");
            var curveDefinitions = new List <InstrumentCurveDefinition>();
            // 1 - discount curve
            var rates = new[]
            {
                new RateMktData("1D", 0.015, "Spot", "None", "Fr007"),
                new RateMktData("15Y", 0.015, "Spot", "None", "Fr007"),
            };

            var fr007Curve = new InstrumentCurveDefinition(
                "Fr007",
                curveConvention,
                rates,
                "SpotCurve");

            curveDefinitions.Add(fr007Curve);

            var rates2 = new[]
            {
                new RateMktData("1D", 0.015, "Spot", "None", "bondCreditCurve"),
                new RateMktData("15Y", 0.015, "Spot", "None", "bondCreditCurve"),
            };
            var bondCreditCurve = new InstrumentCurveDefinition(
                "bondCreditCurve",
                curveConvention,
                rates2,
                "SpotCurve");

            curveDefinitions.Add(bondCreditCurve);

            var rates3 = new[]
            {
                new RateMktData("1D", 0, "Spot", "None", "dividendCurve"),
                new RateMktData("15Y", 0, "Spot", "None", "dividendCurve"),
            };
            var dividendCurve = new InstrumentCurveDefinition(
                "dividendCurve",
                curveConvention,
                rates3,
                "SpotCurve");

            curveDefinitions.Add(dividendCurve);

            var volSurf = new[] { new VolSurfMktData("VolSurf", 0.255669), };

            var marketInfo = new MarketInfo("TestMarket")
            {
                ReferenceDate         = referenceDate,
                YieldCurveDefinitions = curveDefinitions.ToArray(),
                VolSurfMktDatas       = volSurf,
                HistoricalIndexRates  = HistoricalDataLoadHelper.HistoricalIndexRates
            };

            MarketFunctions.BuildMarket(marketInfo, out QdpMarket market);
            var volsurf = market.GetData <VolSurfMktData>("VolSurf").ToImpliedVolSurface(market.ReferenceDate);

            return(new MarketCondition(x => x.ValuationDate.Value = market.ReferenceDate,
                                       x => x.DiscountCurve.Value = market.GetData <CurveData>("bondCreditCurve").YieldCurve,
                                       x => x.FixingCurve.Value = market.GetData <CurveData>("bondCreditCurve").YieldCurve,
                                       x => x.RiskfreeCurve.Value = market.GetData <CurveData>("Fr007").YieldCurve,
                                       x => x.DividendCurves.Value = new Dictionary <string, IYieldCurve> {
                { "", market.GetData <CurveData>("dividendCurve").YieldCurve }
            },
                                       x => x.VolSurfaces.Value = new Dictionary <string, IVolSurface> {
                { "", volsurf }
            },
                                       x => x.SpotPrices.Value = new Dictionary <string, double> {
                { "", 6.21 }
            },
                                       x => x.MktQuote.Value = new Dictionary <string, Tuple <PriceQuoteType, double> > {
                { "010002", Tuple.Create(PriceQuoteType.Dirty, 140.65) }
            },
                                       x => x.HistoricalIndexRates.Value = new Dictionary <IndexType, SortedDictionary <Date, double> >()
                                       ));
        }
예제 #19
0
 public ZFGood()
 {
     this.ID          = "item_";
     this.marketInfo  = new MarketInfo();
     this.virtualInfo = new VirtualInfo();
 }
예제 #20
0
        private IMarketCondition TestMarket2()
        {
            var referenceDate    = "2017-10-20";
            var curveConvention1 = new CurveConvention("discountCurveConvention",
                                                       "CNY",
                                                       "None",
                                                       "Chn_ib",
                                                       "Act360",
                                                       "Continuous",
                                                       "Linear");
            var curveDefinitions = new List <InstrumentCurveDefinition>();
            // 1 - discount curve
            var rates = new[]
            {
                new RateMktData("0Y", 0.041004, "Spot", "None", "DiscountCurve"),
                new RateMktData("1M", 0.045247, "Spot", "None", "DiscountCurve"),
                new RateMktData("3M", 0.049065, "Spot", "None", "DiscountCurve"),
                new RateMktData("6M", 0.048518, "Spot", "None", "DiscountCurve"),
                new RateMktData("9M", 0.049887, "Spot", "None", "DiscountCurve"),
                new RateMktData("1Y", 0.050482, "Spot", "None", "DiscountCurve"),
                new RateMktData("2Y", 0.050935, "Spot", "None", "DiscountCurve"),
                new RateMktData("3Y", 0.05185, "Spot", "None", "DiscountCurve"),
                new RateMktData("4Y", 0.052519, "Spot", "None", "DiscountCurve"),
                new RateMktData("5Y", 0.053361, "Spot", "None", "DiscountCurve"),
                new RateMktData("6Y", 0.055701, "Spot", "None", "DiscountCurve"),
                new RateMktData("7Y", 0.055637, "Spot", "None", "DiscountCurve"),
                new RateMktData("8Y", 0.055674, "Spot", "None", "DiscountCurve"),
                new RateMktData("9Y", 0.056529, "Spot", "None", "DiscountCurve"),
                new RateMktData("10Y", 0.056457, "Spot", "None", "DiscountCurve"),
                new RateMktData("15Y", 0.05672, "Spot", "None", "DiscountCurve"),
                new RateMktData("20Y", 0.058323, "Spot", "None", "DiscountCurve"),
                new RateMktData("30Y", 0.058335, "Spot", "None", "DiscountCurve")
            };


            var discountCurve = new InstrumentCurveDefinition(
                "DiscountCurve",
                curveConvention1,
                rates,
                "SpotCurve");

            curveDefinitions.Add(discountCurve);

            var curveConvention2 = new CurveConvention("riskFreeCurveConvention",
                                                       "CNY",
                                                       "ModifiedFollowing",
                                                       "Chn_ib",
                                                       "Act365",
                                                       "Continuous",
                                                       "CubicHermiteMonotic");
            var rates2 = new[]
            {
                new RateMktData("1D", 0.0283, "Spot", "None", "Fr007SwapCurve"),
                new RateMktData("7D", 0.0344, "Spot", "None", "Fr007SwapCurve"),
                new RateMktData("3M", 0.0349, "Spot", "None", "Fr007SwapCurve"),
                new RateMktData("6M", 0.035411, "Spot", "None", "Fr007SwapCurve"),
                new RateMktData("9M", 0.035567, "Spot", "None", "Fr007SwapCurve"),
                new RateMktData("1Y", 0.035503, "Spot", "None", "Fr007SwapCurve"),
                new RateMktData("2Y", 0.036372, "Spot", "None", "Fr007SwapCurve"),
                new RateMktData("3Y", 0.037521, "Spot", "None", "Fr007SwapCurve"),
                new RateMktData("4Y", 0.037916, "Spot", "None", "Fr007SwapCurve"),
                new RateMktData("5Y", 0.038606, "Spot", "None", "Fr007SwapCurve"),
                new RateMktData("7Y", 0.039, "Spot", "None", "Fr007SwapCurve"),
                new RateMktData("10Y", 0.0397, "Spot", "None", "Fr007SwapCurve")
            };
            var riskFreeCurve = new InstrumentCurveDefinition(
                "Fr007SwapCurve",
                curveConvention2,
                rates2,
                "SpotCurve");

            curveDefinitions.Add(riskFreeCurve);

            var rates3 = new[]
            {
                new RateMktData("1D", 0, "Spot", "None", "DividendCurve"),
                new RateMktData("50Y", 0, "Spot", "None", "DividendCurve"),
            };

            var curveConvention3 = new CurveConvention("dividendCurveConvention",
                                                       "CNY",
                                                       "ModifiedFollowing",
                                                       "Chn_ib",
                                                       "Act365",
                                                       "Continuous",
                                                       "Linear");
            var dividendCurve = new InstrumentCurveDefinition(
                "DividendCurve",
                curveConvention3,
                rates3,
                "SpotCurve");

            curveDefinitions.Add(dividendCurve);

            var volSurf = new[] { new VolSurfMktData("VolSurf", 0.5885), };

            var marketInfo = new MarketInfo("TestMarket")
            {
                ReferenceDate         = referenceDate,
                YieldCurveDefinitions = curveDefinitions.ToArray(),
                VolSurfMktDatas       = volSurf,
                HistoricalIndexRates  = HistoricalDataLoadHelper.HistoricalIndexRates
            };

            MarketFunctions.BuildMarket(marketInfo, out QdpMarket market);
            var volsurf = market.GetData <VolSurfMktData>("VolSurf").ToImpliedVolSurface(market.ReferenceDate);

            return(new MarketCondition(x => x.ValuationDate.Value = market.ReferenceDate,
                                       x => x.DiscountCurve.Value = market.GetData <CurveData>("DiscountCurve").YieldCurve,
                                       x => x.FixingCurve.Value = market.GetData <CurveData>("DiscountCurve").YieldCurve,
                                       x => x.DividendCurves.Value = new Dictionary <string, IYieldCurve> {
                { "", market.GetData <CurveData>("DividendCurve").YieldCurve }
            },
                                       x => x.RiskfreeCurve.Value = market.GetData <CurveData>("Fr007SwapCurve").YieldCurve,
                                       x => x.VolSurfaces.Value = new Dictionary <string, IVolSurface> {
                { "", volsurf }
            },
                                       x => x.SpotPrices.Value = new Dictionary <string, double> {
                { "", 7 }
            },
                                       x => x.MktQuote.Value = new Dictionary <string, Tuple <PriceQuoteType, double> > {
                { "110030.SH", Tuple.Create(PriceQuoteType.Dirty, 110.8192) }
            },
                                       x => x.HistoricalIndexRates.Value = new Dictionary <IndexType, SortedDictionary <Date, double> >()
                                       ));
        }
예제 #21
0
        public QdpMarket VerifyCurveConstructionMarket(string referenceDate)
        {
            var curveConvention = new CurveConvention("curveConvention",
                                                      "CNY",
                                                      "ModifiedFollowing",
                                                      "Chn_ib",
                                                      "Act365",
                                                      "Continuous",
                                                      "ForwardFlat");
            var curveDefinitions = new List <InstrumentCurveDefinition>();
            var name             = "Fr007ForwardFlat";
            // 1 - discount curve
            var rates = new[]
            {
                new RateMktData("1D", 0.0189, "Fr001", "Deposit", name),
                new RateMktData("7D", 0.024, "Fr001", "Deposit", name),
                new RateMktData("3M", 0.0239, "Fr007", "InterestRateSwap", name),
                new RateMktData("6M", 0.02385, "Fr007", "InterestRateSwap", name),
                new RateMktData("9M", 0.02385, "Fr007", "InterestRateSwap", name),
                new RateMktData("1Y", 0.0239, "Fr007", "InterestRateSwap", name),
                new RateMktData("2Y", 0.02405, "Fr007", "InterestRateSwap", name),
                new RateMktData("3Y", 0.02495, "Fr007", "InterestRateSwap", name),
                new RateMktData("4Y", 0.0259, "Fr007", "InterestRateSwap", name),
                new RateMktData("5Y", 0.0267, "Fr007", "InterestRateSwap", name),
                new RateMktData("7Y", 0.0283, "Fr007", "InterestRateSwap", name),
                new RateMktData("10Y", 0.0297, "Fr007", "InterestRateSwap", name),
                new RateMktData("15Y", 0.032, "Fr007", "InterestRateSwap", name)
            };

            var fr007Curve = new InstrumentCurveDefinition(
                name,
                curveConvention,
                rates,
                "ForwardCurve");

            curveDefinitions.Add(fr007Curve);

            var curveConvention2 = new CurveConvention("curveConventionCubic",
                                                       "CNY",
                                                       "ModifiedFollowing",
                                                       "Chn_ib",
                                                       "Act365",
                                                       "Continuous",
                                                       "CubicHermiteMonotic");

            var name2 = "Fr007Cubic";
            // 1 - discount curve
            var rates2 = new[]
            {
                new RateMktData("1D", 0.0189, "Fr001", "Deposit", name),
                new RateMktData("7D", 0.024, "Fr001", "Deposit", name),
                new RateMktData("3M", 0.0239, "Fr007", "InterestRateSwap", name),
                new RateMktData("6M", 0.02385, "Fr007", "InterestRateSwap", name),
                new RateMktData("9M", 0.02385, "Fr007", "InterestRateSwap", name),
                new RateMktData("1Y", 0.0239, "Fr007", "InterestRateSwap", name),
                new RateMktData("2Y", 0.02405, "Fr007", "InterestRateSwap", name),
                new RateMktData("3Y", 0.02495, "Fr007", "InterestRateSwap", name),
                new RateMktData("4Y", 0.0259, "Fr007", "InterestRateSwap", name),
                new RateMktData("5Y", 0.0267, "Fr007", "InterestRateSwap", name),
                new RateMktData("7Y", 0.0283, "Fr007", "InterestRateSwap", name),
                new RateMktData("10Y", 0.0297, "Fr007", "InterestRateSwap", name),
                new RateMktData("15Y", 0.032, "Fr007", "InterestRateSwap", name)
            };

            var fr007Curve2 = new InstrumentCurveDefinition(
                name2,
                curveConvention2,
                rates2,
                "SpotCurve");

            curveDefinitions.Add(fr007Curve2);

            var marketInfo = new MarketInfo("TestMarket")
            {
                ReferenceDate         = referenceDate,
                YieldCurveDefinitions = curveDefinitions.ToArray(),
                HistoricalIndexRates  = HistoricalDataLoadHelper.HistoricalIndexRates
            };

            QdpMarket market;

            MarketFunctions.BuildMarket(marketInfo, out market);
            return(market);
        }
예제 #22
0
 private BatchTradeMonitor(IHubContext context)
 {
     //向行情模块添加消息列表映射
     MarketInfo.SetStrategyQueue(new KeyValuePair <String, Queue>(BatchStrategy, queue_batchtrade_market.GetQueue()));
     _context = context;
 }
예제 #23
0
파일: MarketTcpIp.cs 프로젝트: ssh352/ctp-1
        /// <summary>
        /// 接受行情
        /// </summary>
        /// <param name="obj"></param>
        public override void doOneReceivedData(string str)
        {
            try
            {
                if (!string.IsNullOrEmpty(str))
                {
                    NetInfo ni = new NetInfo();
                    ni.MyReadString(str);
                    if (!string.IsNullOrEmpty(ni.infoT) && ni.code == CommandCode.MARKET01)
                    {
                        if (mainWindow != null)
                        {
                            //将行情收到阻塞线程里面
                            MarketInfo data = new MarketInfo();
                            data.MyReadString(ni.infoT);

                            //if (mainWindow.DaFutures.Equals(mainWindow.marketType))
                            //{
                            //    if ("2".Equals(data.type))
                            //    {
                            //        //if (data.code == "CL1609")
                            //        //{
                            //        //}
                            //        if ("0".Equals(data.currPrice) || "0".Equals(data.currNumber))
                            //        {
                            //            return;
                            //        }
                            //        mainWindow.AddMarketBlock(data);
                            //    }
                            //}
                            //else
                            //{
                            //    if ("0".Equals(data.currPrice) || "0".Equals(data.currNumber))
                            //    {
                            //        return;
                            //    }
                            //    mainWindow.AddMarketBlock(data);
                            //}
                            if (mainWindow.marketBlockingCollection.Count > 500)
                            {
                                Console.WriteLine(mainWindow.marketBlockingCollection.Count);
                                //超过500项先扔掉
                                return;
                            }
                            mainWindow.AddMarketBlock(data);
                        }
                    }
                    else if ((!string.IsNullOrEmpty(ni.infoT) && ni.code == CommandCode.GetSettlePrice))
                    {
                        string   temp = ni.infoT;
                        string[] arr  = temp.Split('^');
                        for (int i = 0; i < arr.Count(); i++)
                        {
                            string     t     = arr[i];
                            string[]   value = t.Split('@');
                            MarketInfo data  = new MarketInfo();
                            data.code     = value[0];
                            data.oldClose = value[1];
                            mainWindow.AddMarketBlock(data);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                mainWindow.marketErrorLoger.log(LogLevel.SYSTEMERROR, str + Environment.NewLine + ex.ToString());
            }
        }
예제 #24
0
        public int AddMarket(MarketInfo model)
        {
            var server = this.CreateService <MarketInfo>();

            return(server.Add(model));
        }
예제 #25
0
 public DateTimeZoneCalculator(string symbolCode)
 {
     this.SymbolCode = symbolCode;
     TimeZone        = MarketInfo.GetTimeZone(symbolCode);
 }
예제 #26
0
        public int UptMarket(MarketInfo model, string[] propertyNames)
        {
            var server = this.CreateService <MarketInfo>();

            return(server.Update(model, propertyNames));
        }
예제 #27
0
 public MarketEvent(DateTime timestamp, long marketId, string station, string system, MarketInfo info) : base(timestamp, NAME)
 {
     this.marketId = marketId;
     this.station  = station;
     this.system   = system;
     this.info     = info;
 }
예제 #28
0
        public QdpMarket VerifyCurveConstructionMarket(string referenceDate)
        {
            var curveConvention = new CurveConvention("curveConvention",
                                                      "CNY",
                                                      "ModifiedFollowing",
                                                      "Chn_ib",
                                                      "Act365",
                                                      "Continuous",
                                                      "CubicHermiteMonotic");
            var curveDefinitions = new List <InstrumentCurveDefinition>();
            // 1 - discount curve
            var rates = new[]
            {
                //new RateMktData("1D", 0.0189, "Spot", "None","Fr007"),
                //new RateMktData("7D", 0.024, "Spot", "None","Fr007"),
                new RateMktData("1D", 0.0189, "Fr001", "Deposit", "Fr007"),
                new RateMktData("7D", 0.024, "Fr001", "Deposit", "Fr007"),
                new RateMktData("3M", 0.0239, "Fr007", "InterestRateSwap", "Fr007"),
                new RateMktData("6M", 0.02385, "Fr007", "InterestRateSwap", "Fr007"),
                new RateMktData("9M", 0.02385, "Fr007", "InterestRateSwap", "Fr007"),
                new RateMktData("1Y", 0.0239, "Fr007", "InterestRateSwap", "Fr007"),
                new RateMktData("2Y", 0.02405, "Fr007", "InterestRateSwap", "Fr007"),
                new RateMktData("3Y", 0.02495, "Fr007", "InterestRateSwap", "Fr007"),
                new RateMktData("4Y", 0.0259, "Fr007", "InterestRateSwap", "Fr007"),
                new RateMktData("5Y", 0.0267, "Fr007", "InterestRateSwap", "Fr007"),
                new RateMktData("7Y", 0.0283, "Fr007", "InterestRateSwap", "Fr007"),
                new RateMktData("10Y", 0.0297, "Fr007", "InterestRateSwap", "Fr007"),
                new RateMktData("15Y", 0.032, "Fr007", "InterestRateSwap", "Fr007")
            };

            var fr007Curve = new InstrumentCurveDefinition(
                "Fr007",
                curveConvention,
                rates,
                "SpotCurve");

            curveDefinitions.Add(fr007Curve);

            var shibor3Mrates = new[]
            {
                new RateMktData("1D", 0.01909, "Shibor1D", "Deposit", "Shibor3M"),
                new RateMktData("7D", 0.02401, "Shibor1W", "Deposit", "Shibor3M"),
                new RateMktData("3M", 0.03144, "Shibor3M", "Deposit", "Shibor3M"),
                new RateMktData("6M", 0.0323, "Shibor3M", "InterestRateSwap", "Shibor3M"),
                new RateMktData("9M", 0.0323, "Shibor3M", "InterestRateSwap", "Shibor3M"),
                new RateMktData("1Y", 0.0323, "Shibor3M", "InterestRateSwap", "Shibor3M"),
                new RateMktData("2Y", 0.033, "Shibor3M", "InterestRateSwap", "Shibor3M"),
                new RateMktData("3Y", 0.03325, "Shibor3M", "InterestRateSwap", "Shibor3M"),
                new RateMktData("4Y", 0.03345, "Shibor3M", "InterestRateSwap", "Shibor3M"),
                new RateMktData("5Y", 0.03405, "Shibor3M", "InterestRateSwap", "Shibor3M"),
                new RateMktData("7Y", 0.03435, "Shibor3M", "InterestRateSwap", "Shibor3M"),
                new RateMktData("10Y", 0.03585, "Shibor3M", "InterestRateSwap", "Shibor3M"),
            };

            var shibor3MCurve = new InstrumentCurveDefinition(
                "Shibor3M",
                curveConvention,
                shibor3Mrates,
                "SpotCurve");

            curveDefinitions.Add(shibor3MCurve);

            var shibor1Drates = new[]
            {
                new RateMktData("1D", 0.02881, "Shibor1D", "Deposit", "Shibor1D"),
                new RateMktData("7D", 0.03873, "Shibor1W", "Deposit", "Shibor1D"),
                new RateMktData("3M", 0.0285, "Shibor1D", "InterestRateSwap", "Shibor1D"),
                new RateMktData("6M", 0.0285, "Shibor1D", "InterestRateSwap", "Shibor1D"),
                new RateMktData("9M", 0.0285, "Shibor1D", "InterestRateSwap", "Shibor1D"),
                new RateMktData("1Y", 0.0285, "Shibor1D", "InterestRateSwap", "Shibor1D"),
                new RateMktData("2Y", 0.0291, "Shibor1D", "InterestRateSwap", "Shibor1D"),
                new RateMktData("3Y", 0.0293, "Shibor1D", "InterestRateSwap", "Shibor1D"),
            };

            var shibor1DCurve = new InstrumentCurveDefinition(
                "Shibor1D",
                curveConvention,
                shibor1Drates,
                "SpotCurve");

            curveDefinitions.Add(shibor1DCurve);

            var depo1Yrates = new[]
            {
                new RateMktData("3M", 0.0135, "Depo3M", "Deposit", "Depo1Y"),
                new RateMktData("6M", 0.0155, "Depo6M", "Deposit", "Depo1Y"),
                new RateMktData("1Y", 0.0175, "Depo1Y", "Deposit", "Depo1Y"),
                new RateMktData("2Y", 0.01575, "Depo1Y", "InterestRateSwap", "Depo1Y"),
                new RateMktData("3Y", 0.0155, "Depo1Y", "InterestRateSwap", "Depo1Y"),
                new RateMktData("4Y", 0.0166, "Depo1Y", "InterestRateSwap", "Depo1Y"),
                new RateMktData("5Y", 0.0166, "Depo1Y", "InterestRateSwap", "Depo1Y"),
                new RateMktData("7Y", 0.0171, "Depo1Y", "InterestRateSwap", "Depo1Y"),
                new RateMktData("10Y", 0.0181, "Depo1Y", "InterestRateSwap", "Depo1Y"),
            };

            var depo1YCurve = new InstrumentCurveDefinition(
                "Depo1Y",
                curveConvention,
                depo1Yrates,
                "SpotCurve");

            curveDefinitions.Add(depo1YCurve);

            var marketInfo2 = new MarketInfo("TestMarket")
            {
                ReferenceDate         = referenceDate,
                YieldCurveDefinitions = curveDefinitions.ToArray(),
                HistoricalIndexRates  = HistoricalDataLoadHelper.HistoricalIndexRates
            };

            QdpMarket market;

            MarketFunctions.BuildMarket(marketInfo2, out market);
            return(market);
        }
 internal IBroadcastMessage CreateSETMessage(string message)
 {
     IBroadcastMessage result;
     try
     {
         string text = message.Substring(0, 2);
         switch (text)
         {
         case "TP":
             result = new TPMessage(message);
             return result;
         case "L+":
             result = new LSAccumulate(message);
             return result;
         case "PO":
             result = new POMessage(message);
             return result;
         case "B+":
             result = new BCTextMessage(message);
             return result;
         case "IS":
             result = new ISMessage(message);
             return result;
         case "IE":
             result = new IEMessage(message);
             return result;
         case "LO":
             this.loMessage.Unpack(message);
             result = this.loMessage;
             return result;
         case "MT":
             result = new MarketInfo(message);
             return result;
         case "PD":
             this.pdMessage.Unpack(message);
             result = this.pdMessage;
             return result;
         case "SC":
             this.scMessage.Unpack(message);
             result = this.scMessage;
             return result;
         case "SS":
             result = new SSMessage(message);
             return result;
         case "AA":
             this.aaMessage.Unpack(message);
             result = this.aaMessage;
             return result;
         case "NH":
             this.nhMessage.Unpack(message);
             result = this.nhMessage;
             return result;
         case "BA":
             result = new BAMessage(message);
             return result;
         case "0I":
             result = new OrderInfoClient(message);
             return result;
         case "0B":
             this.broadcastMessageClient.Unpack(message);
             result = this.broadcastMessageClient;
             return result;
         case "0G":
             this.dgwOrderReply.Unpack(message);
             result = this.dgwOrderReply;
             return result;
         }
         result = null;
     }
     catch (Exception ex)
     {
         throw ex;
     }
     return result;
 }
예제 #30
0
파일: MainWindow.cs 프로젝트: ssh352/ctp-1
        private void ConvertTDFMarketData(TDFMarketData tdfdata, MarketInfo data)
        {
            if (ChinaMarketValue.dicTDFCode.ContainsKey(tdfdata.WindCode))
            {
                string day  = tdfdata.ActionDay.ToString().Substring(0, 4) + "-" + tdfdata.ActionDay.ToString().Substring(4, 2) + "-" + tdfdata.ActionDay.ToString().Substring(6, 2);
                string time = "";
                if (tdfdata.Time < 100000000)
                {
                    //10点以前
                    time = "0" + tdfdata.Time.ToString().Substring(0, 1) + ":" + tdfdata.Time.ToString().Substring(1, 2) + ":" + tdfdata.Time.ToString().Substring(3, 2);
                }
                else
                {
                    time = tdfdata.Time.ToString().Substring(0, 2) + ":" + tdfdata.Time.ToString().Substring(2, 2) + ":" + tdfdata.Time.ToString().Substring(4, 2);
                }

                data.time = day + " " + time;
                if (!string.IsNullOrEmpty(data.time))
                {
                    //换一天的时候把成交量清掉
                    if (day.CompareTo(data.time.Substring(0, 10)) > 0)
                    {
                        data.filledNum = "0";
                    }
                }

                data.exchangeCode = ChinaMarketValue.dicTDFCode[tdfdata.WindCode].Market;
                data.code         = tdfdata.WindCode;
                data.salePrice    = FormatFracPrx(tdfdata.AskPrice[0]);
                data.saleNumber   = (tdfdata.AskVol[0]).ToString();
                data.buyPrice     = FormatFracPrx(tdfdata.BidPrice[0]).ToString();
                data.buyNumber    = (tdfdata.BidVol[0]).ToString();
                data.currPrice    = FormatFracPrx(tdfdata.Match).ToString();

                if (tdfdata.Volume > CommonFunction.StringToDecimal(data.filledNum) && tdfdata.Volume > 0)
                {
                    //成交数据
                    data.currNumber = (tdfdata.Volume - (long)CommonFunction.StringToDecimal(data.filledNum)).ToString();
                    data.type       = "2";
                }
                else
                {
                    data.currNumber = "0";
                    data.type       = "Z";
                }
                data.filledNum = tdfdata.Volume.ToString();
                //data.currNumber = (Tdfdata.Match / 10000).ToString();
                data.high     = FormatFracPrx(tdfdata.High).ToString();
                data.low      = FormatFracPrx(tdfdata.Low).ToString();
                data.open     = FormatFracPrx(tdfdata.Open).ToString();
                data.oldClose = FormatFracPrx(tdfdata.PreClose).ToString();


                data.salePrice2  = FormatFracPrx(tdfdata.AskPrice[1]).ToString();
                data.salePrice3  = FormatFracPrx(tdfdata.AskPrice[2]).ToString();
                data.salePrice4  = FormatFracPrx(tdfdata.AskPrice[3]).ToString();
                data.salePrice5  = FormatFracPrx(tdfdata.AskPrice[4]).ToString();
                data.saleNumber2 = (tdfdata.AskVol[1]).ToString();
                data.saleNumber3 = (tdfdata.AskVol[2]).ToString();
                data.saleNumber4 = (tdfdata.AskVol[3]).ToString();
                data.saleNumber5 = (tdfdata.AskVol[4]).ToString();
                data.buyPrice2   = FormatFracPrx(tdfdata.BidPrice[1]).ToString();
                data.buyPrice3   = FormatFracPrx(tdfdata.BidPrice[2]).ToString();
                data.buyPrice4   = FormatFracPrx(tdfdata.BidPrice[3]).ToString();
                data.buyPrice5   = FormatFracPrx(tdfdata.BidPrice[4]).ToString();
                data.buyNumber2  = (tdfdata.BidVol[1]).ToString();
                data.buyNumber3  = (tdfdata.BidVol[2]).ToString();
                data.buyNumber4  = (tdfdata.BidVol[3]).ToString();
                data.buyNumber5  = (tdfdata.BidVol[4]).ToString();
            }
        }
예제 #31
0
	public ZFGood(ZFGood goodInfo)
	{
		this.ID = goodInfo.ID;
		this.name = goodInfo.name;
		this.description = goodInfo.description;
		this.typePurchase = goodInfo.typePurchase;
		this.marketInfo = new MarketInfo(goodInfo.marketInfo);
		this.virtualInfo = new VirtualInfo(goodInfo.virtualInfo);
		this.goodType = goodInfo.goodType;
	}
    public void AddMarketRowToScrollView(int _marketId, int _itemId, string _itemName, int _typeId, string _typeName, int _playerId, string _nickname, int _quantity, int _priceForUnit)
    {
        MarketInfo _marketInfo = Instantiate(marketInfoPrefab, marketRowScrollViewContent).GetComponent <MarketInfo>();

        _marketInfo.SetValues(_marketId, _itemId, _itemName, _typeId, _typeName, _playerId, _nickname, _quantity, _priceForUnit);
    }
예제 #33
0
	public ZFCurrencyPack()
	{
		this.marketInfo = new MarketInfo();
	}
예제 #34
0
 private AuthorizedStrategyMonitor(IHubContext context)
 {
     //向行情模块添加消息列表映射
     MarketInfo.SetStrategyQueue(new KeyValuePair <String, Queue>(ModuleName, queue_authorized_market.GetQueue()));
     _context = context;
 }
예제 #35
0
	private void declareProductId(SoomlaScriptBuilder builder, string id, MarketInfo marketInfo) {
		bool hasOverrides = false;
		// for iOS
		if (marketInfo.useIos) {
			builder.AppendLine("#if UNITY_IOS");
			builder.AppendLine(string.Format("public const string {0}_PRODUCT_ID = \"{1}\";", id.ToUpper(), marketInfo.iosId));
			hasOverrides = true;
		}
		// for Android
		if (marketInfo.useAndroid) {
			if (hasOverrides) {
				builder.AppendLine("#elif UNITY_ANDROID");
			} else {
				builder.AppendLine("#if UNITY_ANDROID");
			}
			builder.AppendLine(string.Format("public const string {0}_PRODUCT_ID = \"{1}\";", id.ToUpper(), marketInfo.androidId));
			hasOverrides = true;
		}
		// default value
		if (hasOverrides) {
			builder.AppendLine("#else");
		}
		builder.AppendLine(string.Format("public const string {0}_PRODUCT_ID = \"{1}\";", id.ToUpper(), marketInfo.productId));
        if (hasOverrides) {
            builder.AppendLine("#endif");
        }
    }
예제 #36
0
        public virtual void PushQuoteReceived(Quote quote)
        {
            if (quote.ServerTime == DateTime.MinValue)
            {
                quote.ServerTime = this.DataSource.MarketInfo.ConvertLocalTimeToServer(DateTime.Now);
            }

            MarketInfo marketInfo = this.DataSource.MarketInfo;

            //if (marketInfo.IsMarketOpenNow == false) {
            if (marketInfo.IsMarketOpenAtServerTime(quote.ServerTime) == false)
            {
                MarketClearingTimespan clearingTimespanOut;
                DateTime dateTimeNextBarOpenConditional = marketInfo.GetNextMarketServerTimeStamp(
                    quote.ServerTime, this.DataSource.ScaleInterval, out clearingTimespanOut);
                string reason = (clearingTimespanOut != null) ? "is CLEARING" : "CLOSED";
                string msg    = "[" + marketInfo.Name + "]Market " + reason + ", resumes["
                                + dateTimeNextBarOpenConditional.ToString("HH:mm") + "]; ignoring quote[" + quote + "]";
                this.UpdateConnectionStatus(503, msg);
                return;
            }
            else
            {
                int a = 1;
            }

            Quote lastQuote = this.StreamingDataSnapshot.LastQuoteGetForSymbol(quote.Symbol);

            if (lastQuote == null)
            {
                string msg = "RECEIVED_FIRST_QUOTE_EVER_FOR symbol[" + quote.Symbol + "]";
                //Assembler.PopupException(msg);
                //throw new Exception(msg);
            }
            else
            {
                //LESS PRECISE, HAS NO MILLISECONDS FROM QUIK if (quote.ServerTime > lastQuote.ServerTime) {
                if (quote.ServerTime.Ticks > lastQuote.ServerTime.Ticks)
                {
                    //if (quote.IntraBarSerno < Quote.IntraBarSernoShiftForGeneratedTowardsPendingFill) {
                    //    quote.IntraBarSerno = lastQuote.IntraBarSerno + 1;
                    //    if (quote.IntraBarSerno > Quote.IntraBarSernoShiftForGeneratedTowardsPendingFill) {
                    //        string msg = "#3 bro, leave QUOTE unmodified!!!";
                    //        Debugger.Break();
                    //    }
                    //}
                }
                else
                {
                    Assembler.PopupException("WEIRD: upcoming quote.LocalTimeCreatedMillis[" + quote.LocalTimeCreatedMillis.ToString("HH:mm:ss.fff")
                                             + "] <= lastQuoteReceived.Symbol." + quote.Symbol + "["
                                             + lastQuote.LocalTimeCreatedMillis.ToString("HH:mm:ss.fff") + "]: DDE lagged somewhere?...");
                }
                quote.Absno = lastQuote.Absno + 1;
            }

            this.EnrichQuoteWithStreamingDependantDataSnapshot(quote);

            //BacktestStreamingProvider.EnrichGeneratedQuoteSaveSpreadInStreaming has updated lastQuote alredy...
            this.StreamingDataSnapshot.UpdateLastBidAskSnapFromQuote(quote);
            try {
                this.DataDistributor.PushQuoteToChannel(quote);
            } catch (Exception e) {
                string msg = "StreamingProvider.PushReceivedQuote()";
                Assembler.PopupException(msg, e);
                //throw e;
            }
        }