#####
#
# Quantifying Trading Behavior in Financial Markets Using Google Trends
#
# Copyright (C) 2013 Tobias Preis and Helen Susannah Moat
# http://www.tobiaspreis.de
# http://www.suzymoat.co.uk
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version
# 3 of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, see
# http://www.gnu.org/licenses/.
#
# Related publication:
#
# Tobias Preis, Helen Susannah Moat, and H. Eugene Stanley,
# Scientific Reports 3, 1684 (2013)
# doi:10.1038/srep01684
#
#
# Read data file
read.csv(sep=" ","PreisMoatStanley_ScientificReports_3_1684_2013.dat")->dat
# Parameters
deltat1) { # Not on first date (no previous search volume)
r[i]deltat) { # Wait for first window to pass,
# so we can calc past search volume
if(i0) { # search volume has gone up
# Short position
r[i]