Exemple #1
0
        protected override double[,] ComputeCorrelation(int window, int startingPoint)
        {
            double[,] data = new double[window, Option.UnderlyingShareIds.Length];
            for (int i = 0; i < window; i++)
            {
                for (int j = 0; j < Option.UnderlyingShareIds.Length; j++)
                {
                    data[i, j] = Spots[startingPoint - window + i][j];
                }
            }
            double[,] correlation = WRE.computeCorrelationMatrix(data);

            return(correlation);
        }
        private double[] ComputeVolatility(int window, int deb, int step)
        {//Compute the volatility of all the underlying shares at date deb.
         //Estimate the parameters thanks to the data of the window days before deb.
            var res = new List <double>();

            for (var share = 0; share < Option.UnderlyingShareIds.Length; share++)
            {
                double[,] tab = new double[window - 1, 1];
                for (var k = 1; k < window; k++)
                {
                    tab[k - 1, 0] = Math.Log((double)Spots[deb - window + k][share] / (double)Spots[deb - window + k - 1][share]);
                }
                var B = Math.Sqrt(DayCount.ConvertToDouble(step, 365));
                double[,] myVol = WRE.computeVolatility(tab);
                res.Add(myVol[0, 0] / B);
            }
            return(res.ToArray());
        }
Exemple #3
0
        public void computeCorrelationMatrixTest()
        {
            // header
            Debug.WriteLine("******************************");
            Debug.WriteLine("*    WREmodelingCorr in C#   *");
            Debug.WriteLine("******************************");

            // sample data
            double[,] returns = { { 0.05, 0.05, 0.6 }, { -0.001, -0.001, 0.56 }, { 0.7, 0.7, 0.12 }, { -0.3, -0.3, -0.1 },
                                  {  0.1,  0.1, 0.3 } };

            // call WRE via computeCovarianceMatrix encapsulation
            WRE classWRE = new WRE();

            double[,] myCorrMatrix = WRE.computeCorrelationMatrix(returns);

            // display result
            WRE.dispMatrix(myCorrMatrix);

            // ending the program
            Console.WriteLine("\nType enter to exit");
        }