USE KURTOSIS AND SKEWNESS

HOW TO USE KURTOSIS AND SKEWNESS

 

KURTOSIS AND SKEWNESS 



package ‘e1071’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in
C:\Users\ADMIN\AppData\Local\Temp\Rtmp48CkwN\downloaded_packages
> library("e1071", lib.loc="~/R/win-library/3.6")

Attaching package: ‘e1071’

    kurtosis, skewness

Warning message:
package ‘e1071’ was built under R version 3.6.3 
> x <- rnorm(100)
> kurtosis(x)
[1] -0.09225218
> x <- rnorm(100)
> skewness(x)
[1] 0.2068412
> sigmoid(x)
  [1] 0.7924609 0.6012173 0.4015700
  [4] 0.1168985 0.5446880 0.4903706
  [7] 0.7195269 0.7096943 0.6016002
 [10] 0.2019729 0.3525087 0.5408626
 [13] 0.4601341 0.2470393 0.3445243
 [16] 0.6738519 0.6390173 0.5017720
 [19] 0.3256660 0.3072329 0.5314812
 [22] 0.6289924 0.8502339 0.4765683
 [25] 0.5006393 0.3940206 0.6075869
 [28] 0.4465308 0.8705377 0.6635064
 [31] 0.7139986 0.7578363 0.5363243
 [34] 0.3642131 0.6399949 0.2983353
 [37] 0.2082072 0.6549224 0.4033734
 [40] 0.4480780 0.2010318 0.5400087
 [43] 0.7412638 0.4817815 0.3450085
 [46] 0.7708486 0.6844388 0.2889012
 [49] 0.6963281 0.5850107 0.7936972
 [52] 0.6423643 0.6100179 0.9271042
 [55] 0.9262851 0.3325886 0.3185873
 [58] 0.5040252 0.3851227 0.6991765
 [61] 0.7593792 0.7302417 0.6990238
 [64] 0.8273355 0.1847269 0.5340112
 [67] 0.2264907 0.3353517 0.9484346
 [70] 0.8229770 0.4842939 0.4178209
 [73] 0.2967966 0.5143271 0.3565440
 [76] 0.3225993 0.5873630 0.2234188
 [79] 0.8293041 0.3681796 0.8147751
 [82] 0.2231620 0.7632167 0.4017692
 [85] 0.4799441 0.6182596 0.5266224
 [88] 0.5912255 0.8460056 0.1184548
 [91] 0.6034997 0.6074844 0.6780144
 [94] 0.4481176 0.7328068 0.6624322
 [97] 0.6486271 0.3152354 0.4292004
[100] 0.8286585
> dsigmoid(x)
  [1] 0.16446660 0.23975505 0.24031154
  [4] 0.10323324 0.24800298 0.24990727
  [7] 0.20180793 0.20602831 0.23967741
 [10] 0.16117983 0.22824631 0.24833025
 [13] 0.24841071 0.18601089 0.22582730
 [16] 0.21977550 0.23067419 0.24999686
 [19] 0.21960765 0.21284085 0.24900893
 [22] 0.23336097 0.12733620 0.24945095
 [25] 0.24999959 0.23876837 0.23842506
 [28] 0.24714104 0.11270181 0.22326567
 [31] 0.20420462 0.18352043 0.24868054
 [34] 0.23156192 0.23040143 0.20933134
 [37] 0.16485699 0.22599906 0.24066330
 [40] 0.24730411 0.16061803 0.24839930
 [43] 0.19179176 0.24966809 0.22597763
 [46] 0.17664105 0.21598233 0.20543730
 [49] 0.21145526 0.24277318 0.16374195
 [52] 0.22973240 0.23789606 0.06758202
 [55] 0.06828103 0.22197343 0.21708943
 [58] 0.24998380 0.23680320 0.21032871
 [61] 0.18272245 0.19698874 0.21038951
 [64] 0.14285149 0.15060289 0.24884324
 [67] 0.17519267 0.22289095 0.04890642
 [70] 0.14568584 0.24975332 0.24324659
 [73] 0.20870840 0.24979474 0.22942037
 [76] 0.21852898 0.24236770 0.17350285
 [79] 0.14155880 0.23262337 0.15091666
 [82] 0.17336070 0.18071697 0.24035071
 [85] 0.24959776 0.23601467 0.24929125
 [88] 0.24167791 0.13028010 0.10442327
 [91] 0.23928782 0.23844711 0.21831089
 [94] 0.24730821 0.19580098 0.22361579
 [97] 0.22790998 0.21586205 0.24498742
