QQQ. First Trading Day of the month, close 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 close, exit on the next day close.
year | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | Total |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1999 | 0.00 | 0.00 | 0.00 | 2.02 | -0.55 | -2.27 | 0.68 | -0.30 | 0.71 | 0.03 | -0.53 | 2.12 | 1.91 |
2000 | 3.56 | 2.60 | 0.81 | -6.37 | 0.90 | 4.87 | 1.90 | -1.36 | 0.98 | -2.31 | -0.86 | 1.60 | 6.32 |
2001 | -9.25 | 1.30 | 2.78 | -4.68 | 3.97 | 2.87 | -0.55 | 3.12 | -3.26 | -0.87 | 4.07 | -1.74 | -2.24 |
2002 | 2.99 | -0.98 | 5.48 | 1.90 | -0.53 | -3.67 | -5.03 | -4.91 | -3.78 | 5.74 | 2.77 | 1.01 | 0.99 |
2003 | 4.06 | 0.17 | -2.07 | 0.82 | 0.87 | -0.70 | 1.34 | -1.09 | 1.42 | 2.20 | 1.63 | 1.45 | 10.10 |
2004 | -0.26 | -0.28 | 1.29 | 0.86 | 0.95 | -0.14 | -1.88 | 0.18 | 0.73 | 2.66 | 0.39 | 1.98 | 6.48 |
2005 | -1.07 | 0.30 | 1.10 | -1.00 | 0.41 | 0.81 | -0.14 | 0.16 | -0.13 | 0.26 | -0.08 | 1.82 | 2.44 |
2006 | 2.17 | 0.37 | 1.33 | 0.12 | -0.99 | 2.30 | 0.61 | -1.72 | 0.53 | -1.28 | -1.39 | -0.87 | 1.18 |
2007 | 0.19 | -0.16 | -0.48 | 0.14 | 0.33 | 0.06 | 0.90 | 0.77 | 1.63 | 1.14 | -1.90 | -0.84 | 1.78 |
2008 | -1.60 | 1.01 | -0.65 | 4.10 | 3.06 | -1.24 | 1.40 | -1.30 | -1.26 | -1.06 | -0.22 | -8.14 | -5.90 |
2009 | 4.14 | 1.18 | -3.37 | 1.49 | 0.27 | 2.77 | 0.06 | 1.47 | -1.91 | -3.07 | 0.42 | 1.01 | 4.46 |
2010 | 1.44 | 1.10 | 1.43 | 0.00 | 1.38 | -0.94 | -0.28 | 1.84 | 2.89 | -0.12 | 0.08 | 2.06 | 10.88 |
2011 | 1.55 | 1.85 | -1.63 | 0.05 | -0.19 | -2.22 | 1.49 | -0.47 | -0.92 | -2.64 | -2.68 | 0.00 | -5.81 |
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_1.c)/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)