<<"timeseri\\datasmoo.m"
<<"timeseri\\timeseri.m"
<<"timeseri\\userfunc.m"
<<"LinearRegression`"
<<"NonlinearRegression`"
Needs["NonlinearRegression`"]

(*nacitanie dat*)
SetDirectory[NotebookDirectory[]];
data=ReadList["PLN.txt",Expression];

n=Length[data]

(*vykreslenie casoveho radu*)
SetOptions[ListPlot,PlotRange->All,BaseStyle->{10,FontFamily->"Arial"},Joined->True];
popis=Table[{6+i*12,1998+i*1},{i,0,10}];
ListPlot[data,PlotLabel->"priemerny kurz euro/pln",AxesLabel->{"time[month]","priemerny kurz"},Ticks->{popis,Automatic},Joined->True,AxesOrigin->{0,0}]

Print["Vyberova stredna hodnota: ",Mean[data]];
Print["Vyberova smerodajna odchylka: ",StandardDeviation[data]];
Print["Vyberovy rozptyl: ",Variance[data]];

(*skusobna vzorka*)
sv=Drop[data,n-5]

(*testovacia vzorka*)
tv=Drop[data,-5];

(*vykreslenie testovacej a skusobnej vzorky*)

grafsv=ListPlot[sv,PlotLabel->"priemerny kurz euro/pln",AxesLabel->{"time[month]","priemerny kurz"},Joined->True,AxesOrigin->{0,0}]
graftv=ListPlot[tv,PlotLabel->"priemerny kurz euro/pln",AxesLabel->{"time[month]","priemerny kurz"},Joined->True]

(*ulozenie tv,sk a grafov + vypocitanie ich strednej hodnoty,..*)
Save["skusobna vzorka",sv]
Save["testovanica vzorka",tv]
Save["graf sv",grafsv]
Save["graf tv",graftv]

Print["Vyberova stredna hodnota sv: ",Mean[sv]];
Print["Vyberova smerodajna odchylka sv: ",StandardDeviation[sv]];
Print["Vyberovy rozptyl sv: ",Variance[sv]];
Print["Vyberova stredna hodnota tv: ",Mean[tv]];
Print["Vyberova smerodajna odchylka tv: ",StandardDeviation[tv]];
Print["Vyberovy rozptyl tv: ",Variance[tv]];

(*ACF a PACF*)
corrx=CorrelationFunction[tv,114];
myplotcorr1[corrx,2/Sqrt[n],AxesLabel->{k,(Subscript[ρ, k])},PlotLabel->"Autocorrelation Function"]

parcorrx=PartialCorrelationFunction[tv,114];
myplotcorr1[parcorrx,2/Sqrt[n],AxesLabel->{k,(Subscript[ρ, k])},PlotLabel->" Partial Autocorrelation Function"]

armodels=LevinsonDurbinEstimate[tv,20]

Do[Print["k=",k,"  AIC=",AIC[armodels[[k]],n],"       BIC=" ,BIC[armodels[[k]],n],"  ",armodels[[k]][[-1]],"      ",StationaryQ[armodels[[k]]]],{k,1,20}]
Print["Najlepsi model vzhladom na hodnoru BIC je AR(1)"]