Exemplo n.º 1
0
        public void Price_MonthlyCurveBusinessDayWeight_EqualsWeightedAverage()
        {
            var curve = new DoubleCurve <Month>(Month.CreateJanuary(2020), new[] { 56.54, 54.15, 51.14 },
                                                Weighting.BusinessDayCount <Month>(new Day[0]));

            double q1Price = curve.Price(Quarter.CreateQuarter1(2020));

            const double expectedQ1Price = (56.54 * 23.0 + 54.15 * 20.0 + 51.14 * 22.0) / 65.0;

            Assert.AreEqual(expectedQ1Price, q1Price);
        }
Exemplo n.º 2
0
        public void PriceStartAndEndParameters_MonthlyCurveBusinessDayWeight_EqualsWeightedAverage()
        {
            var curve = new DoubleCurve <Month>(Month.CreateJanuary(2020), new [] { 56.54, 54.15, 51.14 },
                                                Weighting.BusinessDayCount <Month>(new Day[0]));

            double febMarPrice = curve.Price(Month.CreateFebruary(2020), Month.CreateMarch(2020));

            const double expectedFebMarPrice = (54.15 * 20.0 + 51.14 * 22.0) / 42.0;

            Assert.AreEqual(expectedFebMarPrice, febMarPrice);
        }
Exemplo n.º 3
0
    private void PresetCurveButtons(Rect position, Rect curveEditorRect)
    {
        if (this.m_CurveEditor.animationCurves.Length == 0)
        {
            return;
        }
        this.InitDoubleCurvePresets();
        if (this.m_DoubleCurvePresets == null)
        {
            return;
        }
        DoubleCurvePresetLibrary currentLib = this.m_DoubleCurvePresets.GetPresetLibraryEditor().GetCurrentLib();
        int   num1   = Mathf.Min(!((UnityEngine.Object)currentLib != (UnityEngine.Object)null) ? 0 : currentLib.Count(), 9);
        float width  = 30f;
        float height = 15f;
        float num2   = 10f;
        float num3   = (float)((double)num1 * (double)width + (double)(num1 - 1) * (double)num2);
        float num4   = (float)(((double)position.width - (double)num3) * 0.5);
        float y      = (float)(((double)position.height - (double)height) * 0.5);
        float x      = 3f;

        if ((double)num4 > 0.0)
        {
            x = num4;
        }
        this.PresetDropDown(new Rect(x - 20f + position.x, y + position.y, 16f, 16f));
        GUI.BeginGroup(position);
        Color.white.a *= 0.6f;
        for (int index = 0; index < num1; ++index)
        {
            if (index > 0)
            {
                x += num2;
            }
            Rect rect = new Rect(x, y, width, height);
            ParticleSystemCurveEditor.s_Styles.presetTooltip.tooltip = currentLib.GetName(index);
            if (GUI.Button(rect, ParticleSystemCurveEditor.s_Styles.presetTooltip, GUIStyle.none))
            {
                DoubleCurve preset = currentLib.GetPreset(index) as DoubleCurve;
                if (preset != null)
                {
                    this.SetTopMostCurve(preset);
                    this.m_CurveEditor.ClearSelection();
                }
            }
            if (Event.current.type == EventType.Repaint)
            {
                currentLib.Draw(rect, index);
            }
            x += width;
        }
        GUI.EndGroup();
    }
Exemplo n.º 4
0
        // TODO test using Weighting.BusinessDayCount
        // TODO test without weighting e.g. equal weighting



        private void AssertBootstrappedContractsConsistentWithCurve <T>(DoubleCurve <T> curve,
                                                                        IReadOnlyList <Contract <T> > bootstrappedContracts, Func <T, double> weighting, double tolerance)
            where T : ITimePeriod <T>
        {
            foreach (var bootstrappedContract in bootstrappedContracts)
            {
                foreach (var curvePeriod in bootstrappedContract.Start.EnumerateTo(bootstrappedContract.End))
                {
                    Assert.AreEqual(bootstrappedContract.Price, curve[curvePeriod], tolerance);
                }
            }
        }
