Beispiel #1
0
        public static object TestSummaryContainer(double[] data)
        {
            object[,] ret = new object[data.Length, 6];
            SummaryContainer sc = new SummaryContainer();

            int i = 0;

            foreach (double d in data)
            {
                sc.Add(d);

                ret[i, 0] = sc.Count;
                ret[i, 1] = sc.Min;
                ret[i, 2] = sc.Max;
                ret[i, 3] = sc.Average;
                ret[i, 4] = sc.Stdev;
                ret[i, 5] = sc.Total;

                i++;
            }

            return(ret);
        }
Beispiel #2
0
        public static object DescribeReturns(object[,] PriceSeries, object HideLabelsOpt, object AnnualisationFactorOpt,
                                             object AnnualRiskFreeRateOpt, object UseBPReturnsOpt, object ExcludeZeroReturnsOpt)
        {
            double[,] priceSeries = Utils.GetMatrix <double>(PriceSeries);
            bool   hideLabels    = Utils.GetOptionalParameter(HideLabelsOpt, false);
            double annFactor     = Utils.GetOptionalParameter(AnnualisationFactorOpt, 1.0);
            double riskFreeRate  = Utils.GetOptionalParameter(AnnualRiskFreeRateOpt, 0.0);
            bool   useBPReturns  = Utils.GetOptionalParameter(UseBPReturnsOpt, false);
            bool   excludeZeroes = Utils.GetOptionalParameter(ExcludeZeroReturnsOpt, false);

            if (priceSeries.Length == 0)
            {
                return("No data!");
            }

            int nAssets = priceSeries.GetLength(1), nDates = priceSeries.GetLength(0);

            object[,] ret = new object[10, nAssets + (hideLabels ? 0 : 1)];
            for (int a = 0; a < nAssets; ++a)
            {
                double                maxLevel = priceSeries[0, a], maxDD = 1e10;
                SummaryContainer      sc = new SummaryContainer();
                DistributionContainer dc = new DistributionContainer(1e-7);
                for (int i = 1; i < nDates; ++i)
                {
                    double r = (useBPReturns ? (priceSeries[i, a] - priceSeries[i - 1, a]) / 100 : priceSeries[i, a] / priceSeries[i - 1, a] - 1);
                    if (!excludeZeroes || r != 0)
                    {
                        sc.Add(r);
                        dc.Add(r);
                    }

                    if (priceSeries[i, a] > maxLevel)
                    {
                        maxLevel = priceSeries[i, a];
                    }

                    double dd = (useBPReturns ? (priceSeries[i, a] - maxLevel) / 100 : priceSeries[i, a] / maxLevel - 1);
                    if (dd < maxDD)
                    {
                        maxDD = dd;
                    }
                }

                int dataIndex = a + (hideLabels ? 0 : 1);
                ret[0, dataIndex] = sc.Average * annFactor;
                ret[1, dataIndex] = sc.Stdev * Math.Sqrt(annFactor);
                ret[2, dataIndex] = (ret[0, dataIndex].AsDouble() - riskFreeRate) / ret[1, dataIndex].AsDouble();
                ret[3, dataIndex] = maxLevel / priceSeries[0, a];
                ret[4, dataIndex] = maxDD;
                ret[5, dataIndex] = -maxDD / (sc.Stdev * Math.Sqrt(annFactor));
                ret[6, dataIndex] = (sc.Average * annFactor) / -maxDD;
                ret[7, dataIndex] = priceSeries[nDates - 1, a] / priceSeries[0, a];
                ret[8, dataIndex] = dc.GetValue(0.05);
                ret[9, dataIndex] = dc.GetValue(0.01);
            }

            if (!hideLabels)
            {
                ret[0, 0] = "Average Return";
                ret[1, 0] = "Volatility";
                ret[2, 0] = "Sharpe";
                ret[3, 0] = "High Watermark";
                ret[4, 0] = "Max Drawdown";
                ret[5, 0] = "Max DD / Vol";
                ret[6, 0] = "Avg Ret / Max DD";
                ret[7, 0] = "Final Level";
                ret[8, 0] = "VaR95";
                ret[9, 0] = "VaR99";
            }

            return(ret);
        }