Autocorrelation Periodogram
Alıntı:
Originally Posted by
stradivarius
Orhan hocam bandpass faslinda gonderdiginiz listede "autocorrelation periodogram" yeni sayilir :) cevirirseniz makbule gecer.
Hantal ve pratik de kullanması çok zordur.
Mesa Phasor'un çevrimini buraya atsaydım daha iyi anlaşılırdı aslında :)
Autocorrelation Periodogram
The Autocorrelation Periodogram was published in the September 2016 Stocks and Commodities article titled Measuring Market Cycles by John F. Ehlers.
PHP Code:
//Autocorrelation Periodogram
//Ayarlar
int HPeriod =48; //High-pass Period
//Veriler
var V = Sistem.GrafikVerileri ;
var C = Sistem.GrafikFiyatOku(V, "Kapanis") ;
var H = Sistem.GrafikFiyatOku(V, "Yuksek") ;
var L = Sistem.GrafikFiyatOku(V, "Dusuk") ;
var O = Sistem.GrafikFiyatOku(V, "Acilis") ;
//Değişkenler
var DominantCycle= Sistem.Liste(0);
List<double> HP= new List<double>(new double[C.Count]);
List<double> Filt= new List<double>(new double[C.Count]);
int AvgLength= 3;
int M= 0;
int N= 0;
double X= 0;
double Y= 0;
double alpha1= 0;
double a1= 0;
double b1= 0;
double c1= 0;
double c2= 0;
double c3= 0;
int Lag= 0;
int count= 0;
double Sx= 0;
double Sy= 0;
double Sxx= 0;
double Syy= 0;
double Sxy= 0;
int Period= 0;
double Sp= 0;
double Spx= 0;
double MaxPwr= 0;
double PeakPwr= 0;
int Color1= 0;
int Color2= 0;
int Color3= 0;
double[] Corr = new double[700];
double[] CosinePart = new double[700];
double[] SinePart = new double[700];
double[] SqSum = new double[700];
double[,] R = new double[700,3];
double[] Pwr = new double[700];
//Hesaplamalar
for (int i = 100; i < C.Count; i++)
{
DominantCycle[i] = 0;
PeakPwr = 0;
Spx = 0;
Sp = 0;
HP[i] = Math.Round(0.94*(C[i] - C[i-1]) + 0.88*HP[i-1], 2);
Filt[i] = Math.Round(0.35*(HP[i] + HP[i-1]) / 2 + 0.98*Filt[i-1] + -0.33*Filt[i-2], 2);
for (Lag = 0; Lag <= HPeriod ; Lag++)
{
M = AvgLength != 0 ? AvgLength : Lag;
Sx = 0; Sy = 0; Sxx = 0; Syy = 0; Sxy = 0;
for (count = 0; count < M; count++)
{
X = Filt[i-count];
Y = Filt[i-Lag - count];
Sx = Sx + X;
Sy = Sy + Y;
Sxx = Sxx + X*X;
Sxy = Sxy + X*Y;
Syy = Syy + Y*Y;
}
if ((M*Sxx - Sx*Sx)*(M*Syy - Sy*Sy) > 0)
{
Corr[Lag] = Math.Round((M*Sxy - Sx*Sy)/Math.Sqrt((M*Sxx - Sx*Sx)*(M*Syy - Sy*Sy)), 2);
}
}
for (Period = 8; Period <= HPeriod ; Period++)
{
CosinePart[Period] = 0;
SinePart[Period] = 0;
for (N = 3; N <= HPeriod ; N++)
{
CosinePart[Period] = Math.Round(CosinePart[Period] + Corr[N]*Math.Cos(((360*N / Period) * Math.PI) / 180), 2);
SinePart[Period] = Math.Round(SinePart[Period] + Corr[N]*Math.Sin(((360*N / Period) * Math.PI) / 180), 2);
}
SqSum[Period] = Math.Round(CosinePart[Period]*CosinePart[Period] + SinePart[Period]*SinePart[Period], 2);
}
for (Period = 7; Period < HPeriod ; Period++)
{
R[Period, 1] = R[Period, 0];
R[Period, 0] = Math.Round(0.2*SqSum[Period]*SqSum[Period] + .8*R[Period, 1], 2);
}
MaxPwr = 0;
for (Period = 7; Period < HPeriod ; Period++)
{
if (R[Period, 0] > MaxPwr)
MaxPwr = R[Period, 0];
}
for (Period = 7; Period < HPeriod ; Period++)
{
Pwr[Period] = R[Period, 0] / MaxPwr;
}
if (false)
{
for (Period = 8; Period < HPeriod ; Period++)
{
Pwr[Period] = Math.Pow(Pwr[Period], 3);
}
}
for (Period = 7; Period < HPeriod ; Period++)
{
if (Pwr[Period] > PeakPwr)
PeakPwr = Pwr[Period];
}
for (Period = 7; Period < HPeriod ; Period++)
{
if (PeakPwr >= 0.25 && Pwr[Period] >= 0.25)
{
Spx = Spx + Period*Pwr[Period];
Sp = Sp + Pwr[Period];
}
}
if (Sp != 0)
DominantCycle[i] = (float)( Spx / Sp);
if (Sp < 0.25)
DominantCycle[i] = (float)(DominantCycle[i-1]);
}
//Çizgiler
Sistem.Cizgiler[0].Deger = DominantCycle;
https://image.prntscr.com/image/9jzv...bCSQi1EUMg.png
https://prnt.sc/lpuezc