bool CellLocationHasEast(CellLocation testLocation)
    {
        if (testLocation.x == NumBuildingBlocksAcross - 1)
        {
            return(false);
        }

        BuildingBlockType testType = buildingBlockTypeGrid[testLocation.x, testLocation.z];

        switch (testType)
        {
        case BuildingBlockType.WNES:
        case BuildingBlockType.WE:
        case BuildingBlockType.NE:
        case BuildingBlockType.ES:
        case BuildingBlockType.WNE:
        case BuildingBlockType.WES:
        case BuildingBlockType.NES:
        case BuildingBlockType.Ex:
            return(true);

        default:
            return(false);
        }
    }
Exemple #2
0
    // Members
    // Add a rate
    public void Add(double Value, string Maturity, BuildingBlockType Type)
    {
        RateSet aRate = new RateSet(Value, Maturity, Type);

        aRate.refDate = this.refDate;  // get the same ref Date. Needed in CompareTo
        List.Add(aRate);
    }
    bool CellLocationHasNorth(CellLocation testLocation)
    {
        if (testLocation.z == NumBuildingBlocksUp - 1)
        {
            return(false);
        }

        BuildingBlockType testType = buildingBlockTypeGrid[testLocation.x, testLocation.z];

        switch (testType)
        {
        case BuildingBlockType.WNES:
        case BuildingBlockType.NS:
        case BuildingBlockType.NE:
        case BuildingBlockType.WN:
        case BuildingBlockType.WNE:
        case BuildingBlockType.NES:
        case BuildingBlockType.WNS:
        case BuildingBlockType.Nx:
            return(true);

        default:
            return(false);
        }
    }
    bool CellLocationHasSouth(CellLocation testLocation)
    {
        if (testLocation.z == 0)
        {
            return(false);
        }

        BuildingBlockType testType = buildingBlockTypeGrid[testLocation.x, testLocation.z];

        switch (testType)
        {
        case BuildingBlockType.WNES:
        case BuildingBlockType.NS:
        case BuildingBlockType.WS:
        case BuildingBlockType.ES:
        case BuildingBlockType.WES:
        case BuildingBlockType.NES:
        case BuildingBlockType.WNS:
        case BuildingBlockType.Sx:
            return(true);

        default:
            return(false);
        }
    }
    protected void PrePorcessData(RateSet rateSetMC, ISingleRateCurve DiscountingCurve)
    {
        this.refDate    = rateSetMC.refDate;
        this.DCurve     = DiscountingCurve;    // my curve used in discounting
        FWDInterpolator = new Interpolation(); // Interpolator used in fwd
        this.mktRateSet = rateSetMC;           // pass market rate set

        // Create Building block
        IEnumerable <BuildingBlock> BB = mktRateSet.GetArrayOfBB();

        // Sort ascending end date
        BBArray = from c in BB
                  orderby c.endDate.SerialValue ascending
                  select c;

        // Only Given Swap from BBArray
        OnlyGivenSwap = (from c in BBArray
                         where c.GetType().BaseType == typeof(SwapStyle)
                         select(SwapStyle) c).ToArray();


        // validating underlying tenor: swap should be all vs the same tenor
        string UnderlyingTenor = ((SwapStyle)OnlyGivenSwap.First()).swapLeg2.UnderlyingRateTenor;

        // Getting the fixing
        fixing = (from c in BBArray
                  where c.GetType().BaseType == typeof(OnePaymentStyle)
                  where c.endDate == refDate.add_period(UnderlyingTenor)
                  select c.rateValue).Single();

        // From date of each fwd rate from longer swap(LS)
        // FromDatesSerial = Date.GetSerialValue(OnlyGivenSwap.Last().scheduleLeg2.fromDates);
        List <double> SerialDate = (from c in OnlyGivenSwap
                                    select c.scheduleLeg2.fromDates.Last().SerialValue).ToList <double>();

        // adding reference date at beginning (this is important since I use the fixing)
        SerialDate.Insert(0, refDate.SerialValue);
        FromDatesSerial = SerialDate.ToArray();

        // some data validation: swap should be all of same building block

        // the type of building block
        BuildingBlockType BBT = OnlyGivenSwap[0].buildingBlockType;

        // Are all them the same?
        bool IsSameSwapType = OnlyGivenSwap.All(s => s.buildingBlockType == BBT);

        if (IsSameSwapType)  // if true
        {
            // it is swap type used as inputs (i.e. EurSwapVs6m, EurSwapVs3m, ...)
            SwapType = (SwapStyle) new BuildingBlockFactory().CreateEmptyBuildingBlock(BBT);
        }
        else
        {
            throw new ArgumentException("error in building blocktype"); // if not throw an exception
        }
    }
    Transform GetPrefabFromBuildingBlockType(BuildingBlockType bbType)
    {
        switch (bbType)
        {
        case BuildingBlockType.Empty:
            return(PrefabBuildingBlock_Empty);

        case BuildingBlockType.WNES:
            return(PrefabBuildingBlock_WNES);

        case BuildingBlockType.WE:
            return(PrefabBuildingBlock_WE);

        case BuildingBlockType.NS:
            return(PrefabBuildingBlock_NS);

        case BuildingBlockType.WN:
            return(PrefabBuildingBlock_WN);

        case BuildingBlockType.NE:
            return(PrefabBuildingBlock_NE);

        case BuildingBlockType.ES:
            return(PrefabBuildingBlock_ES);

        case BuildingBlockType.WS:
            return(PrefabBuildingBlock_WS);

        case BuildingBlockType.WNE:
            return(PrefabBuildingBlock_WNE);

        case BuildingBlockType.WES:
            return(PrefabBuildingBlock_WES);

        case BuildingBlockType.NES:
            return(PrefabBuildingBlock_NES);

        case BuildingBlockType.WNS:
            return(PrefabBuildingBlock_WNS);

        case BuildingBlockType.Wx:
            return(PrefabBuildingBlock_Wx);

        case BuildingBlockType.Nx:
            return(PrefabBuildingBlock_Nx);

        case BuildingBlockType.Ex:
            return(PrefabBuildingBlock_Ex);

        case BuildingBlockType.Sx:
            return(PrefabBuildingBlock_Sx);

        default:
            return(PrefabBuildingBlock_Empty);
        }
    }
    ArrayList GetListOfAllBuildingBlockTypes()
    {
        ArrayList returnList = new ArrayList();

        foreach (BuildingBlockType value in BuildingBlockType.GetValues(typeof(BuildingBlockType)))
        {
            returnList.Add(value);
        }
        return(returnList);
    }
        string IRate.AddMultiCurve(string idCode, double RefDate, object DfTenor, object DfRates, string DfType,
                                   object FwdTenor, object FwdRates, string FwdType, string FixingTenor, double FixingValue)
        {
            #region Market Rates for discounting
            RateSet dfMktRates = new RateSet(new Date(RefDate));

            double[]          dfRates    = (double[])DfRates;
            string[]          dfTenor    = (string[])DfTenor;
            int               MaxDfRates = dfTenor.Count();
            BuildingBlockType dfType     = (BuildingBlockType)Enum.Parse(typeof(BuildingBlockType), DfType);
            for (int i = 0; i < MaxDfRates; i++)
            {
                dfMktRates.Add(dfRates[i], dfTenor[i], dfType);
            }
            #endregion

            #region Market Rates for forwarding
            RateSet           fwdMktRates = new RateSet(new Date(RefDate));
            double[]          fwdRates    = (double[])FwdRates;
            string[]          fwdTenor    = (string[])FwdTenor;
            int               MaxFwdRates = fwdTenor.Count();
            BuildingBlockType fwdType     = (BuildingBlockType)Enum.Parse(typeof(BuildingBlockType), FwdType);
            fwdMktRates.Add(FixingValue, FixingTenor, BuildingBlockType.EURDEPO);
            for (int i = 0; i < MaxFwdRates; i++)
            {
                fwdMktRates.Add(fwdRates[i], fwdTenor[i], fwdType);
            }
            #endregion

            #region InizializeMyCurve
            SingleCurveBuilderStandard <OnDf, LinearInterpolator> DCurve     = new SingleCurveBuilderStandard <OnDf, LinearInterpolator>(dfMktRates, OneDimensionInterpolation.Linear);
            MultiCurveBuilder <SimpleCubicInterpolator>           MultiCurve = new MultiCurveBuilder <SimpleCubicInterpolator>(fwdMktRates, DCurve);

            #endregion

            #region UpDating Dictionary
            try
            {
                if (MCDictionary.ContainsKey(idCode) == true) // check if idCode is in dictionary
                {
                    MCDictionary[idCode] = MultiCurve;        // if true, updates it
                }
                else
                {
                    MCDictionary.Add(idCode, MultiCurve);      // if false, adds it
                }
                return("Loaded @ " + DateTime.Now.ToString()); // return time of last load
            }
            catch (Exception e)
            {
                return((string)e.ToString());
            }
            #endregion
        }
