计算成对滚动相关性

时间:2013-08-10 10:58:34

标签: excel vba excel-vba

请找到工作簿here

第一行包含银行的名称,所有其他条目是每个银行的每日回报。我想要做的是找到从2008年1月1日开始的成对银行的滚动相关性(从过去1年的回报),我将提供一个我想做的例子:

从ERSTE GROUP BANK开始,在2008年1月1日,我想根据过去1年的回报率找到ERSTE GROUP BANK和RAIFFEISEN BANK INTL之间的相关性,因此公式为= CORREL(B2: B263,C2:C263),类似于2008年1月2日,公式为= CORREL(B3:B264,C3:C264),依此类推至2013年2月28日。

然后我想做同样的事情,但现在在2008年1月1日,我发现ERSTE GROUP BANK和DEXIA之间的成对关联,因此2008年1月1日的公式将是= CORREL(B2:B263,D2: D263)依此类推至2013年2月28日。

基本上我想找到ERSTE GROUP BANK和其他所有银行之间的成对关联,从1/1 / 2008-28 / 2/2013。

然后我想对所有其他银行重复这一点,例如,现在把RAIFFEISEN BANK INTL作为主要的'银行和1/1 / 2008-28 / 2/2013,我想找到RAIFFEISEN BANK INTL和ERSTE GROUP BANK,RAIFFEISEN BANK INTL和DEXIA等之间的成对关联。

有没有人知道如何为此编写宏?任何帮助将不胜感激。

编辑:这是我目前的代码,它可以运行,但仅适用于一个银行,我希望代码能够自动为所有其他银行执行此操作。

Sub correlations()
'
' 
'