Exemplo n.º 5
0
 private void PresetCurveButtons(Rect position, Rect curveEditorRect)
 {
     if (this.m_CurveEditor.animationCurves.Length != 0)
     {
         this.InitDoubleCurvePresets();
         if (this.m_DoubleCurvePresets != null)
         {
             DoubleCurvePresetLibrary currentLib = this.m_DoubleCurvePresets.GetPresetLibraryEditor().GetCurrentLib();
             int   a    = (!(currentLib != null)) ? 0 : currentLib.Count();
             int   num  = Mathf.Min(a, 9);
             float num2 = 30f;
             float num3 = 15f;
             float num4 = 10f;
             float num5 = (float)num * num2 + (float)(num - 1) * num4;
             float num6 = (position.width - num5) * 0.5f;
             float num7 = (position.height - num3) * 0.5f;
             float num8 = 3f;
             if (num6 > 0f)
             {
                 num8 = num6;
             }
             this.PresetDropDown(new Rect(num8 - 20f + position.x, num7 + position.y, 16f, 16f));
             GUI.BeginGroup(position);
             Color color;
             Color.white.a = color.a * 0.6f;
             for (int i = 0; i < num; i++)
             {
                 if (i > 0)
                 {
                     num8 += num4;
                 }
                 Rect rect = new Rect(num8, num7, num2, num3);
                 ParticleSystemCurveEditor.s_Styles.presetTooltip.tooltip = currentLib.GetName(i);
                 if (GUI.Button(rect, ParticleSystemCurveEditor.s_Styles.presetTooltip, GUIStyle.none))
                 {
                     DoubleCurve doubleCurve = currentLib.GetPreset(i) as DoubleCurve;
                     if (doubleCurve != null)
                     {
                         this.SetTopMostCurve(doubleCurve);
                         this.m_CurveEditor.ClearSelection();
                     }
                 }
                 if (Event.current.type == EventType.Repaint)
                 {
                     currentLib.Draw(rect, i);
                 }
                 num8 += num2;
             }
             GUI.EndGroup();
         }
     }
 }
Exemplo n.º 6
0
 private static void LoadValue(ConfigNode node, string key, ref DoubleCurve param)
 {
     if (node.HasNode(key))
     {
         ConfigNode subNode = node.GetNode(key);
         param = new DoubleCurve();
         param.Load(subNode);
     }
     else if (debug)
     {
         CustomBarnKit.log("No node " + key);
     }
 }
 private void PresetCurveButtons(Rect position, Rect curveEditorRect)
 {
     if (this.m_CurveEditor.animationCurves.Length != 0)
     {
         this.InitDoubleCurvePresets();
         if (this.m_DoubleCurvePresets != null)
         {
             DoubleCurvePresetLibrary currentLib = this.m_DoubleCurvePresets.GetPresetLibraryEditor().GetCurrentLib();
             int a = (currentLib == null) ? 0 : currentLib.Count();
             int num2 = Mathf.Min(a, 9);
             float width = 30f;
             float height = 15f;
             float num5 = 10f;
             float num6 = (num2 * width) + ((num2 - 1) * num5);
             float num7 = (position.width - num6) * 0.5f;
             float y = (position.height - height) * 0.5f;
             float x = 3f;
             if (num7 > 0f)
             {
                 x = num7;
             }
             this.PresetDropDown(new Rect((x - 20f) + position.x, y + position.y, 16f, 16f));
             GUI.BeginGroup(position);
             Color.white.a *= 0.6f;
             for (int i = 0; i < num2; i++)
             {
                 if (i > 0)
                 {
                     x += num5;
                 }
                 Rect rect = new Rect(x, y, width, height);
                 s_Styles.presetTooltip.tooltip = currentLib.GetName(i);
                 if (GUI.Button(rect, s_Styles.presetTooltip, GUIStyle.none))
                 {
                     DoubleCurve preset = currentLib.GetPreset(i) as DoubleCurve;
                     if (preset != null)
                     {
                         this.SetTopMostCurve(preset);
                         this.m_CurveEditor.ClearSelection();
                     }
                 }
                 if (Event.current.type == EventType.Repaint)
                 {
                     currentLib.Draw(rect, i);
                 }
                 x += width;
             }
             GUI.EndGroup();
         }
     }
 }
