예제 #1
0
        /// <summary>
        /// Writes the curve nodes in a CSV format to an appendable.
        /// </summary>
        /// <param name="underlying">  the underlying appendable destination </param>
        /// <param name="valuationDate">  the valuation date </param>
        /// <param name="group">  the curve group </param>
        public static void writeCurveNodes(Appendable underlying, LocalDate valuationDate, RatesCurveGroup group)
        {
            CsvOutput csv = CsvOutput.standard(underlying);

            // header
            csv.writeLine(HEADERS_NODES);
            // rows
            string valuationDateStr = valuationDate.ToString();
            IDictionary <Currency, Curve> discountingCurves = group.DiscountCurves;
            ISet <CurveName> names = new HashSet <CurveName>();

            foreach (KeyValuePair <Currency, Curve> entry in discountingCurves.SetOfKeyValuePairs())
            {
                Curve curve = entry.Value;
                nodeLines(valuationDateStr, curve, csv);
                names.Add(curve.Name);
            }
            IDictionary <Index, Curve> forwardCurves = group.ForwardCurves;

            foreach (KeyValuePair <Index, Curve> entry in forwardCurves.SetOfKeyValuePairs())
            {
                Curve curve = entry.Value;
                if (!names.Contains(curve.Name))
                {
                    nodeLines(valuationDateStr, curve, csv);
                    names.Add(curve.Name);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Writes the curve settings in a CSV format to an appendable.
        /// </summary>
        /// <param name="underlying">  the underlying appendable destination </param>
        /// <param name="group">  the curve group </param>
        public static void writeCurveSettings(Appendable underlying, RatesCurveGroup group)
        {
            CsvOutput csv = CsvOutput.standard(underlying);

            // header
            csv.writeLine(HEADERS_SETTINGS);
            // rows
            IDictionary <Currency, Curve> discountingCurves = group.DiscountCurves;
            ISet <CurveName> names = new HashSet <CurveName>();

            foreach (KeyValuePair <Currency, Curve> entry in discountingCurves.SetOfKeyValuePairs())
            {
                Curve curve = entry.Value;
                csv.writeLine(curveSettings(curve));
                names.Add(curve.Name);
            }
            IDictionary <Index, Curve> forwardCurves = group.ForwardCurves;

            foreach (KeyValuePair <Index, Curve> entry in forwardCurves.SetOfKeyValuePairs())
            {
                Curve curve = entry.Value;
                if (!names.Contains(curve.Name))
                {
                    csv.writeLine(curveSettings(curve));
                    names.Add(curve.Name);
                }
            }
        }
        //-------------------------------------------------------------------------
        /// <summary>
        /// Write sensitivities to an appendable in the standard sensitivities format.
        /// <para>
        /// The output is written in standard format, with no identifier columns.
        /// The parameter metadata must contain tenors.
        ///
        /// </para>
        /// </summary>
        /// <param name="curveSens">  the curve sensitivities to write </param>
        /// <param name="output">  the appendable to write to </param>
        /// <exception cref="IllegalArgumentException"> if the metadata does not contain tenors </exception>
        /// <exception cref="UncheckedIOException"> if an IO error occurs </exception>
        public void write(CurveSensitivities curveSens, Appendable output)
        {
            CsvOutput      csv = CsvOutput.standard(output, "\n");
            IList <string> additionalHeaders = supplier.headers(curveSens);

            // check for dates
            if (curveSens.TypedSensitivities.values().stream().flatMap(allParamSens => allParamSens.Sensitivities.stream()).flatMap(paramSens => paramSens.ParameterMetadata.stream()).anyMatch(pmd => !(pmd is TenoredParameterMetadata)))
            {
                throw new System.ArgumentException("Parameter metadata must contain tenors");
            }
            bool containsDates = curveSens.TypedSensitivities.values().stream().flatMap(allParamSens => allParamSens.Sensitivities.stream()).flatMap(paramSens => paramSens.ParameterMetadata.stream()).anyMatch(pmd => pmd is DatedParameterMetadata);

            // headers
            csv.writeCell(SensitivityCsvLoader.REFERENCE_HEADER);
            csv.writeCell(SensitivityCsvLoader.TYPE_HEADER);
            csv.writeCell(SensitivityCsvLoader.TENOR_HEADER);
            if (containsDates)
            {
                csv.writeCell(SensitivityCsvLoader.DATE_HEADER);
            }
            csv.writeCell(SensitivityCsvLoader.CURRENCY_HEADER);
            csv.writeCell(SensitivityCsvLoader.VALUE_HEADER);
            csv.writeLine(additionalHeaders);

            // content, grouped by reference, then type
            MapStream.of(curveSens.TypedSensitivities).flatMapValues(sens => sens.Sensitivities.stream()).mapKeys((type, sens) => Pair.of(sens.MarketDataName.Name, type)).sortedKeys().forEach((pair, paramSens) => write(pair.First, pair.Second, curveSens, paramSens, additionalHeaders, containsDates, csv));
        }
        /// <summary>
        /// Writes the curve group in a CSV format to an appendable.
        /// </summary>
        /// <param name="underlying">  the underlying appendable destination </param>
        /// <param name="groups">  the curve groups </param>
        public static void writeCurveGroup(Appendable underlying, params RatesCurveGroup[] groups)
        {
            CsvOutput csv = CsvOutput.standard(underlying);

            csv.writeLine(HEADERS);
            foreach (RatesCurveGroup group in groups)
            {
                writeCurveGroup(csv, group);
            }
        }