QQQ. First Trading Day of the month, open to close.
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 open, exit on close.
year | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | Total |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1999 | 0.00 | 0.00 | 0.00 | -0.82 | -0.23 | -2.09 | 0.36 | -0.44 | 0.09 | 1.39 | -0.53 | 1.04 | -1.23 |
2000 | -1.52 | 2.78 | 0.35 | -4.69 | -0.13 | 2.49 | 1.84 | -1.77 | -0.37 | -4.04 | 0.85 | -0.10 | -4.31 |
2001 | -9.58 | 0.93 | 3.76 | -4.74 | 3.84 | 1.11 | -0.44 | 1.09 | -2.94 | -0.44 | 2.54 | -0.83 | -5.70 |
2002 | 1.35 | -0.68 | 4.46 | 2.58 | -0.36 | -3.53 | -4.49 | -4.45 | -1.84 | 4.88 | 3.47 | -1.49 | -0.10 |
2003 | 2.67 | -0.13 | -2.49 | 0.04 | 0.90 | -1.69 | 2.13 | -0.73 | 1.11 | 1.64 | 0.93 | 0.52 | 4.90 |
2004 | -0.83 | -0.62 | 1.01 | 0.98 | 0.30 | 0.63 | -1.69 | 1.01 | 1.00 | 1.79 | 0.17 | 1.62 | 5.37 |
2005 | -1.49 | 0.08 | 0.69 | -1.71 | 0.06 | 0.94 | -0.36 | 0.03 | -0.21 | 0.05 | 0.16 | 1.18 | -0.58 |
2006 | 1.59 | 0.98 | 1.04 | -0.42 | -1.17 | 2.04 | 0.29 | -0.79 | 0.00 | -1.15 | -1.74 | -0.78 | -0.11 |
2007 | -0.50 | -0.61 | 1.36 | -0.19 | 0.31 | -0.30 | 0.66 | 1.07 | 1.50 | 1.06 | -1.25 | -0.42 | 2.69 |
2008 | -1.70 | 0.20 | -0.60 | 2.58 | 3.02 | -1.05 | 2.18 | -1.41 | -2.89 | -0.87 | 0.03 | -5.83 | -6.34 |
2009 | 4.14 | 2.15 | -1.80 | 2.71 | 0.30 | 1.73 | -0.45 | 0.43 | -1.55 | -2.67 | 0.32 | 0.28 | 5.59 |
2010 | 0.20 | 0.84 | 0.98 | -0.42 | 0.95 | -0.56 | -0.59 | 0.61 | 1.47 | -0.97 | -0.29 | 0.63 | 2.85 |
2011 | 0.62 | 1.11 | -2.07 | -0.45 | -0.34 | -1.99 | 1.44 | -1.68 | -1.18 | -1.76 | -0.14 | 0.00 | -6.44 |
Query used:
select [year], [1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12],[13] Total into #t
from
( select cast((t.c - t.o)/t.c * 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)