Esempio n. 1
0
        public void TestJsonSerializerFormat()
        {
            var x = new[]
            {
                new MktDepositJson
                {
                    IndexType   = "Fr007",
                    DepositInfo = new DepositInfo
                    {
                        StartDate = "2015-02-02"
                    }
                },
                new MktDepositJson
                {
                    IndexType   = "Fr001",
                    DepositInfo = new DepositInfo
                    {
                        StartDate = "2015-02-22"
                    }
                },
            };

            var strX = DataContractJsonObjectSerializer.Serialize(x);

            Console.WriteLine(strX);

            var configReader = new ConfigFileTextReader("Configurations", "MarketInstrumentConventions", "Deposit.cfg");
            var depositRule2 = DataContractJsonObjectSerializer.Deserialize <MktDepositJson[]>(configReader.ReadAllText())
                               .ToDictionary(item => item.IndexType, item => item);

            Console.WriteLine(depositRule2.Count);
            Assert.AreEqual(depositRule2.Count, 9);
        }
Esempio n. 2
0
        static MktInstrumentIrsRule()
        {
            var configReader = new ConfigFileTextReader("Configurations", "MarketInstrumentConventions", "Irs.cfg");

            MktIrsRule = DataContractJsonObjectSerializer.Deserialize <MktIrsJson[]>(configReader.ReadAllText())
                         .ToDictionary(x => x.IndexType.ToIndexType(), x => x);
        }
Esempio n. 3
0
        static CalendarImpl()
        {
            if (!_cacheCalendarData)
            {
                const string filenameSuffix = ".txt";
#if !NETCOREAPP2_1
                //TODO: fix it
                try
                {
                    if (System.AppDomain.CurrentDomain.DomainManager.HostExecutionContextManager.ToString().IndexOf("System.Web") >= 0)
                    {
                        FileLocationType = ConfigFileLocationType.Web;
                    }
                }
                catch
                {
                    // ignore the error for now.
                }
#endif

                var calendarFiles =
                    ConfigFilePathHelper.GetFiles(FileLocationType, "Data", "Calendars")
                    .Where(x => x.EndsWith(filenameSuffix))
                    .ToArray();

                var calendars = calendarFiles.Select(x =>
                {
                    var calendarName     = Path.GetFileNameWithoutExtension(x).ToUpper();
                    var s                = File.ReadAllText(x);
                    var calendarHolidays = DataContractJsonObjectSerializer.Deserialize <CalendarHoliday>(s);
                    return(new CalendarImpl(calendarName, calendarHolidays));
                });

                AllCalendars = calendars.ToDictionary(x => x.CalendarName, x => x as ICalendar);
            }
        }
Esempio n. 4
0
        public static ConvertibleBondInfo ToConvertibleBondInfo(BondInfoBase bondInfo,
                                                                string conversionStartDate,
                                                                string conversionEndDate,
                                                                string conversionStockcode,
                                                                double conversionPrice,
                                                                string dividenCurveName,
                                                                bool treatAsCommonBond       = false,
                                                                string[] ebcStrikeQuoteTypes = null,
                                                                string[] ebpStrikeQuoteTypes = null)
        {
            var json     = DataContractJsonObjectSerializer.Serialize(bondInfo);
            var bondPart = DataContractJsonObjectSerializer.Deserialize <BondInfoBase>(json);

            bondPart.OptionToAssPut = null;
            bondPart.OptionToCall   = null;
            bondPart.OptionToPut    = null;

            var hasPut  = !(bondInfo.OptionToPut == null || !bondInfo.OptionToPut.Any());
            var hasCall = !(bondInfo.OptionToCall == null || !bondInfo.OptionToCall.Any());

            if (!hasPut)
            {
                bondInfo.OptionToPut = new Dictionary <string, double>();
            }
            if (!hasCall)
            {
                bondInfo.OptionToCall = new Dictionary <string, double>();
            }

            var ebos = bondInfo.OptionToPut.Select(x => new VanillaOptionInfo
                                                       (tradeId: "",
                                                       strike: x.Value,
                                                       underlyingTicker: bondInfo.BondId,
                                                       underlyingInstrumentType: "Bond",
                                                       valuationParameter: null,
                                                       startDate: bondInfo.StartDate,
                                                       underlyingMaturityDate: bondInfo.MaturityDate,
                                                       exerciseDates: x.Key,
                                                       calendar: bondInfo.Calendar,
                                                       dayCount: bondInfo.DayCount,
                                                       exercise: "European",
                                                       notional: 1.0,
                                                       optionType: "Call"
                                                       )).Union(
                bondInfo.OptionToCall.Select(x => new VanillaOptionInfo
                                                 ("",
                                                 strike: x.Value,
                                                 underlyingTicker: bondInfo.BondId,
                                                 underlyingInstrumentType: "Bond",
                                                 valuationParameter: null,
                                                 startDate: bondInfo.StartDate,
                                                 underlyingMaturityDate: bondInfo.MaturityDate,
                                                 exerciseDates: x.Key,
                                                 calendar: bondInfo.Calendar,
                                                 optionType: "Put",
                                                 dayCount: bondInfo.DayCount,
                                                 notional: 1.0)
                                             )
                ).ToArray();

            var eboStrikQuoteTypes = ebcStrikeQuoteTypes ?? new string[0]
                                     .Union(ebpStrikeQuoteTypes ?? new string[0])
                                     .ToArray();

            var conversion = new VanillaOptionInfo(
                tradeId: "",
                strike: conversionPrice,
                underlyingTicker: bondInfo.BondId,
                underlyingInstrumentType: "Stock",
                valuationParameter: null,
                startDate: conversionStartDate,
                underlyingMaturityDate: conversionEndDate,
                calendar: bondInfo.Calendar,
                optionType: "Call",
                exercise: "American",
                dayCount: bondInfo.DayCount,
                notional: 1.0,
                exerciseDates: bondInfo.OptionToCall.Keys.First()
                );

            return(new ConvertibleBondInfo(bondPart.BondId)
            {
                BondPart = bondPart,
                ConversionOption = conversion,
                EmbeddedOptions = ebos.Any() ? ebos : null,
                EboStrikeQuoteTypes = eboStrikQuoteTypes.Any() ? eboStrikQuoteTypes : null,
                ValuationParameters = new OptionValuationParameters(discountCurveName: bondInfo.ValuationParamters.DiscountCurveName,
                                                                    dividendCurveName: dividenCurveName,
                                                                    volSurfName: conversionStockcode + "Vol",
                                                                    underlyingId: conversionStockcode),
                TreatAsCommonBond = treatAsCommonBond
            });
        }