Exemple #9
0
 void Awake()
 {
     if (instance != null && instance != this)
     {
         Destroy(this.gameObject);
         return;
     }
     instance = this;
     DontDestroyOnLoad(this.gameObject);
     for (int i = 0; i < allBuildingBlockTypes.Length; i++)
     {
         BuildingBlockType bbt           = allBuildingBlockTypes[i];
         BuildingBlock     buildingBlock = new BuildingBlock(i, bbt.blockName, bbt.prefab);
         buildingBlockDictionary.Insert(i, buildingBlock);
         Debug.Log("Block added to dictionary " + buildingBlockDictionary[i].blockName);
     }
 }
Exemple #10
0
    public RateSet mktRateSet;                  // market starting data

    // constructor: RateSet rateSet are market data inputs
    public SingleCurveBuilder(RateSet rateSet)
    {
        // RefDate
        refDate            = rateSet.refDate;
        PostProcessInterpo = new Interpolation(); // Post process interpolator
        interpAdapter      = new DoInterpOn();
        mktRateSet         = rateSet;

        // Create Building block
        IEnumerable <BuildingBlock> BB = rateSet.GetArrayOfBB();

        // Sort ascending end date
        BBArray = from c in BB
                  orderby c.endDate.SerialValue ascending
                  select c;

        // Only Given Swap from BBArray
        OnlyGivenSwap = (from c in BBArray
                         where c.GetType().BaseType == typeof(SwapStyle)
                         select(SwapStyle) c).ToArray();

        // some data validation: swap should be all of same building block
        // the type of building block
        BuildingBlockType BBT = OnlyGivenSwap[0].buildingBlockType;

        // Are all them the same?
        bool IsSameSwapType = OnlyGivenSwap.All(s => s.buildingBlockType == BBT);

        if (IsSameSwapType)  // if true
        {
            // it is swap type used as inputs (i.e. EurSwapVs6m, EurSwapVs3m, ...)
            SwapType = (SwapStyle) new BuildingBlockFactory().CreateEmptyBuildingBlock(BBT);
        }
        else
        {
            throw new ArgumentException("error in building blocktype"); // if not throw an exception
        }
    }
