Exemplo n.º 1
0
 void Init()
 {
     Instance       = this;
     this.BackColor = Colours.background;
     regions        = FileHandling.LoadRegions();      //loading regions
     interestRegion = regions[0];
 }
Exemplo n.º 2
0
        ///interpolates to find an interest rate for the specified
        private static float GetIntrestRate(InterestRegion region, int days)
        {
            if (region.bonds == null)
            {
                return(-1);
            }
            Bond _lower = GetNearestBond(region.bonds, days, "down");
            Bond _upper = GetNearestBond(region.bonds, days, "up");

            return(Interpolate(_lower.duration, _upper.duration, _lower.interestRate, _upper.interestRate, days));
        }
        //////////////////////////////////////////////////////////
        /// deals with loading bonds

        public static InterestRegion[] LoadRegions()
        {
            //reading all text in the file and splitting into regions
            string[] _dirtyBonds = File.ReadAllText("InterestRegions.txt").Split('|');
            //array to store regions being read from file
            InterestRegion[] _regions = new InterestRegion[_dirtyBonds.Length];

            //loops through saving every region
            for (int i = 0; i < _regions.Length; i++)
            {
                _regions[i] = new InterestRegion();
                string[] _parts = _dirtyBonds[i].Split(':');
                _regions[i].name  = _parts[0];                   //setting name of region
                _regions[i].bonds = new Bond[_parts.Length - 1]; //setting lengt of array
                //loop going through and saving each bond
                for (int j = 1; j < _parts.Length; j++)
                {
                    string[] _working = _parts[j].Split(',');                     //current bond
                    _regions[i].bonds[j - 1] = new Bond(Convert.ToInt32(_working[1]), (float)Convert.ToDecimal(_working[0]));
                }
            }
            return(_regions);
        }
Exemplo n.º 4
0
        ///calculates forward price bounds given price, dividend predictions, time until maturity and interest region
        public static float[] GetForwardPrices(StockInformation _stock, float[] _dividends, int _timeUntilMaturity, InterestRegion _region)
        {
            float[] prices       = new float[3];
            float   riskFreeRate = GetIntrestRate(_region, _timeUntilMaturity);

            for (int i = 0; i < _dividends.Length; i++)
            {
                prices[i] = GetForwardPrice(_stock, _dividends[i], _timeUntilMaturity, riskFreeRate);
            }
            return(prices);
        }