2018年9月20日木曜日

addTA,approx


Draw the line between given 2 positions on the candle chart.

my_draw_line_on_candle <- function(par_xts,start_val,start_date,end_val,end_date){
  len <- length(seq(as.Date(start_date),as.Date(end_date),by='weeks'))
  plot_data <- approx(seq(1,2,1),c(start_val,end_val),n=len,method='linear')$y
  tmp_xts <- as.xts(plot_data,seq(as.Date(start_date),as.Date(end_date),by='weeks'))
  addTA(tmp_xts,on=1,legend="slope")
}


> my_draw_line_on_candle(weekly_pf,2273486,"2018-01-26",2189051,"2018-09-19")
> my_draw_line_on_candle(weekly_pf,as.vector(first(weekly_pf)[,1]),index(first(weekly_pf)),2188051,"2018-09-19")
> my_draw_line_on_candle(weekly_pf,1160008,"2017-01-06",2163476,"2018-09-18")



> last(weekly_pf)[,4]/as.vector(first(weekly_pf)[,1])
              close
2018-09-19 3.450367
> length(index(weekly_pf))
[1] 247
> 3.450367**(1/247)
[1] 1.005027
> seq(1,247,1)
  [1]   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27
<skip>
[244] 244 245 246 247
> 1.005027**seq(1,247,1)
  [1] 1.005027 1.010079 1.015157 1.020260 1.025389 1.030544 1.035724 1.040931 1.046163 1.051423 1.056708 1.062020
 <skip>
[241] 3.348365 3.365197 3.382114 3.399116 3.416203 3.433376 3.450636
> tmp <- as.xts(634440.2*1.005027**seq(1,247,1),index(weekly_pf))
> addTA(tmp,on=1,legend="powered")

my_draw_line_on_candle(weekly_pf,as.vector(first(weekly_pf)[,1]),index(first(weekly_pf)),last(weekly_pf)[,4],index(last(weekly_pf)[,4]))
tmp <- as.xts((as.vector((last(weekly_pf)[,4]/as.vector(first(weekly_pf)[,1]))**(1/length(index(weekly_pf))))**seq(1,length(index(weekly_pf)),1))*as.vector(first(weekly_pf)[,1]),index(weekly_pf))
addTA(tmp,on=1,legend="powered")
tmp <- as.xts((as.vector((1800000/as.vector(first(weekly_pf)[,1]))**(1/length(index(weekly_pf))))**seq(1,length(index(weekly_pf)),1))*as.vector(first(weekly_pf)[,1]),index(weekly_pf))

addTA(tmp,on=1,legend="")


0 件のコメント: