Testing theories about price in a statistical processor(R, Excel etc)

Hi,

I am just playing around width R(trying to learn how to use it) and wanted to test some theories I have.

The theori I have i that in a bear day, the High would be formed in either the London Open Session, or in the New York Open session.

To test my theory, I have downloaded the 15min EURUSD from Oanda, and exported it to a csv(everything via Oanda’s MT4)

I guess I will be using the xts package in R to test this… using this code:


install.packages("xts")
library(xts)
EURUSD.df <- read.csv(file.choose(), header=F)
head(EURUSD.df)


Okay, thats how far Ive come, currently Im trying to convert the data frame containing the price historics into a xts(time series) object… having some issues with it :stuck_out_tongue:

If anyone knows how to do this, I would love some help :wink:

Trust me, there are gazillions of teste theories but nothing works better than following you own intuition.

I know, I would just like to have some numbers to back my intuition :slight_smile:

Don’t know how to do the conversion, but if you have time you can program an Expert Advisor to the backtesting with metatrader mql4.

I know, I have tested many strategies using MT4’s backtester, but because of the limitation of just 1 pair to be tested, it isnt good enough.

I would like to test strategies and use other instruments as confirmation(like stocks and yields etc).

And I would like to learn how to use R :slight_smile:

This is how the code looks like now(crap, I know). It dosnt work, because I have a stupid issue trying to initialize my results data frame :stuck_out_tongue: (called [I]Test[/I] in this edition)

My problem right now is that Time/Date dosnt work in the resulting diagram, since R thinks all the data is supposed to be numbers, and not mixed(Date/Time and Numbers)



eu <- read.csv(file.choose(), header=F)
head(eu)
time.date <- unique(eu[,1])

#test2 <- matrix(rep(NA,length(eu$V) * 7), length(eu$V1), 7)

#Test <- rbind(NA, 1:7)
#Test <- data.frame(Test)
#Test <- as.data.frame(list(a1 = vector("numeric", n), a2 = vector("character", n)))
Test <- as.data.frame(list(Date = vector("character",n), Open = vector("number",n),
	High = vector("number",n), Low = vector("number",n), Close = vector("number,n"),
	HighAt = vector("character",n), LowAt = vector("character",n)))

x = 1
for (x in 1:length(time.date)) {
      cur_day <- eu[eu[,1] == time.date[x],] #All the data for the current date

	nHigh = max(cur_day[,4])
	nLow = min(cur_day[,5])
	
	nHighAtnr = which.max(cur_day[,4])
	nLowAtnr  = which.min(cur_day[,5])

	nHighAt = cur_day[nHighAtnr,2]
	nLowAt = cur_day[nLowAtnr,2]

	Test[x,1] = time.date[x]   #Date
	Test[x,2] = cur_day[1,3]  #Open
	Test[x,3] = nHigh            #High
	Test[x,4] = nLow             #Low
	Test[x,5] = cur_day[length(cur_day),6] #Close
	Test[x,6] = nHighAt        #High occured at time
	Test[x,7] = nLowAt         #Low occured at time
}

i could help you if you would use matlab :wink: good luck with R though, it’s the most powerful statistical computation tool there is.

Hi, thanks for the offer, I’ll let you know if I give up R(which is probably soon :confused: )

I have got all the information Except the date now:


> Test
  Date   Open   High    Low  Close    V6    V7
1 <NA> 1.1801 1.1862 1.1769 1.1791 12:45 04:30

by initialising Test like this:


Test <- data.frame(Date = as.Date(character()),
	Open = numeric(),
	High = numeric(),
	Low = numeric(), 
	Close = numeric(),
	HighAt =  str(5), 
	LowAt =  str(5),
	stringsAsFactors=FALSE)

I manage to get everything to work, except the sorting of the data, so I cheated a little bit, and copied my data into excel…

This is the diagram that came out


Remember this is Oandas data, so all the times are EST(GMT-5)

This data represent the low of the day if its a up day, or the high of the day if its a down day.
In other words, when you have yor bias correct, say a up-day, the Low of the day is supposed to be at 22:15 EST(Or around 18:00 since thats a bigger grouping)…

That does not comply with what I anticipated, so I need to take a look at my code and see if I have done anything wrong :stuck_out_tongue:

anyway, here is the code I used:

[C++] R test - Pastebin.com

Theres commercial stuff that can do that for you

Yeah I know, and it all cost money :wink: And the all require you to learn how to program it their way… So why not use the commonly used R to do statstics with?

I can’t help you, but I like your creative idea! I never thought of this.

Thanks, have been working on streamlining the code… And its done :slight_smile:

This is what you’ll see when you run the code:


> eu    <- read.csv(file.choose(), header=F)
> data  <- TestHighLowofDay(eu)
  Collecting information
|=================================================================================| 100%
   Removeing Saturday and Sunday candles
  Creating time list
  Creating Count list
  creating return list
  Done.

> plot(data,type="h")
> 

and thit is what it plots:

(All the times are GMT, data is run from 1999 to 2013

To check out the code, visit pastebin:
[C] When A high is made in a Low day/oppisit for up day - Pastebin.com

Please let me know if you have other ideas wich I can trie out :smiley: