QQQ. Days of the month, close to close.
Profit/loss (%) calculated for each day of the month for the period from 3/10/1999 till 11/28/2011: go long on close, exit on close next day.
day | 1999 | 2000 | 2001 | 2002 | 2003 | 2004 | 2005 | 2006 | 2007 | 2008 | 2009 | 2010 | 2011 | Total |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | 2.94 | 9.93 | 17.86 | 5.71 | 5.70 | 6.08 | 2.89 | -0.29 | -0.17 | 0.02 | 0.85 | 6.39 | -4.31 | 53.56 |
2 | 5.54 | -2.83 | -18.42 | -12.82 | 11.69 | 2.48 | 3.47 | -1.66 | 2.30 | -7.76 | 3.61 | 8.39 | -3.63 | -9.64 |
3 | 6.11 | 10.53 | 9.68 | -8.43 | 3.32 | -4.04 | -2.25 | 1.76 | -1.00 | -0.58 | 5.10 | 4.95 | 2.17 | 27.34 |
4 | 3.06 | -3.81 | 1.54 | 0.61 | -0.30 | 1.52 | 1.03 | 5.77 | 4.15 | -7.61 | 8.78 | -6.34 | -3.62 | 4.75 |
5 | 9.95 | 0.45 | 12.55 | -1.39 | -4.99 | 2.94 | -1.82 | -0.35 | 2.01 | 0.71 | 1.67 | 4.95 | 2.47 | 29.14 |
6 | -2.22 | -15.24 | -6.09 | 5.00 | 3.40 | -3.17 | -0.29 | -0.31 | 4.51 | -13.15 | 3.62 | -4.43 | 2.11 | -26.28 |
7 | 1.95 | 22.95 | -5.10 | -9.37 | 3.24 | 0.54 | 2.80 | -5.53 | -4.61 | -6.46 | -9.23 | -1.53 | 2.74 | -7.58 |
8 | 0.16 | -5.87 | -9.30 | 16.17 | -2.73 | -4.03 | -1.36 | 1.98 | 0.90 | 6.13 | 3.77 | 3.33 | -5.73 | 3.39 |
9 | 3.22 | -4.86 | -12.64 | -15.22 | -1.22 | -0.78 | 0.75 | -2.43 | -6.06 | -7.65 | 4.57 | 2.91 | -1.22 | -40.61 |
10 | 2.25 | -21.67 | 10.27 | 2.68 | -1.26 | 0.81 | -2.16 | 0.24 | -0.80 | -1.10 | 3.63 | 9.27 | -2.36 | -0.17 |
11 | 7.01 | 3.84 | 11.26 | 0.11 | 4.53 | 2.61 | 1.44 | -1.45 | -0.69 | -5.97 | 0.92 | -0.96 | 5.57 | 28.25 |
12 | -3.67 | -16.62 | 7.59 | 1.57 | 6.40 | 2.37 | 0.43 | -2.82 | 2.55 | -1.84 | 2.19 | -0.49 | 2.54 | 0.20 |
13 | -2.16 | 10.76 | -0.62 | -1.92 | 3.41 | -1.98 | -0.24 | -0.11 | 5.09 | 23.31 | 0.30 | 2.62 | 2.39 | 40.83 |
14 | -6.13 | -8.05 | -3.95 | 13.72 | 4.40 | -2.17 | 0.31 | 5.66 | -0.75 | -11.34 | -1.24 | 0.25 | 3.23 | -6.07 |
15 | 3.47 | 0.58 | -4.96 | 11.79 | -0.91 | -2.78 | -1.52 | 7.64 | -2.72 | -15.17 | 2.14 | 3.70 | 1.78 | 3.02 |
16 | 9.77 | 4.71 | -9.95 | -1.86 | 4.38 | -0.50 | -1.41 | 1.49 | 0.78 | 16.17 | 4.22 | -1.94 | -5.48 | 20.39 |
17 | 5.22 | 11.92 | -9.12 | 8.79 | -5.65 | 3.52 | 1.77 | -4.11 | -0.36 | -11.68 | -2.39 | 3.49 | -3.64 | -2.28 |
18 | 2.65 | -8.44 | 11.41 | -9.67 | 8.87 | 4.59 | 0.00 | -0.84 | 1.80 | 4.47 | 6.49 | 1.10 | -5.00 | 17.40 |
19 | -6.61 | 1.33 | 12.45 | -13.70 | -5.32 | -5.13 | 0.60 | 1.66 | -1.57 | -4.19 | 0.08 | -1.45 | -1.65 | -23.54 |
20 | 1.84 | -10.00 | -21.31 | -2.32 | 0.19 | 0.93 | -2.88 | -2.89 | 3.19 | -2.83 | -8.15 | -0.72 | -0.06 | -44.96 |
21 | 12.12 | -3.62 | -0.73 | 0.73 | 2.61 | 0.43 | 2.24 | -4.93 | 6.36 | -3.37 | 7.12 | -0.73 | 2.37 | 20.54 |
22 | -5.31 | 7.92 | 10.03 | -7.32 | 0.34 | 0.70 | -2.77 | -1.91 | 0.77 | -11.63 | -2.36 | 1.36 | -5.32 | -15.51 |
23 | 0.16 | -3.45 | -9.42 | -4.77 | 3.67 | -2.16 | 0.10 | -1.36 | 1.70 | -0.74 | 7.33 | -2.84 | 2.11 | -9.62 |
24 | 3.00 | 3.05 | 10.71 | 1.02 | -12.02 | 1.90 | 0.12 | 3.30 | 1.12 | 8.27 | 4.47 | 0.81 | 4.21 | 29.95 |
25 | 2.40 | -4.26 | 1.51 | -0.66 | 0.05 | 6.94 | 1.14 | 3.78 | 0.03 | 0.68 | 1.65 | 1.72 | -2.16 | 12.86 |
26 | -0.57 | -2.79 | -1.67 | -5.62 | 0.51 | 0.69 | 0.81 | 3.02 | -0.43 | -0.87 | 4.49 | -1.54 | 5.52 | 1.54 |
27 | -0.64 | 0.77 | 3.01 | -3.43 | 3.46 | 1.06 | -2.76 | -2.34 | -4.61 | -2.09 | -5.50 | 3.46 | 4.62 | -4.95 |
28 | 5.84 | -11.44 | -14.23 | -5.33 | 8.39 | -2.62 | -1.11 | 0.80 | -0.56 | 9.68 | 4.35 | -4.26 | 0.77 | -9.74 |
29 | 5.69 | -15.37 | -6.36 | -1.72 | 6.19 | 3.99 | -0.21 | 5.60 | 4.86 | -9.87 | 0.80 | -4.39 | 2.58 | -8.19 |
30 | -4.25 | 5.73 | -8.36 | 3.48 | -3.95 | -3.06 | 0.42 | -1.10 | 0.59 | 7.49 | -5.02 | -5.91 | -0.13 | -14.08 |
31 | -0.50 | 15.70 | -3.56 | -3.98 | -3.05 | -0.23 | 2.92 | -0.17 | 0.75 | 3.02 | -1.36 | -1.15 | 0.72 | 9.14 |
Query used:
--1
select [day], [1999], [2000], [2001], [2002], [2003], [2004], [2005], [2006],[2007], [2008], [2009], [2010], [2011], [2012] Total into #t
from
( select cast((t.c- t_1.c)/t_1.c * 100 as decimal(10,2)) pl, DATEPART(d, t.d) [day], YEAR(t.d) y
from qqq t
join qqq t_1 on t_1.id = t.id -1
) p
pivot
(
sum(pl)
for y in ([1999], [2000], [2001], [2002], [2003], [2004], [2005], [2006],[2007], [2008], [2009], [2010], [2011],[2012])
) r
order by [day]
--2
update t
set t.Total = p.pl
from #t t
join (
select
datepart(d, t.d) [day],
cast(sum((t.c- t_1.c)/t_1.c * 100) as decimal(10,2)) 'PL'
from qqq t
join qqq t_1 on t_1.id = t.id -1
group by datepart(d, t.d)
) p on T.[day] = p.[day]
--3
DECLARE @HeaderList varchar(max)
SELECT @HeaderList = COALESCE(@HeaderList + '', '') + name
from tempdb.sys.columns where object_id = object_id('tempdb..#t') order by column_id
select ' ' + @HeaderList + ' '
--4
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
--select ' ' + @SelectList + ' '
declare @sql varchar(max)
select @sql = 'select ''''+' + @SelectList + '+'' '' from #t'
exec (@sql)
3 and 4 can be replaced with:
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)