Exemplo n.º 8
0
        public void BuilderWithData_ConstructedWithCapacityParameter_AddsPointsToBuiltSeries()
        {
            var curve = new DoubleCurve <Month> .Builder(1, month => 1.0)
                        .WithData(Month.CreateJanuary(2019), 1.0)
                        .WithData(Month.CreateFebruary(2019), 2.0)
                        .WithData(Month.CreateMarch(2019), 3.0)
                        .Build();

            Assert.AreEqual(3, curve.Count);
            Assert.AreEqual(1.0, curve[Month.CreateJanuary(2019)]);
            Assert.AreEqual(2.0, curve[Month.CreateFebruary(2019)]);
            Assert.AreEqual(3.0, curve[Month.CreateMarch(2019)]);
            Assert.AreEqual(2.0, curve.Price(Quarter.CreateQuarter1(2019)));
        }
 private void InitDoubleCurvePresets()
 {
     int num;
     if (this.m_CurveEditor.GetTopMostCurveID(out num) && ((this.m_DoubleCurvePresets == null) || (this.m_LastTopMostCurveID != num)))
     {
         this.m_LastTopMostCurveID = num;
         Action<DoubleCurve> presetSelectedCallback = delegate (DoubleCurve presetDoubleCurve) {
             this.SetTopMostCurve(presetDoubleCurve);
             InternalEditorUtility.RepaintAllViews();
         };
         DoubleCurve doubleCurveToSave = this.CreateDoubleCurveFromTopMostCurve();
         this.m_DoubleCurvePresets = new DoubleCurvePresetsContentsForPopupWindow(doubleCurveToSave, presetSelectedCallback);
         this.m_DoubleCurvePresets.InitIfNeeded();
     }
 }
Exemplo n.º 10
0
 private void PresetDropDown(Rect rect)
 {
     if (EditorGUI.DropdownButton(rect, EditorGUI.GUIContents.titleSettingsIcon, FocusType.Passive, EditorStyles.inspectorTitlebarText))
     {
         DoubleCurve doubleCurve = this.CreateDoubleCurveFromTopMostCurve();
         if (doubleCurve != null)
         {
             this.InitDoubleCurvePresets();
             if (this.m_DoubleCurvePresets != null)
             {
                 this.m_DoubleCurvePresets.doubleCurveToSave = this.CreateDoubleCurveFromTopMostCurve();
                 PopupWindow.Show(rect, this.m_DoubleCurvePresets);
             }
         }
     }
 }
 void PresetDropDown(Rect rect)
 {
     if (EditorGUI.DropdownButton(rect, EditorGUI.GUIContents.titleSettingsIcon, FocusType.Passive, EditorStyles.inspectorTitlebarText))
     {
         DoubleCurve doubleCurveToSaveAsPreset = CreateDoubleCurveFromTopMostCurve();
         if (doubleCurveToSaveAsPreset != null)
         {
             InitDoubleCurvePresets();
             if (m_DoubleCurvePresets != null)
             {
                 m_DoubleCurvePresets.doubleCurveToSave = CreateDoubleCurveFromTopMostCurve();
                 // We prioritize left first for normal inspector layout (where the inspector is on the right)
                 PopupWindow.Show(rect, m_DoubleCurvePresets);
             }
         }
     }
 }