Exemple #11
0
    // According to BuildingBlockType will create an empty building block (so no rate, no tenor, no ref date).
    // Empty building block is used to have info stored in Load Specifications()
    public BuildingBlock CreateEmptyBuildingBlock(BuildingBlockType myBuildingBlockType)
    {
        if (myBuildingBlockType == BuildingBlockType.EURZERORATE)
        {
            return(new EurZeroRate());
        }

        else if (myBuildingBlockType == BuildingBlockType.EURDEPO)
        {
            return(new EurDepo());
        }

        else if (myBuildingBlockType == BuildingBlockType.EURSWAP6M)
        {
            return(new EurSwapVs6m());
        }

        else if (myBuildingBlockType == BuildingBlockType.EURSWAP3M)
        {
            return(new EurSwapVs3m());
        }

        else if (myBuildingBlockType == BuildingBlockType.EURBASIS6M3M)
        {
            return(new EurSwap6mVs3m());
        }

        else if (myBuildingBlockType == BuildingBlockType.EONIASWAP)
        {
            return(new EoniaSwap());
        }
        else
        {
            return(null);
        }
    }
    Transform GetPrefabFromBuildingBlockType(BuildingBlockType bbType)
    {
        switch (bbType)
        {
            case BuildingBlockType.Empty:
                return PrefabBuildingBlock_Empty;
            case BuildingBlockType.WNES:
                return PrefabBuildingBlock_WNES;
            case BuildingBlockType.WE:
                return PrefabBuildingBlock_WE;
            case BuildingBlockType.NS:
                return PrefabBuildingBlock_NS;
            case BuildingBlockType.WN:
                return PrefabBuildingBlock_WN;
            case BuildingBlockType.NE:
                return PrefabBuildingBlock_NE;
            case BuildingBlockType.ES:
                return PrefabBuildingBlock_ES;
            case BuildingBlockType.WS:
                return PrefabBuildingBlock_WS;
            case BuildingBlockType.WNE:
                return PrefabBuildingBlock_WNE;
            case BuildingBlockType.WES:
                return PrefabBuildingBlock_WES;
            case BuildingBlockType.NES:
                return PrefabBuildingBlock_NES;
            case BuildingBlockType.WNS:
                return PrefabBuildingBlock_WNS;
            case BuildingBlockType.Wx:
                return PrefabBuildingBlock_Wx;
            case BuildingBlockType.Nx:
                return PrefabBuildingBlock_Nx;
            case BuildingBlockType.Ex:
                return PrefabBuildingBlock_Ex;
            case BuildingBlockType.Sx:
                return PrefabBuildingBlock_Sx;

            default:
                return PrefabBuildingBlock_Empty;
        }
    }
 public BuildingBlock(BuildingBlockType buildingBlockType, ILocation location)
 {
     Location          = location;
     BuildingBlockType = buildingBlockType;
 }
