我试图建立一个类来创建Aroon系列。但似乎我不明白这些步骤。我不确定我必须使用period参数的目的。计算Aroon指标系列
这是我第一次尝试:
/// <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;
}
}
是否有其他人想这样做之前?
下面是CSV文件我用:
https://drive.google.com/file/d/0Bwv_-8Q17wGaRDVCa2FhMWlyRUk/view
但结果集阿隆上下不阿隆功能的TTR包的结果R.
table <- read.csv("table.csv", header = TRUE, sep = ",")
trend <- aroon(table[,c("High", "Low")], n=5)
View(trend)
匹配
截图ř结果:
在此先感谢,
扩大你的问题,以添加你正在遇到的问题。你给了什么投入?你的预期产出是什么?你的实际产出是多少? –
@SteveMitcham我已经更新了我的问题。 – anilca
你的结果与R结果有什么不同?我不是这里的专家,但你提供的信息越多,就越有可能有人能够明白为什么会有差异。 –