Exemple #1
0
        protected static Tuple<double[,], double[]> computeCorrelationAndVol(DateTime priceDate, IAsset underlying, ICurrency cur, int date_nb)
        {
            List<DateTime> dates_correl = new List<DateTime>();
            int total = 0, real = 0; // current number of date : total also have not taken dates cause week end
            while (real < date_nb)
            {
                DateTime curr_date = priceDate - TimeSpan.FromDays(total);
                if (!(curr_date.DayOfWeek == DayOfWeek.Saturday || curr_date.DayOfWeek == DayOfWeek.Sunday))
                {
                    dates_correl.Add(curr_date);
                    real++;
                }
                total++;
            }
            // get the prices from database
            Dictionary<DateTime, double> hist_correl = AccessDB.Get_Asset_Price(underlying.getName(), dates_correl);
            // transform the Tuple format to double[,] format
            double[,] hist_correl_double = new double[2, date_nb];
            int j = 0;
            foreach (DateTime d in dates_correl)
            {
                hist_correl_double[0, j] = hist_correl[d];
                j++;
            }
            j = 0;
            foreach (DateTime d in dates_correl)
            {
                hist_correl_double[1, j] = 1 / cur.getChangeToEuro(d);
                j++;
            }

            // compute correl and vol using C++ functions
            Wrapping.Tools tools = new Wrapping.Tools();
            double[,] correl = new double[2, 2];
            double[] vol = new double[2];
            tools.getCorrelAndVol(date_nb, 2, hist_correl_double, correl, vol);
            return new Tuple<double[,], double[]>(correl, vol);
        }
Exemple #2
0
        public double getVolatility(DateTime t)
        {
            Wrapping.Tools tools = new Wrapping.Tools();

            int nb_dates = 15;

            double[,] price = getPriceDouble(t - TimeSpan.FromDays(nb_dates), t, TimeSpan.FromDays(1));

            double[,] correl = new double[1, 1];
            double[] vol = new double[1];
            tools.getCorrelAndVol(nb_dates, 1, price, correl, vol);
            return vol[0];
        }
Exemple #3
0
        /*
        public Tuple<bool, double> getPayoff(DateTime t)
        {
            LinkedList<DateTime> dates = new LinkedList<DateTime>();
            foreach (DateTime d in getObservationDates())
            {

                if (d > t)
                {
                    break;
                }
                dates.AddLast(d);
            }
            double[,] historic = new double[underlying_list.Count, dates.Count];
            int ass_i = 0;
            foreach (IAsset ass in underlying_list)
            {
                int d_i = 0;
                foreach (DateTime d in dates)
                {
                    historic[ass_i, d_i] = ass.getPrice(d);
                    d_i++;
                }
                ass_i++;
            }
            int nb_dates = dates.Count;
            int nb_asset = this.underlying_list.Count;
            wp.getPayoffEverglades(nb_dates, nb_asset, historic, this.VLR);
            return new Tuple<bool, double>(wp.getPayoffIsAnticipated(), wp.getPayoff());
        }
         * */

        private Tuple<double[,], double[]> computeCorrelationAndVol(DateTime priceDate, List<String> assetNames, List<Currencies> currencies, uint date_nb)
        {
            int asset_nb = assetNames.Count;
            int currencies_nb = currencies.Count;
            // create a list of dates to get price for correlation computing
            int nb_dates_correl = 200;
            List<DateTime> dates_correl = new List<DateTime>();
            int total = 0, real = 0; // current number of date : total also have not taken dates cause week end
            while (real < nb_dates_correl)
            {
                DateTime curr_date = priceDate - TimeSpan.FromDays(total);
                if (!(curr_date.DayOfWeek == DayOfWeek.Saturday || curr_date.DayOfWeek == DayOfWeek.Sunday))
                {
                    dates_correl.Add(curr_date);
                    real++;
                }
                total++;
            }
            // get the prices from database
            Dictionary<Tuple<String, DateTime>, double> hist_correl = AccessDB.Get_Asset_Price_Eur(assetNames, dates_correl);
            Dictionary<Currencies, Dictionary<DateTime, double>> hist_correl_cur = AccessBD.Access.GetCurrenciesExchangeWithEuro(currencies, dates_correl);
            // transform the Tuple format to double[,] format
            double[,] hist_correl_double = new double[asset_nb + currencies_nb, nb_dates_correl];
            int k = 0;
            foreach (IAsset ass in underlying_list)
            {
                int j = 0;
                foreach (DateTime d in dates_correl)
                {
                    hist_correl_double[k, j] = hist_correl[new Tuple<String, DateTime>(ass.getName(), d)];
                    j++;
                }
                k++;
            }
            foreach (Currencies cur in currencies)
            {
                int j = 0;
                foreach (DateTime d in dates_correl)
                {
                    hist_correl_double[k, j] = hist_correl_cur[cur][d];
                    j++;
                }
                k++;
            }
            // compute correl and vol using C++ functions
            Wrapping.Tools tools = new Wrapping.Tools();
            double[,] correl = new double[asset_nb + currencies_nb, asset_nb + currencies_nb];
            double[] vol = new double[asset_nb + currencies_nb];
            tools.getCorrelAndVol(nb_dates_correl, asset_nb + currencies_nb, hist_correl_double, correl, vol);
            return new Tuple<double[,], double[]>(correl, vol);
        }