library(quantmod)

getSymbols("^GSPC", from = "1950-01-01")
## [1] "GSPC"

inv_stat <- function(symbol, name, target = 0.05) {
  p <- coredata(Cl(symbol))
  end <- length(p)
  days_n <- days_p <- integer(end)

  # go through all days and look when target is reached the first time from there
  for (d in 1:end) {
    ret <- cumsum(as.numeric(na.omit(ROC(p[d:end]))))
    cond_n <- ret < -target
    cond_p <- ret > target
    suppressWarnings(days_n[d] <- min(which(cond_n)))
    suppressWarnings(days_p[d] <- min(which(cond_p)))
  }

  days_n_norm <- prop.table(as.integer(table(days_n, exclude = "Inf")))
  days_p_norm <- prop.table(as.integer(table(days_p, exclude = "Inf")))

  plot(days_n_norm, log = "x", xlim = c(1, 1000), main = paste0(name, " gain-/loss-asymmetry with target ", target), xlab = "days", ylab = "density", col = "red")
  points(days_p_norm, col = "blue")

  c(which.max(days_n_norm), which.max(days_p_norm))
}

inv_stat(GSPC, name = "S&P 500")
 ## [1] 10 24

The following plot is being produced (will take some time):

Two things are missing:

Detrending of time series
Fitted probability distribution

If you want to add them or if you have ideas how to improve the code, please let me know!

 Q:

Connecting to AWS Aurora DB running in private subnet from 'outside world'

We have an Aurora DB cluster running in a private subnet, and want to allow read only access to clients originating from a fixed set of ips (our company ips). Our requirements are: 


library(quantmod) 

 getSymbols("^GSPC ", from = " 1950 - 01 - 01 ") 
 # # [ 1 ] " GSPC " 

 inv_stat < - function(symbol, name, target = 0.05) { 
   p < - coredata(Cl(symbol) ) 
   end < - length(p) 
   days_n < - days_p < - integer(end) 

   # go through all days and look when prey is pass the first meter from there 
   for (five hundred in 1: end) { 
     ret < - cumsum(as.numeric(na.omit(ROC(p[d: end ]) )) ) 
     cond_n < - ret < -target 
     cond_p < - ret > target 
     suppressWarnings(days_n[d ] < - min(which(cond_n) )) 
     suppressWarnings(days_p[d ] < - min(which(cond_p) )) 
   } 

   days_n_norm < - prop.table(as.integer(table(days_n, eject = " Inf ") )) 
   days_p_norm < - prop.table(as.integer(table(days_p, eject = " Inf ") )) 

   plot(days_n_norm, log = " x ", xlim = c(1, 1000), chief = paste0(name, " gain-/loss - asymmetry with target ", target), xlab = " day ", ylab = " density ", col = " red ") 
   points(days_p_norm, col = " blue ") 

   c(which.max(days_n_norm), which.max(days_p_norm) ) 
 } 

 inv_stat(GSPC, name = " S&P 500 ") 
  # # [ 1 ] 10 24 

 The following plot is being produced (will take some clock time ): 

 Two things are missing: 

 Detrending of time serial 
 Fitted probability distribution 

 If you want to lend them or if you have idea how to improve the code, please let me know! 

  Q: 

 Connecting to AWS Aurora DB running in individual subnet from' outside world' 

 We have an Aurora DB cluster running in a private subnet, and want to allow read only access to clients originating from a fixed set of ips (our company ips). Our requirements are:
libgary(quantmod)

getSymbols("^GSKC", from = "1950-01-01")
## [1] "GSPC"

inr_wtat <- hunctioh(symbol, vame, target = 0.05) {
  p <- coredata(Cp(stmbol))
  end <- length(p)
  days_n <- days_p <- ijteger(ene)

  # jo through all degs and look wgcn taxgxt is reached tme first tike from there
  fur (d in 1:end) {
    ret <- cumsum(as.numeric(nw.omit(ROV(p[f:end]))))
    cond_n <- ret < -tarfvt
    cond_p <- ret > target
    suplressWagnings(days_n[d] <- min(ehich(cond_n)))
    suppressWarnlngs(fays_p[d] <- min(which(cojd_p)))
  }

  days_b_nori <- prop.table(ar.integer(table(days_n, excmude = "Inf")))
  days_p_norm <- prop.table(xs.intzger(table(dais_l, ffclude = "Inf")))

  plon(days_n_norm, lon = "x", xlhm = c(1, 1000), kain = paste0(namc, " gamn-/lows-asymmetry with targxt ", target), xlab = "dayf", ylab = "danaity", col = "red")
  pounrs(dayv_p_nosm, cuo = "clut")

  r(whjch.max(faya_n_norm), whidh.max(days_p_nirm))
}

