Example #1
0
        public static string[] GetDatesWithinTime(string[] _dates, int _days)
        {
            List <string> _datesWithinTime = new List <string>();

            int[] _daysUntilPayments = new int[_dates.Length];              //array to store days until dividend payment

            //loops through all dividends and gets the days until the payment
            for (int i = 0; i < _daysUntilPayments.Length; i++)
            {
                _daysUntilPayments[i] = DateHandling.DaysUntil(_dates[i]);
            }

            for (int i = 0; i < _daysUntilPayments.Length; i++)
            {
                if (_daysUntilPayments[i] <= _days)
                {
                    _datesWithinTime.Add(_dates[i]);
                }
            }

            return(_datesWithinTime.ToArray());
        }
Example #2
0
        //calculates indivdual forward price
        private static float GetForwardPrice(StockInformation _stock, float dividend, int days, float riskFreeRate)
        {
            //initial
            double _forward = _stock.price * Math.Exp(riskFreeRate / 100 * days);

            int[] _daysUntilPayments = new int[_stock.dates.Length];              //array to store days until dividend payment

            //loops through all dividends and gets the days until the payment
            for (int i = 0; i < _daysUntilPayments.Length; i++)
            {
                _daysUntilPayments[i] = DateHandling.DaysUntil(_stock.dates[i]);
            }

            //loops through checking if dividend will be paid within time, if so it takes payment off price
            for (int i = 0; i < _daysUntilPayments.Length; i++)
            {
                if (_daysUntilPayments[i] < days)
                {
                    _forward -= dividend * Math.Exp(riskFreeRate * (days - _daysUntilPayments[i]));
                }
            }

            return((float)_forward);
        }