程式
技術分析 - 計算阿隆指標系列
我正在嘗試建立一個類來創建 Aroon 系列。但似乎我不太了解這些步驟。我不確定我必須使用 period 參數的目的是什麼。
這是我的第一次嘗試:
/// <summary> /// Aroon /// </summary> public class Aroon : IndicatorCalculatorBase { public override List<Ohlc> OhlcList { get; set; } public int Period { get; set; } public Aroon(int period) { this.Period = period; } /// <summary> /// Aroon up: {((number of periods) - (number of periods since highest high)) / (number of periods)} x 100 /// Aroon down: {((number of periods) - (number of periods since lowest low)) / (number of periods)} x 100 /// </summary> /// <see cref="http://www.investopedia.com/ask/answers/112814/what-aroon-indicator-formula-and-how-indicator-calculated.asp"/> /// <returns></returns> public override IIndicatorSerie Calculate() { AroonSerie aroonSerie = new AroonSerie(); int indexToProcess = 0; while (indexToProcess < this.OhlcList.Count) { List<Ohlc> tempOhlc = this.OhlcList.Skip(indexToProcess).Take(Period).ToList(); indexToProcess += tempOhlc.Count; for (int i = 0; i < tempOhlc.Count; i++) { int highestHighIndex = 0, lowestLowIndex = 0; double highestHigh = tempOhlc.Min(x => x.High), lowestLow = tempOhlc.Max(x => x.Low); for (int j = 0; j < i; j++) { if (tempOhlc[j].High > highestHigh) { highestHighIndex = j; highestHigh = tempOhlc[j].High; } if (tempOhlc[j].Low < lowestLow) { lowestLowIndex = j; lowestLow = tempOhlc[j].Low; } } int up = ((this.Period - (i - highestHighIndex)) / this.Period) * 100; aroonSerie.Up.Add(up); int down = ((this.Period - (i - lowestLowIndex)) / this.Period) * 100; aroonSerie.Down.Add(down); } } return aroonSerie; } }
以前有沒有其他人嘗試過這樣做?以下是有關該指標的一些參考點:
我在SO中回答了@Anilca 的問題(答案被接受)
我用工作解決方案總結了我的答案:
public class Aroon : IndicatorCalculatorBase { public override List<OhlcSample> OhlcList { get; set; } private readonly int _period; public int Period { get { return _period; } } public Aroon(int period) { _period = period; } public override IIndicatorSerie Calculate() { var aroonSerie = new AroonSerie(); for (var i = _period; i < OhlcList.Count; i++) { var aroonUp = CalculateAroonUp(i); var aroonDown = CalculateAroonDown(i); aroonSerie.Down.Add(aroonDown); aroonSerie.Up.Add(aroonUp); } return aroonSerie; } private double CalculateAroonUp(int i) { var maxIndex = FindMax(i - _period, i); var up = CalcAroon(i - maxIndex); return up; } private double CalculateAroonDown(int i) { var minIndex = FindMin(i - _period, i); var down = CalcAroon(i - minIndex); return down; } private double CalcAroon(int numOfDays) { var result = ((_period - numOfDays)) * ((double)100 / _period); return result; } private int FindMin(int startIndex, int endIndex) { var min = double.MaxValue; var index = startIndex; for (var i = startIndex; i <= endIndex; i++) { if (min < OhlcList[i].Low) continue; min = OhlcList[i].Low; index = i; } return index; } private int FindMax(int startIndex, int endIndex) { var max = double.MinValue; var index = startIndex; for (var i = startIndex; i <= endIndex; i++) { if (max > OhlcList[i].High) continue; max = OhlcList[i].High; index = i; } return index; } }
附言
伙計們,我通常活躍在 SO ……如果有人需要澄清,請在源問題中提問(並隨時這樣做)