[100] 0.14198362
> d2sigmoid(x)
  [1] -0.0962001121 -0.0485347410
  [3]  0.0473077111  0.0790976167
  [5] -0.0221655221  0.0048129378
  [7] -0.0886045466 -0.0864059134
  [9] -0.0487025268  0.0960719243
 [11]  0.0673287026 -0.0202948456
 [13]  0.0198062388  0.0941068862
 [15]  0.0702213253 -0.0764167954
 [17] -0.0641354039 -0.0008859772
 [19]  0.0765701691  0.0820574196
 [21] -0.0156782067 -0.0602035621
 [23] -0.0891949150  0.0116901260
 [25] -0.0003196607  0.0506090505
 [27] -0.0513028320  0.0264288900
 [29] -0.0835205388 -0.0730107132
 [31] -0.0873989881 -0.0946364661
 [33] -0.0180663040  0.0628861539
 [35] -0.0645100404  0.0844294905
 [37]  0.0962081495 -0.0700246146
 [39]  0.0465089613  0.0256810513
 [41]  0.0960393588 -0.0198762770
 [43] -0.0925448333  0.0090971429
 [45]  0.0700492322 -0.0956859528
 [47] -0.0796710462  0.0867351325
 [49] -0.0830292377 -0.0412766260
 [51] -0.0961811072 -0.0654113974
 [53] -0.0523456462 -0.0577291270
 [55] -0.0582143683  0.0743217566
 [57]  0.0787655589 -0.0020124786
 [59]  0.0544066307 -0.0837850845
 [61] -0.0947887922 -0.0907100610
 [63] -0.0837450567 -0.0935207186
 [65]  0.0949620716 -0.0169268988
 [67]  0.0958336440  0.0733972126
 [69] -0.0438626631 -0.0941063585
 [71]  0.0078452920  0.0399795769
 [73]  0.0848204933 -0.0071576502
 [75]  0.0658234717  0.0775344030
 [77] -0.0423479494  0.0959752468
 [79] -0.0932317896  0.0613290307
 [81] -0.0950096028  0.0959856723
 [83] -0.0951354489  0.0472196933
 [85]  0.0100117943 -0.0558219940
 [87] -0.0132734716 -0.0440943718
 [89] -0.0901552964  0.0796843926
 [91] -0.0495324249 -0.0512586801
 [93] -0.0777249452  0.0256619068
 [95] -0.0911676106 -0.0726447915
 [97] -0.0677472046  0.0797673218
 [99]  0.0346900170 -0.0933282339
> plot(sigmoid, -5, 5, ylim = c(-.2, 1))
> plot(dsigmoid, -5, 5, add = TRUE, col = 2)
> plot(d2sigmoid, -5, 5, add = TRUE, col = 3)
> tckr = c('SPY')
> end<- format(Sys.Date(),"%Y-%m-%d")
> start<-format(Sys.Date() - 365*20,"%Y-%m-%d")
> dat1 = (getSymbols(tckr[1], src="yahoo", from=start, to=end, auto.assign = FALSE))
‘getSymbols’ currently uses auto.assign=TRUE by default, but will
use auto.assign=FALSE in 0.5-0. You will still be able to use
‘loadSymbols’ to automatically load data. getOption("getSymbols.env")
and getOption("getSymbols.auto.assign") will still be checked for
alternate defaults.

This message is shown once per session and may be disabled by setting 
options("getSymbols.warning4.0"=FALSE). See ?getSymbols for details.

> ret1 = as.numeric((dat1[,4] - dat1[,1])/dat1[,1] )
> n = length(as.numeric(ret1))
> time0 = index(dat1)
> head(time0) ; tail(time0)
[1] "2000-04-18" "2000-04-19" "2000-04-20"
[4] "2000-04-24" "2000-04-25" "2000-04-26"
[1] "2020-04-02" "2020-04-03" "2020-04-06"
[4] "2020-04-07" "2020-04-08" "2020-04-09"
> s = seq(1,n,22)
> k = NULL
> for (i in 1:(length(s)-1)){
+     k[i] = 3+kurtosis(ret1[s[i]:s[(i+1)]])
+ }
> time0[s[which(k>quantile(k,.95))]]
 [1] "2005-12-27" "2007-02-16" "2009-10-30"
 [4] "2011-01-21" "2012-06-14" "2012-12-24"
 [7] "2013-01-28" "2017-05-09" "2017-07-12"
[10] "2019-03-12" "2019-08-16" "2020-01-24"
> plot(k~time0[s[1:(length(s)-1)] ], ty = "b", xlab = "Time", ylab = "Monthly Kurtosis", 
+      main = "Monthly Kurtosis over Time")
> abline(a = quantile(k,.90), b = 0, lwd = 2, col = 2)
> abline(a = quantile(k,.95), b = 0, lwd = 2, col = 3)
> abline(a = quantile(k,.99), b = 0, lwd = 2, col = 4)

No comments:

Post a Comment