1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673
| Public Record_Count As Integer
Public Sub RunIt(TimeFrom As String, TimeTo As String, timeName As String)
'Set Variables
Dim Celldata As String
'Column position in the destination sheet
Dim BondPosition(1 To 100) As String
Dim BondPositionRow As Integer
'Column position in the source sheet
Dim Inputrow() As String
Dim Datecheck As Integer
Dim Tempno As String
Dim LastRowColA As Integer
Dim LastRowinDestination As Integer
Dim MyDateString As String
Dim RowCount As Integer
Dim MyVar As String
Dim icount As Integer
Dim OutputCSV As String
Dim LDate As String
Dim LTime As String
Dim MyDirectory As String
Dim MyTime As String
Dim AddTime As String
Dim MyDate As String
Dim Control As Integer
Dim InData As String
Dim BondCol() As Integer
Dim CDPosition() As String
Dim Arraysize As Integer
Dim AssetType As String
Dim InTime As Boolean
Dim TimeBoundary As String
Dim HeaderRec(1 To 144) As String
Dim BondCount As Integer
Dim CDCount As Integer
Dim TextLine1 As String
Dim TextLine2 As String
Dim TextLine3 As String
Dim HeaderRow As Integer
Dim TimeofFile As String
Dim CopyofCpty As String
Dim InfoDisplay(1 To 200) As String
Dim Net_Amount_Price As Double
Dim Net_Amount_Nominal As Double
Dim Net_Amount_Accrued As Double
Dim Net_Amount_Price_Factor As Integer
Dim OutApp As Object
Dim OutMail As Object
Dim d As Date
Dim today As Long
' Set Variables
BondPositionRow = 2 'We want the copy to destination to start on second row
MyVar = "" 'Temporary variable to do stuff
'Clear down the destination workbook before starting
LastRowinDestination = Sheets("Destination").Range("A65536").End(xlUp).Row
If LastRowDestination = 0 Then LastRowDestination = 1
'Sheets("Destination").Range("A2:EZ" & Trim(Str(LastRowinDestination))).ClearContents
Sheets("Destination").Range("A2:EZ50").ClearContents
'Go to the Source worksheet and find out how many rows
Sheets("Source").Activate
LastRowColA = Range("A65536").End(xlUp).Row
ReDim Inputrow(LastRowColA) 'now have an array than hold all the lines in the file
LDate = Date ' get todays date
LTime = Time ' get the current time
For i = 1 To 144 'Get the data in to the right size array
HeaderRec(i) = Cells(1, 2 + i).Text
Sheets("Destination").Cells(1, (i)) = Trim(HeaderRec(i))
Next i
BondCount = 0
CDCount = 0
Sheets("Source").Activate
TimeofFile = "00_00"
MyTimeBoundary = 0
Dim todaytext As String
Dim todaydbl As Double
todaydbl = CDbl(Year(d) * 10000 + Month(d) * 100 + Day(d))
todaytext = todaydbl
For RowCount = 2 To LastRowColA 'loop round the number of lines
AssetType = Cells(RowCount, 7).Text ' read in the asset type
MyDate = Cells(RowCount, 1).Text ' read in the date
MyTime = Cells(RowCount, 2).Text ' read in the time
'AddTime = Mid(MyTime, 1, 2) + 1
'MyTime = AddTime & Mid(MyTime, 3, 8)
InTime = False
Arraysize = 33
ReDim BondCol(Arraysize)
ReDim CDPosition(Arraysize)
BondCol(1) = 3
BondCol(2) = 4
BondCol(3) = 5
BondCol(4) = 7
BondCol(5) = 8
BondCol(6) = 12
BondCol(7) = 14
BondCol(8) = 21
BondCol(9) = 22
BondCol(10) = 23
BondCol(11) = 25
BondCol(12) = 29
BondCol(13) = 30
BondCol(14) = 31
BondCol(15) = 32
BondCol(16) = 34
BondCol(17) = 35
BondCol(18) = 36
BondCol(19) = 37
BondCol(20) = 47
BondCol(21) = 49
BondCol(22) = 50
BondCol(23) = 51
BondCol(24) = 55
BondCol(25) = 57
BondCol(26) = 61
BondCol(27) = 73
BondCol(28) = 74
BondCol(29) = 106
BondCol(30) = 141
BondCol(31) = 142
BondCol(32) = 143
BondCol(33) = 144
Control = 1
For i = 1 To Arraysize 'Get the data in to the right size array
CDPosition(i) = Cells(RowCount, BondCol(i)).Value
Next i
'MyTime is the time on the trade extract
'LTime is the time of the network server
'TimeNo() is just a function that allows you to evaluate time
'The time limit on LTime has been adjusted by 15 minutes to allow trades entered upto the cut off date being included
'if not custumized time then base the time frame on date of run
If TimeFrom = " " Then
MsgBox ("wrong predefined time frame")
'If (TimeNo(MyTime) > TimeNo("18:01:00") And TimeNo(LTime) <= TimeNo("10:15:00")) Then
' InTime = True
' MyTimeBoundary = "10_00"
'End If
'If (TimeNo(MyTime) <= TimeNo("10:00:00") And TimeNo(LTime) <= TimeNo("10:15:00")) Then
' InTime = True
' MyTimeBoundary = "10_00"
'End If
'If (TimeNo(MyTime) <= TimeNo("12:00:00") And TimeNo(MyTime) > TimeNo("10:00:00")) Then
' If (TimeNo(LTime) <= TimeNo("12:15:00") And TimeNo(LTime) > TimeNo("10:15:00")) Then
' InTime = True '
' MyTimeBoundary = "12_00"
' End If
'End If
'If (TimeNo(MyTime) <= TimeNo("13:30:00") And TimeNo(MyTime) > TimeNo("12:00:00")) Then
' If (TimeNo(LTime) <= TimeNo("13:45:00") And TimeNo(LTime) > TimeNo("12:15:00")) Then
' InTime = True
' MyTimeBoundary = "13_30"
' End If
'
' End If
'If (TimeNo(MyTime) <= TimeNo("15:00:00") And TimeNo(MyTime) > TimeNo("13:30:00")) Then
' If (TimeNo(LTime) <= TimeNo("15:15:00") And TimeNo(LTime) > TimeNo("13:45:00")) Then
' InTime = True '
' MyTimeBoundary = "15_00"
' End If
'End If
'If (TimeNo(MyTime) <= TimeNo("18:10:00") And TimeNo(MyTime) > TimeNo("15:00:00")) Then
' If (TimeNo(LTime) <= TimeNo("18:15:00") And TimeNo(LTime) > TimeNo("15:15:00")) Then
' InTime = True
' MyTimeBoundary = "18_00"
' End If
'
'End If
'If (TimeNo(LTime) > TimeNo("18:15:00")) Then
' InTime = True
' MyTimeBoundary = "18_15"
'End If
'use the customized time frame
Else
'MsgBox ("customized time frame")
todaytext = Mid(LDate, 7, 4) & Mid(LDate, 4, 2) & Mid(LDate, 1, 2)
'if time from is after timeto we consider this is from yesterday
If TimeDo(TimeFrom) > TimeDo(TimeTo) Then
'then just check time for from
If MyDate < todaytext Then
If TimeDo(MyTime) > TimeDo(TimeFrom & ":00") Then
InTime = True
End If
Else
If (TimeDo(MyDate & MyTime) <= TimeDo(todaytext & TimeTo & ":00")) Then
InTime = True
End If
End If
Else
If TimeDo(MyDate & MyTime) > TimeDo(todaytext & TimeFrom & ":00") And (TimeDo(MyDate & MyTime) <= TimeDo(todaytext & TimeTo & ":00")) Then
InTime = True
End If
End If
End If
If InTime = True Then
' MyTimeBoundary = Replace(TimeFrom & "_" & TimeTo, ":", "_")
MyTimeBoundary = Replace(timeName, ":", "_")
' MsgBox (RowCount & " is in")
Else
'MsgBox (RowCount & " is NOT in time")
End If
TimeofFile = MyTimeBoundary
For icount = 1 To Arraysize
Celldata = CDPosition(icount) ' read in the value
Select Case icount ' Dependent upon position in array, no blanks
Case Is = 1
BondPosition(icount) = "A" 'TRN_NB - Trade Id
Case Is = 2
Select Case Celldata
Case Is = "New"
Celldata = "New"
Case Is = "Cancelled"
Celldata = "Delete"
Case Else
Celldata = "ERR"
End Select
BondPosition(icount) = "B" 'Last Action - New,Update,Cancel
InfoDisplay(RowCount) = Celldata
Case Is = 3
BondPosition(icount) = "C" 'Buy/Sell - Buy/Sell
InfoDisplay(RowCount) = InfoDisplay(RowCount) & " " & Celldata
Case Is = 4 ' determine Bond or CP
BondPosition(icount) = "E" 'Typology - Bond
MyVar = Celldata
Select Case MyVar
Case Is = "Bond"
Celldata = "Bond"
Case Is = "CP"
Celldata = "CP"
Case Else
Celldata = "CD"
End Select
Case Is = 5
BondPosition(icount) = "F" 'Client Investment ID
Select Case MyVar
Case Is = "Bond"
'BondPosition(icount) = "L" 'Security Code - ISIN
Celldata = ""
Case Else
End Select
Case Is = 6
BondPosition(icount) = "J" 'Exchange
Select Case MyVar
Case Is = "Bond"
'BondPosition(icount) = "S" 'Quantity - Notional
Celldata = ""
Case Else
End Select
Case Is = 7
BondPosition(icount) = "L" 'ISIN
Select Case MyVar
Case Is = "Bond"
'BondPosition(icount) = "T" 'Clean price - Price
'Celldata = ""
Case Else
End Select
Case Is = 8
BondPosition(icount) = "S" 'Quantity - Notional
Net_Amount_Nominal = Celldata
Select Case MyVar
Case Is = "Bond"
'BondPosition(icount) = "U" 'Accrued
Case Else
End Select
Case Is = 9
BondPosition(icount) = "T" 'Price
Net_Amount_Price = CDPosition(icount)
Select Case MyVar
Case Is = "Bond"
'BondPosition(icount) = "AB" 'Counterparty label - Broker
Case Else
End Select
Case Is = 10
BondPosition(icount) = "U" 'Accrued Interest
Net_Amount_Accrued = CDPosition(icount)
Select Case MyVar
Case Is = "Bond"
'BondPosition(icount) = "AC" 'Trade date - Transaction date
Case Else
End Select
Case Is = 11
BondPosition(icount) = "W" 'Commission Fees
Celldata = "0.0"
Case Is = 12
BondPosition(icount) = "AA" 'Net Amount
Net_Amount_Price_Factor = "100"
Celldata = Round(((Net_Amount_Nominal * Net_Amount_Price) / Net_Amount_Price_Factor) + Net_Amount_Accrued, 2)
Case Is = 13
BondPosition(icount) = "AB" 'Counterpart
Select Case MyVar
Case Is = "Bond"
'BondPosition(icount) = "AD" 'Settlement date - Settle date
Case Else
CopyofCpty = Celldata
End Select
Case Is = 14
BondPosition(icount) = "AC" 'Trade date - Transaction date
Select Case MyVar
Case Is = "Bond"
'BondPosition(icount) = "AG" 'Fixed field - Custodian Account - Fund-ID e.g.
'Celldata = "ESM1"
Case Else
End Select
Case Is = 15
BondPosition(icount) = "AD" 'Settle Date
Select Case MyVar
Case Is = "Bond"
'BondPosition(icount) = "AI" 'Strategy
'Celldata = "ESMDEFAULT"
Case Else
End Select
Case Is = 16
BondPosition(icount) = "AF" 'Settle Currency
Select Case MyVar
Case Is = "Bond"
'BondPosition(icount) = "EI" 'Contract Nb - Block ID
Case Else
End Select
Case Is = 17
BondPosition(icount) = "AG" 'Fixed field - Custodian Account - Fund-ID e.g. ESM1
If Celldata = "M_LBI" Or Celldata = "M_INVT_FEES" Then
Celldata = "ESM2"
Else
Celldata = "ESM1"
End If
Case Is = 18
BondPosition(icount) = "AI" 'Strategy
Celldata = "ESMDEFAULT"
Case Is = 19
BondPosition(icount) = "AN" 'Counterpart
If MyVar <> "Bond" Then
Celldata = CopyofCpty
End If
Case Is = 20
BondPosition(icount) = "AS" 'Maturity
If AssetType = "Bond" Then Celldata = ""
Case Is = 21
BondPosition(icount) = "AU" 'Interest Basis
'ACT/360,30/365,ACT/366,Actual/365,Actual/Actual
Select Case MyVar
Case Is = "Bond"
Celldata = ""
Case Else
MyDateString = Celldata
Select Case MyDateString
Case Is = "N A/A I"
Celldata = "ACT/ACT"
Case Is = "ACT/360"
Celldata = "ACT/360"
Case Is = "ACT/365"
Celldata = "Actual/365"
Case Is = "ACT/ACT"
Celldata = "Actual/Actual"
Case Else
Celldata = Celldata
End Select
End Select
Case Is = 22
BondPosition(icount) = "AV" 'Coupon Payment
'182DAYS,364DAYS,91DAYS,BI -ANNUAL,BI -MONTHLY,BI -MONTHLY,
'BI -WEEKLY,DAILY,IAM,LUNAR,MONTHLY,NONE,QUARTERLY,SEMI -ANNUAL,WEEKLY,YEARLY
Select Case MyVar
Case Is = "Bond"
Celldata = ""
Case Else
Select Case Celldata
Case Is = "1y"
Celldata = "YEARLY"
Case Is = "0od"
Celldata = "NONE"
Case Else
Celldata = Celldata
End Select
End Select
Case Is = 23
BondPosition(icount) = "AW" 'Interest Rate
If MyVar = "Bond" Then Celldata = ""
Case Is = 24
BondPosition(icount) = "BA" 'Spread
If MyVar = "Bond" Then Celldata = ""
Case Is = 25
BondPosition(icount) = "BC" 'Accrual Start date
Select Case MyVar
Case Is = "Bond"
Celldata = ""
Case Else
If InStr(1, Celldata, "/") <> 0 Then
MyDateString = Mid(Celldata, 7, 4)
MyDateString = MyDateString & Mid(Celldata, 4, 2) & Mid(Celldata, 1, 2)
Celldata = MyDateString
End If
End Select
Case Is = 26
BondPosition(icount) = "BG" 'First Coupon Date
Select Case MyVar
Case Is = "Bond"
Celldata = ""
Case Else
If InStr(1, Celldata, "/") <> 0 Then
MyDateString = Mid(Celldata, 7, 4)
MyDateString = MyDateString & Mid(Celldata, 4, 2) & Mid(Celldata, 1, 2)
Celldata = MyDateString
End If
End Select
Case Is = 27
BondPosition(icount) = "BS" 'Issue Date
Select Case MyVar
Case Is = "Bond"
Celldata = ""
Case Else
If InStr(1, Celldata, "/") <> 0 Then
MyDateString = Mid(Celldata, 7, 4)
MyDateString = MyDateString & Mid(Celldata, 4, 2) & Mid(Celldata, 1, 2)
Celldata = MyDateString
End If
End Select
Case Is = 28
BondPosition(icount) = "BT" 'Issue country
If MyVar = "Bond" Then Celldata = ""
Case Is = 29
BondPosition(icount) = "CZ" 'Reset Frequency
Select Case MyVar
Case Is = "Bond"
Celldata = ""
Case Else
MyDateString = Celldata
Select Case MyDateString
Case Is = "1y"
Celldata = "YEARLY"
Case Is = "0od"
Celldata = "NONE"
End Select
End Select
Case Is = 30
BondPosition(icount) = "EI" 'Block Id
Case Is = 31
BondPosition(icount) = "EJ" 'Security Description
If MyVar = "Bond" Then Celldata = ""
Case Is = 32
BondPosition(icount) = "EK" 'Issue Price
If MyVar = "Bond" Then Celldata = ""
Case Is = 33
BondPosition(icount) = "EL" 'Maturity Price
If MyVar = "Bond" Then Celldata = ""
End Select
If InTime Then
Sheets("Destination").Range(BondPosition(icount) & Trim(Str(BondPositionRow))) = Trim(Celldata)
End If
Next icount
If InTime Then
BondPositionRow = BondPositionRow + 1
If MyVar = "Bond" Then
BondCount = BondCount + 1
Else
CDCount = CDCount + 1
End If
End If
Next RowCount
'generate directory and filename from Date and Time - but this should be 10 12 15 18 files
'Check to see if the directory has been created for today, if not create it
OutputCSV = "M:\01_Murex\Citi\Citi Trade Extracts\" & Mid(LDate, 7, 4) & "_" & Mid(LDate, 4, 2) & "_" & Mid(LDate, 1, 2) 'This one
'OutputCSV = "H:\Citi Trade Extracts\" & Mid(LDate, 7, 4) & "_" & Mid(LDate, 4, 2) & "_" & Mid(LDate, 1, 2) 'For testing
' OutputCSV = "C:\" & Mid(LDate, 7, 4) & "_" & Mid(LDate, 4, 2) & "_" & Mid(LDate, 1, 2)
If Len(Dir(OutputCSV, vbDirectory)) = 0 Then
MkDir OutputCSV
End If
'Create the filename out of the time and append to the directory
If timeName = "18:15" Then
OutputCSV = OutputCSV & "\EFSFGCCA_EFSF_Summary_Trade_"
OutputCSV = OutputCSV & Mid(LDate, 7, 4)
OutputCSV = OutputCSV & Mid(LDate, 4, 2)
OutputCSV = OutputCSV & Mid(LDate, 1, 2) & ".csv"
Else
OutputCSV = OutputCSV & "\EFSFGCCA_EFSF_Trade_"
OutputCSV = OutputCSV & Mid(LDate, 7, 4)
OutputCSV = OutputCSV & Mid(LDate, 4, 2)
OutputCSV = OutputCSV & Mid(LDate, 1, 2) & "_" & TimeofFile & ".csv"
End If
Application.DisplayAlerts = False
'Now copy the trade file contents to a CSV file
'LastRowinDestination = Sheets("Destination").Range("A65536").End(xlUp).Row
If (BondCount > 0) Or (CDCount > 0) Then
LastRowinDestination = Sheets("Destination").Range("A1").End(xlDown).Row
Sheets("Destination").Range("A1:EO" & Trim(Str(LastRowinDestination))).Copy
Workbooks.Add
ActiveSheet.Paste
ActiveWorkbook.SaveAs Filename:= _
OutputCSV _
, FileFormat:=xlCSV, CreateBackup:=False
Application.DisplayAlerts = False
End If
' Display a message giving the user some feedback
If (BondCount > 0) Or (CDCount > 0) Then
TextLine1 = "A file has been created for " & MyTimeBoundary & ""
TextLine2 = "It contains " & Str(BondCount) & " Bonds and " & Str(CDCount) & " CD/CPs"
TextLine3 = "The file has been created - Press OK to continue"
ActiveWorkbook.Close ' Close the CSV file
Else
TextLine1 = "NO Trades so NO file created "
TextLine2 = "" & Str(BondCount) & " Bonds and " & Str(CDCount) & " CD/CPs" & "were found"
TextLine3 = "The file has NOT been created - Press OK to continue"
End If
If MsgBox(TextLine1 & vbCrLf & TextLine2 & vbCrLf & InfoDisplay(1) & vbCrLf & InfoDisplay(1) & vbCrLf & TextLine3, vbOKOnly, OutputCSV) = vbYes Then
InTime = False
Else
InTime = False
End If
Application.DisplayAlerts = True
End Sub
Public Function TimeNo(Time As String) As Long
TimeNo = CLng(Replace(Format(Time, "hhnnss"), ":", ""))
End Function
Public Function TimeDo(Time As String) As Double
TimeDo = CDbl(Replace(Time, ":", ""))
End Function |
Partager