When I bought these I was doing my charting by hand on graph paper using prices from the Wall Street Journal, but in due course I got a computer and began using various software programs; Excel, Open Office Calc, QtStalker and finally ended up where I am today using Octave, R and Gnuplot. But however proficient I became at using these last three my programming skills weren't up to coding the Delta Phenomenon, until now that is. I had already quite easily coded the Adam Projection and the Natural Market Mirror, Natural Market River and Natural Moving Average from Ocean theory. Over the next few posts I am going to outline how I intend to test the Delta Phenomenon and show the eventual results of these tests, but before that I am going to present in this post the "breakthrough" piece of coding that finally allows me to do so. I think other users of R may find it useful.
The issue to be solved was overcoming the problem of missing days in the time series data, e.g. weekends, holidays, exchange closures, just plain missing data etc. because the Delta Phenomenon is predicated on counting days before or after specified dates, and of course any algorithmic counting over the data would be upset by such missing days. My forum query here and forum searches that turned up this led me to the R xts package, which finally resulted in me being able to write the following piece of R code
The code takes a csv file of the price time series, merges it with a csv file of the "Delta Solution," fills in any missing dates and then writes out the result to a final csv file that looks like this
rm(list=ls(all=TRUE)) # remove all previous data from workspace library(xts) # load the required library # preparation for output to new file sink(file="solution",append=FALSE,type=c("output"),split=FALSE) # read in the raw data files data_1 <- read.csv(file="sp",header=FALSE,sep=",") itdmtd <- read.csv(file="itdmtd",header=FALSE,sep=",") # create xts objects from above data: x <- xts(data_1[c('V2','V3','V4','V5')],as.Date(data_1[,'V1'])) y <- xts(itdmtd[c('V2','V3','V4','V5','V6','V7','V8','V9')],as.Date(itdmtd[,'V1'])) z <- merge.xts(x,y) # merge x and y # create a contiguous date vector to encompass date range of above data d <- timeBasedSeq(paste(start(z),end(z),"d",sep="/"), retclass="Date") # merge z with an "empty" xts object, xts(,d), filling with NA prices <- merge(z,xts(,d),fill=NA) # coerce prices xts object to a data frame object prices_df <- data.frame(date=index(prices), coredata(prices)) # output to new file write.table(prices_df,quote=FALSE,row.names=FALSE,col.names=FALSE,sep=",") sink()
This might not actually look like much, but using this as input to this Gnuplot script
gives a nice plot thus
reset set title "Medium Term Delta Turning Points" textcolor rgb "#FFFFFF" set object 1 rect from graph 0, 0, 0 to graph 1.1, 1.1, 0 behind lw 1.0 fc rgb "#000000" fillstyle solid 1.00 set datafile separator "," set xdata time set timefmt "%Y-%m-%d" set format x set y2range [0:1] plot "solution" using 1:10 notitle with impulses linecolor rgb "#B0171F" axis x1y2, \ "solution" using 1:11 notitle with impulses linecolor rgb "#0000FF" axis x1y2, \ "solution" using 1:12 notitle with impulses linecolor rgb "#FFA500" axis x1y2, \ "solution" using 1:13 notitle with impulses linecolor rgb "#00EE00" axis x1y2, \ "solution" using 1:2:3:4:5 notitle with candlesticks linecolor rgb "#FFFFFF" axis x1y1, \ "solution" using 1:($$2>$$5?$$2:1/0):($$2>$$5?$$3:1/0):($$2>$$5?$$4:1/0):($$2>$$5?$$5:1/0) notitle with candlesticks lt 1 axis x1y1, \ "solution" using 1:($$2<$$5?$$2:1/0):($$2<$$5?$$3:1/0):($$2<$$5?$$4:1/0):($$2<$$5?$$5:1/0) notitle with candlesticks lt 3 axis x1y1
Delta Society sells on its website. Most importantly of all, of course, is that I am now in a position to do computerised testing of the Delta Phenomenon. More on these tests in upcoming posts.