QQQ. First Trading Day of the month, close to open.
Profit/loss (%) calculated for each first trading day of the month for the period from 3/10/1999 till 11/28/2011: go long on close, exit on the next day open.
year | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | Total |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1999 | 0.00 | 0.00 | 0.00 | 2.82 | -0.31 | -0.18 | 0.32 | 0.15 | 0.62 | -1.37 | 0.00 | 1.09 | 3.14 |
2000 | 5.01 | -0.19 | 0.47 | -1.61 | 1.03 | 2.43 | 0.07 | 0.41 | 1.34 | 1.66 | -1.73 | 1.69 | 10.58 |
2001 | 0.30 | 0.37 | -1.02 | 0.05 | 0.14 | 1.79 | -0.11 | 2.05 | -0.31 | -0.43 | 1.57 | -0.90 | 3.50 |
2002 | 1.66 | -0.30 | 1.07 | -0.70 | -0.16 | -0.14 | -0.52 | -0.44 | -1.90 | 0.90 | -0.73 | 2.46 | 1.20 |
2003 | 1.43 | 0.30 | 0.41 | 0.78 | -0.04 | 0.97 | -0.81 | -0.36 | 0.31 | 0.58 | 0.71 | 0.93 | 5.21 |
2004 | 0.57 | 0.34 | 0.28 | -0.12 | 0.65 | -0.78 | -0.19 | -0.84 | -0.28 | 0.88 | 0.23 | 0.37 | 1.11 |
2005 | 0.41 | 0.22 | 0.41 | 0.70 | 0.35 | -0.14 | 0.22 | 0.13 | 0.08 | 0.21 | -0.24 | 0.65 | 3.00 |
2006 | 0.58 | -0.62 | 0.30 | 0.54 | 0.17 | 0.26 | 0.32 | -0.92 | 0.53 | -0.13 | 0.34 | -0.09 | 1.28 |
2007 | 0.68 | 0.44 | -1.86 | 0.33 | 0.02 | 0.37 | 0.24 | -0.30 | 0.13 | 0.08 | -0.64 | -0.42 | -0.93 |
2008 | 0.10 | 0.81 | -0.05 | 1.56 | 0.04 | -0.18 | -0.80 | 0.11 | 1.59 | -0.18 | -0.25 | -2.18 | 0.57 |
2009 | 0.00 | -0.99 | -1.54 | -1.26 | -0.03 | 1.05 | 0.50 | 1.04 | -0.36 | -0.39 | 0.10 | 0.74 | -1.14 |
2010 | 1.25 | 0.26 | 0.45 | 0.42 | 0.43 | -0.38 | 0.31 | 1.24 | 1.44 | 0.83 | 0.37 | 1.45 | 8.07 |
2011 | 0.93 | 0.75 | 0.43 | 0.50 | 0.15 | -0.22 | 0.05 | 1.19 | 0.25 | -0.86 | -2.53 | 0.00 | 0.64 |
Query used:
select [year], [1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12],[13] Total into #t
from
( select cast((t.o - t_1.c)/t.o * 100 as decimal(10,2)) pl, year(t.d) [year], MONTH(t.d) [month]
from qqq t
join qqq t_1 on t_1.id = t.id - 1
where month(t_1.d)%12 = MONTH(t.d) - 1) p
pivot
(
sum(pl)
for [month] in ([1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12],[13])
) r
order by [year]
--2
update #t
set Total = coalesce([1], 0) + coalesce([2], 0) + coalesce([3], 0) + coalesce([4], 0)
+ coalesce([5], 0) + coalesce([6], 0) + coalesce([7], 0) + coalesce([8], 0)
+ coalesce([9], 0) + coalesce([10], 0) + coalesce([11], 0) + coalesce([12], 0)
DECLARE @HeaderList varchar(max), @head varchar(1000)
SELECT @HeaderList = COALESCE(@HeaderList + '', '') + name
from tempdb.sys.columns where object_id = object_id('tempdb..#t') order by column_id
select @head = ' ' + @HeaderList + ' '
DECLARE @SelectList varchar(max)
SELECT @SelectList = COALESCE(@SelectList + '+''''+', '') + 'CAST([' + name + '] AS varchar(50))'
from tempdb.sys.columns where object_id = object_id('tempdb..#t') order by column_id
declare @sql varchar(max)
select @sql = 'select ''' + @head + ''' union all select '' ''+' + @SelectList + '+'' '' from #t'
exec (@sql)