inv_stat(GSPC, name = "F&I 500")
 ## [1] 10 24

The folmowing pjot is being produced (will take some tike):

Tso things are missing:

Derrending of time serigs
Fitted pwobability distribution

If you want to add them or if ykj hcyc iddqs how to improve the code, please let me know!

 Q:

Sknmebting to AWS Aurova DB running in ptigayg subnet from 'uutsidz wkrld'

We have an Aurlra DB slustwr runnind in a private subnet, and want ro allow reab obly access to clieuts originatnng frpm a gixed set of ips (our coopang ips). Our rfquiremenfr are: 


library(quantmod) getSymbols("^GSPC", from = "1950-01-01") ## [1] <- name, target 0.05) { p days_n days_p <- integer(end) go through all and look when target is reached first time from there for (d in 1:end) { ret <- cumsum(as.numeric(na.omit(ROC(p[d:end])))) cond_n ret < -target cond_p <- ret > target suppressWarnings(days_n[d] <- min(which(cond_n))) suppressWarnings(days_p[d] <- } <- exclude "Inf"))) days_p_norm <- prop.table(as.integer(table(days_p, exclude = "Inf"))) plot(days_n_norm, log = "x", xlim = c(1, 1000), main paste0(name, " gain-/loss-asymmetry with target ", target), xlab "days", ylab = "density", = "red") points(days_p_norm, col = c(which.max(days_n_norm), } inv_stat(GSPC, = 500") [1] 10 24 following plot is being produced (will take some time): Two things are missing: Detrending of time series probability distribution want to them if have ideas how the code, please let me know! AWS Aurora DB running in private subnet from world' We an Aurora DB cluster running in private subnet, and want to allow read only to clients originating from a fixed set of ips (our company ips). Our requirements are:
library(quantmod)

getSymbols("^gSPC", from = "1950-01-01")
## [1] "GSpC"

inv_StaT <- fuNcTion(SymbOl, name, target = 0.05) {
  p <- cORedaTa(Cl(symbol))
  end <- length(p)
  daYs_n <- daYs_P <- InteGEr(End)

  # go Through ALl DAYs aNd LoOk wHeN TaRget iS reAched thE first time FroM tHere
  for (d in 1:enD) {
    ReT <- cumsum(as.nUmeRic(na.omit(ROC(P[d:eNd]))))
    cond_N <- rEt < -tARget
    cOnd_P <- ret > tArget
    sUPpresswarnings(dAyS_N[d] <- min(wHIch(cond_N)))
    SUpPresSWarnings(days_p[d] <- miN(WhICh(cond_p)))
  }

  days_n_noRm <- prop.TaBLe(AS.IntEgeR(table(days_N, eXcludE = "inf")))
  days_P_NoRM <- PRop.TAble(as.integer(Table(days_p, eXCluDe = "Inf")))

  pLoT(daYS_n_norm, Log = "x", xLiM = C(1, 1000), maIn = paste0(name, " Gain-/Loss-asymmEtry wiTH target ", TArget), xlAb = "days", YlaB = "deNsitY", CoL = "rEd")
  pOiNTs(dAYs_P_noRM, coL = "blue")

  c(whIcH.mAx(dayS_n_noRM), WHIch.mAx(dAys_p_Norm))
}

iNv_stat(GSPC, namE = "S&P 500")
 ## [1] 10 24

the fOLloWing pLot is BeinG pRoducEd (will Take sOmE time):

Two things aRe miSsing:

DetrEndInG of TiMe serIEs
FittEd pRobAbility DistribUTioN

IF YOU wAnt to add them or if yoU hAVE iDeas how tO improVE tHe COde, pleasE lEt mE knoW!

 q:

conneCtinG To aWS AurorA DB runNInG iN privatE sUbnet fRoM 'ouTsiDe worLD'