Exemple #14
0
 public BuildingBlockData(Vector3 _pos, BuildingBlockType type, Quaternion _rot = new Quaternion())
 {
     pos       = _pos;
     blockType = type;
     rot       = _rot;
 }
Exemple #15
0
 public void Initialize(Vector3 pos, BuildingBlockType type)
 {
     transform.position = pos;
     blockType          = type;
 }
Exemple #16
0
 private IBuildingBlockIdentifier GetBuildingBlockIdentifier(IMazeSchema mazeSchema, BuildingBlockType buildingBlockType)
 {
     return((from x in mazeSchema.GetBuildingBlockDefinations()
             where x.GetBuildingBlockType() == buildingBlockType
             select x).FirstOrDefault());
 }
Exemple #17
0
        public BuildingBlock CreateBuildingBlock(Date refDate, double rateValue, string tenor, BuildingBlockType type)
        {
            switch (type)
            {
            case BuildingBlockType.EURZERORATE:
                return(new EurZeroRate(refDate, rateValue, tenor));

            case BuildingBlockType.EURDEPO:

                break;

            case BuildingBlockType.EURSWAP3M:

                break;

            case BuildingBlockType.EURSWAP6M:

                break;

            case BuildingBlockType.EONIASWAP:

                break;

            case BuildingBlockType.EURBASIS6M3M:
                break;

            default:
                return(null);
            }
            return(null);
        }
Exemple #18
0
 public BuildingBlock CreateEmptyBuildingBlock(BuildingBlockType type)
 {
     return(null);
 }
Exemple #19
0
 // Set type
 public void SetType(BuildingBlockType Type)
 {
     this.T = Type;
 }
Exemple #20
0
    }                                                   // Copy Constructor

    // Constructor needs value or rate, tenor of rate as string and building block type
    public RateSet(double Value, string Maturity, BuildingBlockType Type)
        : this(Value, new Period(Maturity), Type)
    {
    }
Exemple #21
0
 // Constructor needs value or rate, tenor of rate as period and building block type
 public RateSet(double Value, Period Maturity, BuildingBlockType Type)
 {
     this.M = Maturity;
     this.V = Value;
     this.T = Type;
 }
Exemple #22
0
    // According to BuildingBlockType will crate the right BuildingBlock
    public BuildingBlock CreateBuildingBlock(Date RefDate, double rateValue, string TenorString, BuildingBlockType myBuildingBlockType)
    {
        if (myBuildingBlockType == BuildingBlockType.EURZERORATE)
        {
            return(new EurZeroRate(RefDate, rateValue, TenorString));
        }

        else if (myBuildingBlockType == BuildingBlockType.EURDEPO)
        {
            return(new EurDepo(RefDate, rateValue, TenorString));
        }

        else if (myBuildingBlockType == BuildingBlockType.EURSWAP6M)
        {
            return(new EurSwapVs6m(RefDate, rateValue, TenorString));
        }

        else if (myBuildingBlockType == BuildingBlockType.EURSWAP3M)
        {
            return(new EurSwapVs3m(RefDate, rateValue, TenorString));
        }

        else if (myBuildingBlockType == BuildingBlockType.EURBASIS6M3M)
        {
            return(new EurSwap6mVs3m(RefDate, rateValue, TenorString));
        }

        else if (myBuildingBlockType == BuildingBlockType.EONIASWAP)
        {
            return(new EoniaSwap(RefDate, rateValue, TenorString));
        }
        else
        {
            return(null);
        }
    }
 public BuildingBlockIdentifier(BuildingBlockType buildingBlockType, string defination)
 {
     Defination        = defination;
     BuildingBlockType = buildingBlockType;
 }
 public virtual IBuildingBlockIdentifier CreateBuildingBlockIdentifier(BuildingBlockType buildingBlockType, string defination)
 {
     return(new BuildingBlockIdentifier(buildingBlockType, defination));
 }