Beispiel #1
0
 public LinearCurveTest()
 {
     _points = new[] {
         new Position(10, 10),
         new Position(20, 20)
     };
     _curve = new LinearCurve(_points, 10);
 }
Beispiel #2
0
 public PerfectCurveTest()
 {
     _points = new[] {
         new Position(10, 10),
         new Position(20, 20),
         new Position(30, 10)
     };
     _curve = new PerfectCurve(_points, -1);
 }
Beispiel #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="logger"></param>
        /// <param name="cache"></param>
        /// <param name="ratecurve"></param>
        /// <param name="fixingCalendar"></param>
        /// <param name="paymentCalendar"></param>
        /// <returns></returns>
        public virtual decimal[] CalculatePDH(ILogger logger, ICoreCache cache, CurveBase ratecurve, IBusinessCalendar fixingCalendar, IBusinessCalendar paymentCalendar)
        {
            if (AnalyticsModel == null)
            {
                switch (ModelIdentifier)
                {
                case "SimpleSwapAsset":
                case "ClearedSwapAsset":
                    AnalyticsModel = new SimpleSwapAssetAnalytic();
                    break;

                case "SimpleDiscountSwapAsset":
                case "DiscountClearedSwapAsset":
                    AnalyticsModel = new SimpleDiscountSwapAssetAnalytic();
                    break;
                }
            }
            var result = new List <decimal>();

            if (ratecurve != null)
            {
                var riskCurves = ratecurve.CreateCurveRiskSet(1);
                ISwapAssetParameters analyticModelParameters = new IRSwapAssetParameters
                {
                    NotionalAmount = Notional,
                    //2. Get the discount factors
                    DiscountFactors =
                        GetDiscountFactors(ratecurve,
                                           AdjustedPeriodDates.ToArray(),
                                           BaseDate),
                    //3. Get the respective year fractions
                    YearFractions = YearFractions,
                    Rate          =
                        MarketQuoteHelper.NormalisePriceUnits(
                            FixedRate, "DecimalRate").value
                };
                //4. Get the Weightings
                analyticModelParameters.Weightings =
                    CreateWeightings(CDefaultWeightingValue, analyticModelParameters.DiscountFactors.Length - 1);
                //4. Set the anaytic input parameters and Calculate the respective metrics
                //
                if (AnalyticsModel != null)
                {
                    var analyticResults = AnalyticsModel.Calculate <IRateAssetResults, RateAssetResults>(analyticModelParameters, new[] { RateMetrics.NPV });
                    var baseNPV         = analyticResults.NPV;
                    //Now loop through the risk curves.
                    foreach (var curve in riskCurves)
                    {
                        analyticResults = RiskCalculationHelper((IRateCurve)curve, analyticModelParameters);
                        result.Add(analyticResults.NPV - baseNPV);
                    }
                }
            }
            return(result.ToArray());
        }
        /// <summary>
        /// Awake.
        /// </summary>
        void Awake()
        {
            if (!this.initFlag)
            {
                this.curve        = this.gameObject.GetComponent <CurveBase>();
                this.lineRenderer = this.gameObject.GetComponent <LineRenderer>();

                if (this.curve != null)
                {
                    this.curve.ValueChanged += this.OnCurveEvaluatorValueChanged;
                    this.typeTxt.text        = this.curveType.ToString();
                    this.DrawCurve();
                }

                this.initFlag = true;
            }
        }
Beispiel #5
0
        public BezierTest()
        {
            _points = new[] {
                new Position(10, 10),
                new Position(20, 20),
                new Position(20, 20),
                new Position(30, 10)
            };
            var _points2 = new[] {
                new Position(10, 10),
                new Position(20, 20),
                new Position(20, 20),
                new Position(27, 17),
                new Position(30, 10)
            };

            _curve  = new BezierCurve(_points, -1);
            _curve2 = new BezierCurve(_points2, -1);
        }