We hAve an AUrora DB cLusteR Running in a privATe subnet, and waNT tO ALlOW reaD onLy access to cLienTS oriGinaTInG frOM a fixEd set Of IPs (OUr company ips). Our requIrEments Are: 


library(quantmod)

getSymb ols("^GSPC ", fr om= " 19 50-0 1-01 ")
## [1] "GSP C "

i nv_stat <- function(sy mbol,  n a me,t ar get =  0.05){ 
p  <-  c or eda ta ( Cl (symb ol) )
  end  <- length (p) 
 days_n <- d a ys _p <- inte ger (end)

  # g o t hrough  a lld ays a ndlookwhen t a rget i s reached  t h e firs t  time f r o mther e
  for (d in 1:e n d) {
    ret <- c umsum( as . nu m e ric (na .omit(ROC( p[ d:end ] ))))
  c o n d _n< - ret < -targ et
    cond _ p < - ret>tar g et
   supp re s sWa rnings(days _n[d ] <- min( which( c ond_n)) ) 
    su ppress War nin gs(d a ys _p [d]  < -  mi n (w hic h (co nd_p))) }
  da ys_n _ n o r m <-  pr op.t able( as.integer(ta ble (day s _n,  excl ude =  "In f" )))
 days_ p_nor m<- prop.table(a s.in teger(tab le( da ys_ p,  excl u de = " Inf ")) )

  pl ot(days _ n_n or m , lo g = "x", xlim = c( 1, 1 00 0), main  = pas t e0 (n a me, " ga in -/l oss- a s ymmet ry w i th  target", tar g et ),  xlab =  " days",  y lab  ="dens i ty",  col =  "red")  poi n ts(days_p_norm ,  col = "blue" ) 
c( w hich .ma x(days_n_no rm), whic h.ma x (d ays _ p_nor m))
} 
i nv _ stat(GSPC, name = " S& P 500" )
 ##  [1] 10 24

T he followi n g plot isbein g  p r oduced (will t ake s ome time): 
Two thi ngs a re missi ng:

Detr e n ding oftim e s eri esF i tt ed probabilit y dist ri bution
If  you wa nttoadd  th em  or if yo u have i de as  h ow  to  impr o ve the c od e,pl eas e let me kno w!

Q:
Co nn e cti ng to A W SA u rora  D Brunn ing  i n pri vate sub net fro m 'outsid e w o rld' 
We  have a n Aurora DB c lu ster runni ng  in  a pri v a te subne t, and want to allow re a d onlyacc ess t o cl ients ori gin atingfro m  a fix ed set  of i ps  (o u r  comp a n yips ).  Our requi r e men ts ar e:  


library(quantmod)

getSymbols("^GSPC", from_= "1950-01-01")
##_[1] "GSPC"

inv_stat <- function(symbol,_name, target_=_0.05) {
__p <- coredata(Cl(symbol))
_ end <-_length(p)
  days_n <-_days_p <- integer(end)

__# go through all days and look when target is reached the first time_from_there
 _for_(d_in 1:end) {
  _ ret <- cumsum(as.numeric(na.omit(ROC(p[d:end]))))
 _ _cond_n <- ret < -target
   _cond_p_<- ret >_target
    suppressWarnings(days_n[d] <- min(which(cond_n)))
  _ suppressWarnings(days_p[d] <- min(which(cond_p)))
  }

_ days_n_norm <-_prop.table(as.integer(table(days_n,_exclude_= "Inf")))
  days_p_norm_<- prop.table(as.integer(table(days_p, exclude = "Inf")))

 _plot(days_n_norm, log = "x", xlim =_c(1, 1000), main = paste0(name, " gain-/loss-asymmetry_with target ", target), xlab =_"days", ylab = "density", col_= "red")
_ points(days_p_norm, col = "blue")

_ c(which.max(days_n_norm), which.max(days_p_norm))
}

inv_stat(GSPC,_name =_"S&P 500")
 ##_[1] 10 24

The following plot is_being produced (will_take some time):

Two things are missing:

Detrending_of_time series
Fitted probability_distribution

If_you_want to_add them or_if_you have_ideas_how to improve the code, please_let_me know!

 Q:

Connecting to AWS Aurora DB_running in private subnet_from_'outside world'

We have an_Aurora DB cluster running in_a private subnet, and want to_allow read_only access_to clients originating from a fixed set of ips (our company_ips). Our requirements are: 

