/// <summary> /// Berechnet die Kovrianz und legt das Ergebnis in einem neuen Datencontainer ab. /// </summary> /// /// <param name="a">Datenreihe A</param> /// <param name="b">Datenreihe B</param> /// <param name="nRange">Anzahl der Daten, von dem die Kovarianz gebildet werden soll</param> /// <returns>Neuer DatenContainer mit n Ergebnisdaten</returns> public static DataContainer CreateFrom(DataContainer a, DataContainer b, int nRange) { if (nRange < 1) { throw new ArgumentOutOfRangeException("Range", nRange, "Must be greater than zero."); } DataContainer avg_a = MovingAverage.CreateFrom(a, nRange); DataContainer avg_b = MovingAverage.CreateFrom(b, nRange); DataContainer result = new DataContainer(); double dSum = 0; WorkDate workdate = a.OldestDate.Clone(); WorkDate historyworkdate = a.OldestDate.Clone(); for (int i = 0; i < nRange - 1; i++, workdate++) { dSum += a[workdate] * b[workdate]; } do { dSum += a[workdate] * b[workdate]; double dTemp = dSum - (nRange * avg_a[workdate] * avg_b[workdate]); result[workdate] = dTemp / (nRange - 1); workdate++; dSum -= a[historyworkdate] * b[historyworkdate]; historyworkdate++; }while (workdate <= a.YoungestDate); return(result); }
/// <summary> /// Berechnet die durchschnittliche Abweichung in dB% vom Durchschnitt. /// </summary> /// <param name="source">Daten, von dem die durchschnittliche Abweichung gebildet werden soll</param> /// <param name="nAverage">Anzahl der Daten, von dem die durchschnittliche Abweichung gebildet werden soll</param> /// <returns>Neuer DatenContainer mit den Ergebnisdaten</returns> public static DataContainer CreateFrom(DataContainer source, int nAverage) { if (nAverage < 1) { throw new ArgumentOutOfRangeException("nAverage", nAverage, "Must be greater than zero."); } DataContainer result = new DataContainer(); DataContainer relperf = RelativePerformance.CreateFrom(source); DataContainer movavg = MovingAverage.CreateFrom(relperf, nAverage); if (movavg.Count >= nAverage) { double dSum = 0; WorkDate workdate = movavg.OldestDate.Clone(); WorkDate historyworkdate = movavg.OldestDate.Clone(); for (int i = 0; i < nAverage - 1; i++, workdate++) { dSum += Math.Abs(relperf[workdate] - movavg[workdate]); } do { dSum += Math.Abs(relperf[workdate] - movavg[workdate]); result[workdate] = dSum / nAverage; workdate++; dSum -= Math.Abs(relperf[historyworkdate] - movavg[historyworkdate]); historyworkdate++; }while (workdate <= source.YoungestDate); } return(result); }
///<summary> /// Berechnet den PriceOscillator und legt das Ergebnis in einem neuen Datencontainer ab. /// </summary> /// <param name="source">Daten, von dem der Indikator gebildet werden soll</param> /// <param name="nAverageFast">Anzahl der Daten, des kuerzeren GD</param> /// <param name="nAverageSlow">Anzahl der Daten, des laengerem GD</param> /// <returns>Neuer DatenContainer mit den Ergebnisdaten</returns> public static DataContainer CreateFrom(DataContainer source, int nAverageFast, int nAverageSlow) { if (nAverageFast > nAverageSlow) { throw(new ArgumentOutOfRangeException()); } DataContainer fast = MovingAverage.CreateFrom(source, nAverageFast); DataContainer slow = MovingAverage.CreateFrom(source, nAverageSlow); DataContainer result = new DataContainer(); for (WorkDate workdate = slow.OldestDate.Clone(); workdate <= slow.YoungestDate; workdate++) { //double dPerf = Math.Log(fast[workdate] / slow[workdate], 2.0) * 100.0; double dPerf = (fast[workdate] / slow[workdate]) - 1.0; result[workdate] = dPerf; } return(result); }
/// <summary> /// Berechnet die ReturnRiskRatio und legt das Ergebnis in einem neuen Datencontainer ab. /// </summary> /// <param name="source">Datensatz, von dem die ReturnRiskRatio gebildet werden soll</param> /// <param name="nRange">Anzahl der einzubeziehenden Daten pro Berechnung</param> /// <returns>Neuer DatenContainer mit den Ergebnisdaten</returns> public static DataContainer CreateFrom(DataContainer source, int nRange) { //DataContainer sourceperf = RelativePerformance.CreateFrom(source); DataContainer sourcechange = RelativeChange.CreateFrom(source); DataContainer changemovavg = MovingAverage.CreateFrom(sourcechange, nRange); DataContainer volatility = Volatility.CreateFrom(sourcechange, nRange); DataContainer result = new DataContainer(); //WorkDate historydate = volatility.OldestDate.Clone() - (int)nRange; WorkDate workdate = volatility.OldestDate.Clone(); for (; workdate <= volatility.YoungestDate; workdate++ /*, historydate++*/) { double dReturn = changemovavg[workdate]; //sourceperf[workdate] - sourceperf[historydate]; double dRisk = volatility[workdate]; // Standardabweichung //result[workdate] = dReturn / (dRisk + 1.0); result[workdate] = dReturn - dRisk; } return(result); }