I have created a simple Q script (see below) that reads 41 years of
daily hog futures data and attempts to calculate the profit of long
positions entered at a specified calendar date each year and exited at
a subsequent date for each of the 41 years of data. The challenge in
calculating the 41 years of results is that a specifed entry and
subsequent exit date in some years fall on weekends and/or holidays
(i.e., non-trading days). In order to get around this problem, the
trading rule is to use the next trading day (e.g., Monday in most but
not all cases) where trading occurred (and the database has trading
data) for entering the trade (i.e., going long) and use the previously
available trading day (Friday in most cases) when exiting the
position.
I have tried different things but am not able to generate trades in
each of the 41 years. The script below gives an error message becasue
data for entering the position does not match data for exiting (i.e.,
in some years there is entry into the position but no exit and vice
versa).
Any suggestions on what I can use to select the next available close
price when entering a trade and the last available close price on exit
when the specified date falls on a weekend/holiday?
Thanks in advance for the help!
t:(“SISSDIDIIIIIIFFFF”;enlist “,”) 0: `:c:/q/LHData1103244.txt
ntr:select Tradeyear,Monthsymbol,ntrdate:Tradedate,ntrclose:Close2
from t where Monthsymbol=G,Tradeday=2011.01.08 xit:select Tradeyear,Monthsymbol,xitdate:Tradedate,xitclose:Close2 from t where Monthsymbol=
G,Tradeday=2011.01.18
trd:ntr,'xit
trdresults:update profit:ntrclose-xitclose from select from trd
`:c:/q/trdresults.csv 0: “,” 0: trdresults