Exemplo n.º 12
0
        public void BuilderBuild_ConstructedWithCapacityParameter_AsExpected()
        {
            var curve = new DoubleCurve <Month> .Builder(2, month => 1.0)
            {
                { Month.CreateJanuary(2019), 1.0 },
                { Month.CreateFebruary(2019), 2.0 },
                { Month.CreateMarch(2019), 3.0 }
            }

            .Build();

            Assert.AreEqual(3, curve.Count);
            Assert.AreEqual(1.0, curve[Month.CreateJanuary(2019)]);
            Assert.AreEqual(2.0, curve[Month.CreateFebruary(2019)]);
            Assert.AreEqual(3.0, curve[Month.CreateMarch(2019)]);
            Assert.AreEqual(2.0, curve.Price(Quarter.CreateQuarter1(2019)));
        }
    void InitDoubleCurvePresets()
    {
        int topMostCurveID;

        if (m_CurveEditor.GetTopMostCurveID(out topMostCurveID))
        {
            if (m_DoubleCurvePresets == null || m_LastTopMostCurveID != topMostCurveID)
            {
                m_LastTopMostCurveID = topMostCurveID;
                // Selection callback for library window
                System.Action <DoubleCurve> presetSelectedCallback = delegate(DoubleCurve presetDoubleCurve)
                {
                    SetTopMostCurve(presetDoubleCurve);
                    UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
                };
                DoubleCurve doubleCurveToSaveAsPreset = CreateDoubleCurveFromTopMostCurve();
                m_DoubleCurvePresets = new DoubleCurvePresetsContentsForPopupWindow(doubleCurveToSaveAsPreset, presetSelectedCallback);
                m_DoubleCurvePresets.InitIfNeeded();
            }
        }
    }
Exemplo n.º 14
0
 internal static void AssertCurveConsistentWithInputs <T>(IEnumerable <Contract <T> > inputContracts,
                                                          Func <T, double> weighting, DoubleCurve <T> curve, double tolerance)
     where T : ITimePeriod <T>
 {
     foreach (var inputContract in inputContracts)
     {
         var weightedAverageCurvePrice = curve.Price(inputContract.Start, inputContract.End);
         Assert.AreEqual(inputContract.Price, weightedAverageCurvePrice, tolerance);
     }
 }
    void PresetCurveButtons(Rect position, Rect curveEditorRect)
    {
        if (m_CurveEditor.animationCurves.Length == 0)
        {
            return;
        }

        InitDoubleCurvePresets();
        if (m_DoubleCurvePresets == null)
        {
            return;
        }

        DoubleCurvePresetLibrary curveLibrary = m_DoubleCurvePresets.GetPresetLibraryEditor().GetCurrentLib();
        const int maxNumPresets  = 9;
        int       numPresets     = (curveLibrary != null) ? curveLibrary.Count() : 0;
        int       showNumPresets = Mathf.Min(numPresets, maxNumPresets);

        float swatchWidth          = 30;
        float swatchHeight         = 15;
        float spaceBetweenSwatches = 10;
        float presetButtonsWidth   = showNumPresets * swatchWidth + (showNumPresets - 1) * spaceBetweenSwatches;
        float flexWidth            = (position.width - presetButtonsWidth) * 0.5f;

        // Preset swatch area
        float curY = (position.height - swatchHeight) * 0.5f;
        float curX = 3.0f;

        if (flexWidth > 0)
        {
            curX = flexWidth;
        }

        PresetDropDown(new Rect(curX - 20 + position.x, curY + position.y, 16, 16));

        GUI.BeginGroup(position);

        Color curveColor = Color.white;

        curveColor.a *= 0.6f;
        for (int i = 0; i < showNumPresets; i++)
        {
            if (i > 0)
            {
                curX += spaceBetweenSwatches;
            }

            Rect swatchRect = new Rect(curX, curY, swatchWidth, swatchHeight);

            if (swatchRect.xMax > position.width)
            {
                break;
            }

            s_Styles.presetTooltip.tooltip = curveLibrary.GetName(i);
            if (GUI.Button(swatchRect, s_Styles.presetTooltip, GUIStyle.none))
            {
                DoubleCurve presetDoubleCurve = curveLibrary.GetPreset(i) as DoubleCurve;
                if (presetDoubleCurve != null)
                {
                    SetTopMostCurve(presetDoubleCurve);
                    m_CurveEditor.ClearSelection();
                }
            }
            if (Event.current.type == EventType.Repaint)
            {
                curveLibrary.Draw(swatchRect, i);
            }

            curX += swatchWidth;
        }
        GUI.EndGroup();
    }