Beispiel #6
0
        /// <summary>
        /// Calculates the specified metric for the fast bootstrapper.
        /// </summary>
        /// <param name="discountCurve">The discount curve.</param>
        /// <param name="forecastCurve">The forecast curve</param>
        /// <param name="curveToPerturb">The curve to perturb: the discount curve, the forecast curve or both.</param>
        /// <returns></returns>
        public IDictionary <string, Decimal> CalculatePDH(CurveBase discountCurve, CurveBase forecastCurve, CurvePerturbation curveToPerturb)
        {
            if (AnalyticsModel == null)
            {
                switch (ModelIdentifier)
                {
                case "SwapAsset":
                    AnalyticsModel = new SwapAssetAnalytic();
                    break;

                case "DiscountSwapAsset":
                    AnalyticsModel = new DiscountSwapAssetAnalytic();
                    break;
                }
            }
            var result = new Dictionary <string, Decimal>();

            if (discountCurve != null && forecastCurve != null)
            {
                ISwapAssetParameters analyticModelParameters = new IRSwapAssetParameters
                {
                    NotionalAmount = Notional,
                    //2. Get the discount factors
                    DiscountFactors =
                        GetDiscountFactors(discountCurve,
                                           AdjustedPeriodDates.ToArray(),
                                           BaseDate),
                    //3. Get the respective year fractions
                    YearFractions = YearFractions,
                    Weightings    = Weightings,
                    Rate          =
                        MarketQuoteHelper.NormalisePriceUnits(
                            FixedRate, "DecimalRate").value,
                    FloatingLegDiscountFactors =
                        GetDiscountFactors(discountCurve,
                                           FloatingLegAdjustedPeriodDates.ToArray(),
                                           BaseDate),
                    FloatingLegForecastDiscountFactors =
                        GetDiscountFactors(forecastCurve, FloatingLegAdjustedPeriodDates.ToArray(), BaseDate),
                    FloatingLegYearFractions = FloatingLegYearFractions,
                    FloatingLegWeightings    = FloatingLegWeightings,
                    FloatingLegSpread        =
                        MarketQuoteHelper.NormalisePriceUnits(
                            FloatingLegSpread, "DecimalRate").value
                };
                if (ForwardRates != null)
                {
                    analyticModelParameters.FloatingLegForwardRates = ForwardRates;
                }
                //4. Set the analytic input parameters and Calculate the respective metrics
                //
                if (AnalyticsModel != null)
                {
                    var analyticResults = AnalyticsModel.Calculate <IRateAssetResults, RateAssetResults>(analyticModelParameters, new[] { RateMetrics.NPV });
                    AnalyticResults = analyticResults;
                    analyticModelParameters.BaseNPV = analyticResults.NPV;
                    //Now loop through the risk curves.
                    if (curveToPerturb == CurvePerturbation.DiscountCurve)
                    {
                        var riskCurves = discountCurve.CreateCurveRiskSet(1);
                        foreach (var curve in riskCurves)
                        {
                            var perturbedAsset = curve.GetPricingStructureId().Properties.GetValue <string>("PerturbedAsset");
                            analyticResults = RiskCalculationHelper((IRateCurve)curve, analyticModelParameters);
                            result.Add("DiscountCurve:" + perturbedAsset, analyticResults.NPVChange);
                        }
                    }
                    if (curveToPerturb == CurvePerturbation.ForecastCurve)
                    {
                        var riskCurves = forecastCurve.CreateCurveRiskSet(1);
                        foreach (var curve in riskCurves)
                        {
                            var perturbedAsset = curve.GetPricingStructureId().Properties.GetValue <string>("PerturbedAsset");
                            analyticResults = ForecastRiskCalculationHelper((IRateCurve)curve, analyticModelParameters);
                            result.Add("ForecastCurve:" + perturbedAsset, analyticResults.NPVChange);
                        }
                    }
                    if (curveToPerturb == CurvePerturbation.Both)
                    {
                        var riskCurves1 = discountCurve.CreateCurveRiskSet(1);
                        foreach (var curve in riskCurves1)
                        {
                            var perturbedAsset = curve.GetPricingStructureId().Properties.GetValue <string>("PerturbedAsset");
                            analyticResults = RiskCalculationHelper((IRateCurve)curve, analyticModelParameters);
                            result.Add("DiscountCurve:" + perturbedAsset, analyticResults.NPVChange);
                        }
                        var riskCurves2 = forecastCurve.CreateCurveRiskSet(1);
                        foreach (var curve in riskCurves2)
                        {
                            var perturbedAsset = curve.GetPricingStructureId().Properties.GetValue <string>("PerturbedAsset");
                            analyticResults = ForecastRiskCalculationHelper((IRateCurve)curve, analyticModelParameters);
                            result.Add("ForecastCurve:" + perturbedAsset, analyticResults.NPVChange);
                        }
                    }
                }
            }
            return(result);
        }
Beispiel #7
0
 private void Add(CurveBase curveBase)
 {
     // if(curveBase == )
 }
        /// <summary>
        /// カーブタイプの変更。
        /// </summary>
        void ChangeCurveType(CurveType curveType)
        {
            if (this.curve != null &&
                ((curveType == CurveType.StraightLine && this.curve.GetType() == typeof(StraightLine)) ||
                 (curveType == CurveType.HermiteCurve && this.curve.GetType() == typeof(HermiteCurve)) ||
                 (curveType == CurveType.BezierCurve && this.curve.GetType() == typeof(BezierCurve)) ||
                 (curveType == CurveType.RationalBezierCurve && this.curve.GetType() == typeof(RationalBezierCurve)) ||
                 (curveType == CurveType.BSplineCurve && this.curve.GetType() == typeof(BSplineCurve)) ||
                 (curveType == CurveType.NURBSCurve && this.curve.GetType() == typeof(NURBSCurve))) ||
                (curveType == CurveType.CatmullRomSplineCurve && this.curve.GetType() == typeof(CatmullRomSplineCurve)))
            {
                return;
            }

            this.curveType    = curveType;
            this.typeTxt.text = this.curveType.ToString();

            // see : http://anchan828.hatenablog.jp/entry/2013/11/18/012021
            EditorApplication.delayCall += () => {
                if (this.curve != null)
                {
                    this.curve.ValueChanged -= this.OnCurveEvaluatorValueChanged;
                    DestroyImmediate(this.curve);
                    this.curve = null;
                }

                switch (curveType)
                {
                case CurveType.None:
                    return;

                    break;

                case CurveType.StraightLine:
                    this.curve = this.gameObject.AddComponent <StraightLine>();
                    break;

                case CurveType.HermiteCurve:
                    this.curve = this.gameObject.AddComponent <HermiteCurve>();
                    break;

                case CurveType.BezierCurve:
                    this.curve = this.gameObject.AddComponent <BezierCurve>();
                    break;

                case CurveType.RationalBezierCurve:
                    this.curve = this.gameObject.AddComponent <RationalBezierCurve>();
                    break;

                case CurveType.BSplineCurve:
                    this.curve = this.gameObject.AddComponent <BSplineCurve>();
                    break;

                case CurveType.NURBSCurve:
                    this.curve = this.gameObject.AddComponent <NURBSCurve>();
                    break;

                case CurveType.CatmullRomSplineCurve:
                    this.curve = this.gameObject.AddComponent <CatmullRomSplineCurve>();
                    break;
                }

                if (this.curve != null)
                {
                    this.curve.ValueChanged += this.OnCurveEvaluatorValueChanged;
                    this.DrawCurve();
                }
            };
        }