'
    Range("C1:Z1").Select
    Selection.Copy
    ActiveWindow.SmallScroll ToRight:=5
    Range("AC1").Select
    ActiveSheet.Paste
    ActiveWindow.ScrollColumn = 21
    ActiveWindow.ScrollColumn = 22
    ActiveWindow.ScrollRow = 6
    ActiveWindow.ScrollRow = 11
    ActiveWindow.ScrollRow = 15
    ActiveWindow.ScrollRow = 20
    ActiveWindow.ScrollRow = 24
    ActiveWindow.ScrollRow = 27
    ActiveWindow.ScrollRow = 33
    ActiveWindow.ScrollRow = 36
    ActiveWindow.ScrollRow = 40
    ActiveWindow.ScrollRow = 42
    ActiveWindow.ScrollRow = 47
    ActiveWindow.ScrollRow = 49
    ActiveWindow.ScrollRow = 51
    ActiveWindow.ScrollRow = 53
    ActiveWindow.ScrollRow = 56
    ActiveWindow.ScrollRow = 58
    ActiveWindow.ScrollRow = 60
    ActiveWindow.ScrollRow = 65
    ActiveWindow.ScrollRow = 67
    ActiveWindow.ScrollRow = 69
    ActiveWindow.ScrollRow = 74
    ActiveWindow.ScrollRow = 76
    ActiveWindow.ScrollRow = 78
    ActiveWindow.ScrollRow = 80
    ActiveWindow.ScrollRow = 87
    ActiveWindow.ScrollRow = 89
    ActiveWindow.ScrollRow = 94
    ActiveWindow.ScrollRow = 96
    ActiveWindow.ScrollRow = 98
    ActiveWindow.ScrollRow = 103
    ActiveWindow.ScrollRow = 112
    ActiveWindow.ScrollRow = 116
    ActiveWindow.ScrollRow = 118
    ActiveWindow.ScrollRow = 120
    ActiveWindow.ScrollRow = 123
    ActiveWindow.ScrollRow = 127
    ActiveWindow.ScrollRow = 129
    ActiveWindow.ScrollRow = 134
    ActiveWindow.ScrollRow = 141
    ActiveWindow.ScrollRow = 145
    ActiveWindow.ScrollRow = 147
    ActiveWindow.ScrollRow = 152
    ActiveWindow.ScrollRow = 154
    ActiveWindow.ScrollRow = 156
    ActiveWindow.ScrollRow = 159
    ActiveWindow.ScrollRow = 161
    ActiveWindow.ScrollRow = 163
    ActiveWindow.ScrollRow = 165
    ActiveWindow.ScrollRow = 170
    ActiveWindow.ScrollRow = 176
    ActiveWindow.ScrollRow = 179
    ActiveWindow.ScrollRow = 188
    ActiveWindow.ScrollRow = 192
    ActiveWindow.ScrollRow = 199
    ActiveWindow.ScrollRow = 205
    ActiveWindow.ScrollRow = 208
    ActiveWindow.ScrollRow = 212
    ActiveWindow.ScrollRow = 217
    ActiveWindow.ScrollRow = 223
    ActiveWindow.ScrollRow = 226
    ActiveWindow.ScrollRow = 230
    ActiveWindow.ScrollRow = 232
    ActiveWindow.ScrollRow = 237
    ActiveWindow.ScrollRow = 239
    ActiveWindow.ScrollRow = 241
    ActiveWindow.ScrollRow = 243
    ActiveWindow.ScrollRow = 246
    ActiveWindow.ScrollRow = 248
    ActiveWindow.ScrollRow = 252
    ActiveWindow.ScrollRow = 257
    ActiveWindow.ScrollRow = 259
    ActiveWindow.ScrollRow = 261
    ActiveWindow.ScrollRow = 266
    ActiveWindow.ScrollRow = 270
    ActiveWindow.ScrollRow = 275
    ActiveWindow.ScrollRow = 277
    ActiveWindow.ScrollRow = 279
    ActiveWindow.ScrollRow = 284
    ActiveWindow.ScrollRow = 286
    ActiveWindow.ScrollRow = 288
    ActiveWindow.ScrollRow = 293
    ActiveWindow.ScrollRow = 295
    ActiveWindow.ScrollRow = 299
    ActiveWindow.ScrollRow = 304
    ActiveWindow.ScrollRow = 306
    ActiveWindow.ScrollRow = 311
    ActiveWindow.ScrollRow = 313
    ActiveWindow.ScrollRow = 317
    ActiveWindow.ScrollRow = 319
    ActiveWindow.ScrollRow = 324
    ActiveWindow.ScrollRow = 326
    ActiveWindow.ScrollRow = 328
    ActiveWindow.ScrollRow = 335
    ActiveWindow.ScrollRow = 337
    ActiveWindow.ScrollRow = 340
    ActiveWindow.ScrollRow = 344
    ActiveWindow.ScrollRow = 349
    ActiveWindow.ScrollRow = 351
    ActiveWindow.ScrollRow = 353
    ActiveWindow.ScrollRow = 355
    ActiveWindow.ScrollRow = 357
    ActiveWindow.ScrollRow = 360
    ActiveWindow.ScrollRow = 362
    ActiveWindow.ScrollRow = 364
    ActiveWindow.ScrollRow = 366
    ActiveWindow.ScrollRow = 371
    ActiveWindow.ScrollRow = 373
    ActiveWindow.ScrollRow = 378
    ActiveWindow.ScrollRow = 380
    ActiveWindow.ScrollRow = 384
    ActiveWindow.ScrollRow = 387
    ActiveWindow.ScrollRow = 389
    ActiveWindow.ScrollRow = 391
    ActiveWindow.ScrollRow = 393
    ActiveWindow.ScrollRow = 400
    ActiveWindow.ScrollRow = 402
    ActiveWindow.ScrollRow = 407
    ActiveWindow.ScrollRow = 409
    ActiveWindow.ScrollRow = 411
    ActiveWindow.ScrollRow = 416
    ActiveWindow.ScrollRow = 418
    ActiveWindow.ScrollRow = 420
    ActiveWindow.ScrollRow = 422
    ActiveWindow.ScrollRow = 425
    ActiveWindow.ScrollRow = 427
    ActiveWindow.ScrollRow = 429
    ActiveWindow.ScrollRow = 425
    ActiveWindow.ScrollRow = 416
    ActiveWindow.ScrollRow = 413
    ActiveWindow.ScrollRow = 409
    ActiveWindow.ScrollRow = 402
    ActiveWindow.ScrollRow = 393
    ActiveWindow.ScrollRow = 384
    ActiveWindow.ScrollRow = 380
    ActiveWindow.ScrollRow = 375
    ActiveWindow.ScrollRow = 369
    ActiveWindow.ScrollRow = 364
    ActiveWindow.ScrollRow = 362
    ActiveWindow.ScrollRow = 355
    ActiveWindow.ScrollRow = 353
    ActiveWindow.ScrollRow = 351
    ActiveWindow.ScrollRow = 349
    ActiveWindow.ScrollRow = 346
    ActiveWindow.ScrollRow = 344
    ActiveWindow.ScrollRow = 342
    ActiveWindow.ScrollRow = 340
    ActiveWindow.ScrollRow = 337
    ActiveWindow.ScrollRow = 335
    ActiveWindow.ScrollRow = 333
    ActiveWindow.ScrollRow = 328
    ActiveWindow.ScrollRow = 326
    ActiveWindow.ScrollRow = 324
    ActiveWindow.ScrollRow = 322
    ActiveWindow.ScrollRow = 317
    ActiveWindow.ScrollRow = 315
    ActiveWindow.ScrollRow = 311
    ActiveWindow.ScrollRow = 308
    ActiveWindow.ScrollRow = 306
    ActiveWindow.ScrollRow = 304
    ActiveWindow.ScrollRow = 302
    ActiveWindow.ScrollRow = 299
    ActiveWindow.ScrollRow = 297
    ActiveWindow.ScrollRow = 295
    ActiveWindow.ScrollRow = 293
    ActiveWindow.ScrollRow = 290
    ActiveWindow.ScrollRow = 288
    ActiveWindow.ScrollRow = 286
    ActiveWindow.ScrollRow = 284
    ActiveWindow.ScrollRow = 281
    ActiveWindow.ScrollRow = 277
    ActiveWindow.ScrollRow = 275
    ActiveWindow.ScrollRow = 273
    ActiveWindow.ScrollRow = 270
    ActiveWindow.ScrollRow = 268
    ActiveWindow.ScrollRow = 266
    ActiveWindow.ScrollRow = 264
    ActiveWindow.ScrollRow = 261
    ActiveWindow.ScrollRow = 259
    ActiveWindow.ScrollRow = 257
    ActiveWindow.ScrollRow = 255
    ActiveWindow.ScrollRow = 252
    ActiveWindow.ScrollRow = 250
    ActiveWindow.ScrollRow = 246
    ActiveWindow.ScrollRow = 239
    ActiveWindow.ScrollRow = 237
    ActiveWindow.ScrollRow = 232
    ActiveWindow.ScrollRow = 230
    ActiveWindow.ScrollRow = 228
    ActiveWindow.ScrollRow = 226
    ActiveWindow.ScrollRow = 223
    ActiveWindow.ScrollRow = 221
    ActiveWindow.ScrollRow = 217
    ActiveWindow.ScrollRow = 214
    ActiveWindow.ScrollRow = 210
    ActiveWindow.ScrollRow = 208
    ActiveWindow.ScrollRow = 210
    ActiveWindow.ScrollRow = 214
    ActiveWindow.ScrollRow = 223
    ActiveWindow.ScrollRow = 230
    ActiveWindow.ScrollRow = 235
    ActiveWindow.ScrollRow = 241
    ActiveWindow.ScrollRow = 243
    ActiveWindow.ScrollRow = 248
    ActiveWindow.ScrollRow = 250
    ActiveWindow.ScrollRow = 252
    Range("AC263").Select
    Application.CutCopyMode = False
    ActiveCell.FormulaR1C1 = "=CORREL(R[-261]C2:RC2,R[-261]C[-26]:RC[-26])"
    Range("AC264").Select
    ActiveWindow.ScrollColumn = 19
    ActiveWindow.ScrollColumn = 20
    ActiveWindow.ScrollColumn = 21
    ActiveWindow.ScrollColumn = 22
    ActiveWindow.ScrollColumn = 23
    ActiveWindow.ScrollColumn = 24
    ActiveWindow.ScrollColumn = 25
    ActiveWindow.ScrollColumn = 26
    Range("AC263").Select
    Selection.AutoFill Destination:=Range("AC263:AZ263"), Type:=xlFillDefault
    Range("AC263:AZ263").Select
    Selection.AutoFill Destination:=Range("AC263:AZ1610"), Type:=xlFillDefault
    Range("AC263:AZ1610").Select
End Sub

0 个答案:

没有答案