Thursday, November 19, 2009

Ye duniya agar mil bhi jaye to....

Yeh Mehloon,Yeh Takhto,Yeh Taajon Ki Duniya,
Yeh Insaan Key Dushman Samaajon Ki Duniya,
Yeh Daulat Key Bhookey Riwazon Ki Duniya,
Yeh Duniya Agar Mil Bhi Jaye To Kya Hai

Har Eik Jism Ghayal,Har Eik Rooh Pyaasi,
Nigahoon Mein Uljhan,Diloon Mein Udaasi,
Yeh Duniya Hai Ya Aalam-e-Badhawasi,
Yeh Duniya Agar Mil Bhi Jaye To Kya Hai

Yahaan Eik Khiloona Hai Insaan Ki Hasti,
Yeh Basti Hai Murda Paraston Ki Basti,
Yahaan To Jeevan Se Hai Maut Sasti,
Yeh Duniya Agar Mil Bhi Jaye To Kya Hai

Jawaani Bhatakti Hai Badkaar Ban Kar,
Jawaan Jism Sajtey Hein Bazaar Ban Kar,
Yahaan Pyaar Hota Hai Beopaar Ban Kar,
Yeh Duniya Agar Mil Bhi Jaye To Kya Hai

Yeh Duniya Jahaan Aadmi Kuch Nahi Hai,
Wafa Kuch Nahi,Doosti Kuch Nahi Hai,
Yahaan Pyaar Ki Qadr Hi Kuch Nahi Hai,
Yeh Duniya Agar Mil Bhi Jaye To Kya Hai

Jala Du Isey,Phoonk Daloo Yeh Duniya.
Meray Saamney Sey Hata Loo Yeh Duniya,
Tumhari Hai Tum Hi Sanmbhaloo Yeh Duniya,
Yeh Duniya Agar Mil Bhi Jaye To Kya Hai
Yeh Duniya Agar Mil Bhi Jaye To Kya Hai

Tuesday, October 27, 2009

Issues in life of ppl --- zindagi main bahut load, pareshani. Still ppl njoi. Dont learn frm mistakes. Dont even want to pay for the mistakes. Just want somehow those probs to vanish. Even by putting those on others names. Still complaints nd more complaints. Somehow thgs turn for better. Do we ever leave thgs bcoz we assess ourselves n realise tat wat we r getting is far more than our worth? NO, tat will b foolishness..aint!! just grab opportunities n shrug off the probs, issues n make urself happy.

Friday, April 17, 2009

Restrain and Refrain

re⋅straint   /rɪˈstreɪnt/ –noun 1. a restraining action or influence: freedom from restraint.
2. Sometimes, restraints. a means of or device for restraining, as a harness for the body.
3. the act of restraining, holding back, controlling, or checking.
4. the state or fact of being restrained; deprivation of liberty; confinement.
5. constraint or reserve in feelings, behavior, etc.


--------------------------------------------------------------------------------

re⋅frain1   /rɪˈfreɪn/ Show Spelled Pronunciation [ri-freyn] Show IPA
–verb (used without object) 1. to abstain from an impulse to say or do something (often fol. by from): I refrained from telling him what I thought.

–verb (used with object) 2. Archaic. to curb.


--------------------------------------------------------------------------------



Well quite related words but I think the two have a basic difference: Former being an external force and latter pointing to the internal force. Its by force and by choice thing. Ppl want to do so many things as soon as they get a chance - at the first available option. Ppl want to be liberated, throw away any shackles but are restrained by the society, the family, the religion and what not. But give them the chance and take away the conscience and they will do it.

Some ppl understand the reasons and refrain from a number of stuffs because they want to do things which they believe in. Ppl may ask how can they believe that what they are not doing is not right because they haven't experienced it and one should not believe on others words. But if one really wants to understand things, I believe it doesn't require the hands on experience always.

There is another group which refrains from stuffs because it is their in their brains...it has been stuffed down without any analysis.

Manipulation

Manipulation of ppl - the brain wash.

The manipulators always try to attack the point where ppl/masses are weakest so that they are not able to question a lot about it. They put the facts in such a way that the ppl are bound to think the way they want them to. Ppl show that the life is to be utilized for the service of certain things like GOD and for this even if they need to lay down lives or take lives, they should go ahead and do it. But who are these GODs regarding whom these manipulators are talking. Are these the real God who always want peace and harmony and righteous thinking or are these the artificially created ones who cater to the thoughts of the manipulators in such a way that these manipulators are successful in fulfilling their heinous plans and taking away the life, the prestige, the respect of their opponents!!!

Monday, April 13, 2009

The winds of change

http://www.fsa.gov.uk/pubs/other/turner_review.pdf

http://www.laitman.com/2008/10/the-financial-crisis-an-analysis/

http://en.wikipedia.org/wiki/List_of_entities_involved_in_2007-2008_financial_crises

Report card for Politicians

Well I believe all the things are judged by the progress made in a period of time. This is judged either through the performance in exams or through the progress report of the project which displays how much of the project has been completed.

In India, the biggest project that is the Five year plan and the budgets are not reviewed as regularly as they should be. Y shouldn't every year a report card of the project be placed in the parliament and available for the public scrutiny? All the projects that are promised in budgets with all the financials should be placed with all the relevant progress and the money expended displayed in it. May be the budget has all of this but they are not displayed in the right manner to give the public the right view. So I think there should be a dedicated progress report card displaying the progresses made and the reasons for delay and what are the steps that are being taken to avoid them in future.

Sunday, February 15, 2009

PYTHON

Its not about python, the reptile but a very high level programming language Python :)

http://www.python.org/ says
Python is a dynamic object-oriented programming language that can be used for many kinds of software development. It offers strong support for integration with other languages and tools, comes with extensive standard libraries, and can be learned in a few days. Many Python programmers report substantial productivity gains and feel the language encourages the development of higher quality, more maintainable code

What is dynamic object oriented programming language?

As per the publication http://jeffsutherland.com/papers/Rans/OOlanguages.pdf it is :
A project commenced at Xerox PARC in the early 70z with the aim of creating the quintessential dynamic object oriented language. This is one which allows new classes, objects and behaviouf to be appended on the fly by representing the class hierarchy, objects and methods of a program as meta-data at run-time.
Also,
dynamic programming language
Refers to a language that requires less rigid coding on the part of the programmer. It typically features "dynamic typing," which gives the programmer more freedom to pass parameters at runtime without having to define them beforehand. A dynamic language may also perform some amount of self checking at runtime, which would normally be done ahead of time in a compilation stage. Although a dynamic language offers runtime flexibility and is generally easier to program, it does not eliminate the programmer's responsibility for understanding the interactions that will take place.

Convert to Machine Code at Runtime
The term may also refer to interpreted languages in general, which convert source code or bytecode to machine language at runtime, as well as to just-in-time compilation, the process of compiling the program the moment before it is executed.

Dynamic and Non-Dynamic Examples
Numerous languages fall into the dynamic category, including JavaScript, VBScript, Lisp, Perl, PHP, Python, Ruby and Smalltalk. Examples of languages that are not dynamic are C/C++, Java, COBOL and FORTRAN. See dynamic, interpreter and JIT compiler.


Nice one is http://visualwikipedia.com/en/Object-oriented_programming_language

Some useful sites for python which I found useful as I start to learn python are:

http://code.activestate.com/recipes/146847/
http://koichitamura.blogspot.com/2008/06/various-ways-to-integrate-python-and-c.html
http://svn.python.org/projects/ctypes/tags/ctypes-1.0.2/
http://snippets.dzone.com/tag/python
http://starship.python.net/crew/theller/ctypes/

Sunday, February 08, 2009

Hypocrisy

This is what I read when I check dictionary.com for hypocrisy.

hy⋅poc⋅ri⋅sy 
–noun, plural -sies. 1. a pretense of having a virtuous character, moral or religious beliefs or principles, etc., that one does not really possess.
2. a pretense of having some desirable or publicly approved attitude.
3. an act or instance of hypocrisy.


When ppl expect others to treat them in certain fashion and they themselves treat others in not the same fashion, I think it is a genuine case of hypocrisy. People think others should try to make them happy, think about their scenarios, their problems and be considerate about them but do they themselves do the same when they talk to the same person from whom they expect so much? No is the answer in majority of cases. For such people having the thought to be cared for is hypocrisy I think.


From wikipedia::::

Psychology of hypocrisy
In psychology, hypocritical behavior is closely related to the fundamental attribution error: individuals are more likely to explain their own actions by their environment, yet they attribute the actions of others to 'innate characteristics', thus leading towards judging others while justifying ones' own actions.
Also, some people genuinely fail to recognize that they have character faults which they condemn in others. This is called psychological projection. This is self-deception rather than deliberate deception of other people. In other words, "psychological hypocrisy" is usually interpreted by psychological theorists to be an unconscious defense mechanism rather than a conscious act of deception, as in the more classic connotation of hypocrisy. People understand vices which they are struggling to overcome or have overcome in the past. Efforts to get other people to overcome such vices may be sincere. There may be an element of hypocrisy as well if the actors do not readily admit to themselves or to others how far they are or have been subject to these vices.

A Common Fallacy
It is a common fallacy to accuse someone of being a hypocrite to disprove their argument. This can be known as an ad hominem attack.


This ad hominem attack must have been faced by a large number of ppl. I have seen people restricting others from going to pubs and drinking but they themselves drink, may be in close company of few friends. But, should they drink if they want to restrict others from doing the same. Even in lob, I have seen ppl expecting others to understand them but not taking the pain to understand y similar thing happened with others and they say "lob is the ultimate reason for human existence".

Ppl want others to care for them but do they deserve it?

Persons who believe in certain principles and dont agree with certain other principles but feel proud of calling themselves the follower of a certain culture are also in a way hypocrites. If we dont believe in certain aspects we should say that we dont agree with certain things and we should change them. Not because society expects us to be sth we silently accept things...but if one takes pride in being something, he/she should try to abide by it fully, even if it is painful to him/her. But does it mean hard core followers of religions are right in doing what they do because they believe in these? A bit of confusion here but if people who teach religion to these people teach it the right way, I think there will not be any such confusion. People are misguided and if one wants others to follow what he/she is doing then he/she must have full understanding of the reasons and the implications of it.

Monday, December 01, 2008

Online FIR filing

Y can't we have online FIR filing system in India for petty crimes like pickpocetting/loss of purse etc?
Even today if we lose a purse, we have to feed 100-200 rs to file and FIR and we need the FIR for even getting a sim blocked. So y not simplify the system for public's benifit. In case a person needs the FIR for blocking of sim and other related activites he/she can file it online. In addition to this, we can have the regular filing as well.
For this one needs to have a valid ID card. For this, it is required that all the govt bodies issuing such ID cards (viz driving license, PAN card, ration cards, Passport number, Visa number etc) needs to be integrated online so that one can choose the issuing body and the ID card from the govt body's database directly. It will require a lot of database to be put in place.

Thursday, November 13, 2008

what happens when there is a small hole in a dam and that too in the deep? The force of water gushing out of this is so huge that it seems as if the water wants to tear this hole into a cavity. Result, the areas around the corners of the hole feel extremely high stress and may eventually give in.

wat happens to ppl who have been restrained to do certain things in life but have a willingness to do it? Well if the restrain is too big, the desire may keep on building(may sometime spill over the restrain). If someday the person finds a small opening through this restrain the person will try to use this opening with such ferosity that even the person does not know what she/he has lost bcoz of the usage of the opening.

There are game watchers and players watching the game. The watchers try to assosciate themselves with the players and wish for the corresponding players win. There are a few players who as well watch the game. They may support some players as other watchers. They may also keep on learning things to play better. Suppose there is a group of players watching the game and except one others pass the wall and get on the other side of game and start playing in the game? What will the only player watching the game feel............a moving surge to get into the game at the slightest opportunity??

Friday, September 12, 2008

CollateCsv

Public Sub AlignDate()
Dim X() As Variant
Dim shtArr() As Integer
Dim smallest_date As Date
Dim largest_date As Date
Dim FwdFill As Boolean
Dim BusDays As Boolean
Dim inputDate As Boolean
Sheets(3).Activate
Cells.ClearContents
ActiveWindow.FreezePanes = False
On Error Resume Next
Start:
If Sheet1.FileTypecsv.Value Then
FileType = Sheet1.FileTypecsv.Caption
mulSel = True
X = Application.GetOpenFilename(filefilter:="CSV Files,*.csv", _
MultiSelect:=True, Title:="File(s) to be aligned")
'Tests the variable X to see if it is valid
If UBound(X) = 0 Then Exit Sub
ReDim shtArr(1)
shtArr(1) = 1
If (MsgBox("Would you like to input min and max dates for alignment?", vbYesNo) = vbYes) Then
inputDate = False
Dim temp_smallest_date As Date
Dim temp_largest_date As Date
temp_smallest_date = minDateCSV(X())
temp_largest_date = maxDateCSV(X())
smallest_date = Application.InputBox("Enter min date(mm/dd/yyyy)", "Date Entry", , 250, 75, "", , 2)
If smallest_date = False Then Exit Sub
largest_date = Application.InputBox("Enter max date(mm/dd/yyyy)", "Date Entry", , 250, 75, "", , 2)
If largest_date = False Then Exit Sub
If temp_smallest_date < smallest_date Then smallest_date = temp_smallest_date
If temp_largest_date > largest_date Then largest_date = temp_largest_date
Else
Application.ScreenUpdating = False
inputDate = True
smallest_date = minDateCSV(X())
largest_date = maxDateCSV(X())
End If
ElseIf Sheet1.FileTypexls.Value Then
MsgBox "Still working on Excel file handling. Please use this tool for csv only."
Exit Sub
FileType = Sheet1.FileTypexls.Caption
mulSel = False
Target = Application.GetOpenFilename(filefilter:=FileType & " Files,*." & FileType, _
MultiSelect:=mulSel, Title:="File to be aligned")
If Target = False Then Exit Sub
ReDim X(1) As Variant
X(1) = Target
smallest_date = minDateXL(X(), shtArr())
largest_date = maxDateXL(X(), shtArr())
Else
MsgBox Prompt:="Select a File Type First", Buttons:=vbCritical
Exit Sub
End If
Dim fileName As String
fileName = ThisWorkbook.Name
currfileName = ThisWorkbook.Name
Application.ScreenUpdating = False
For Y = 1 To UBound(X)
Workbooks.Open X(Y)
currfileName1 = ActiveWorkbook.Name
Workbooks(currfileName1).Sheets(1).Copy After:=Workbooks(currfileName).Sheets(2 + Y)
Windows(currfileName1).Close
Next
X(1) = ActiveWorkbook.FullName

Windows(currfileName).Activate
Sheets(3).Activate
Cells("A3").Select
Dim range_len As Integer
Range("A1").Value = "Asset:"
Range("A2").Value = "date"
range_len = DateDiff("d", smallest_date, largest_date)
Range("A3").Value = smallest_date
Range("A3").Select
Selection.AutoFill Destination:=Range("A3:A" & range_len + 3), Type:=xlFillDefault
last_column = 2
Sheets(3).Activate
Dim datelocal As String
datelocal = Cells(row, 1).Value
For files2handle = 4 To ActiveWorkbook.Sheets.Count
Sheets(files2handle).Activate
Cells.End(xlEnd).Select
next_last_column = ActiveCell.Column
Range(Cells(1, ActiveCell.Column), Cells(2, 2)).Select
Selection.Copy
Sheets(3).Activate
Cells(1, last_column).Activate
ActiveCell.PasteSpecial (xlPasteAll)
Cells(3, last_column).Select
last_column = last_column + next_last_column - 1
Next

Sheets(3).Activate
Dim mat_row As Integer
For row = 3 To range_len + 3
Sheets(3).Activate
next_last_column = 1
last_column = 2
Dim test_val As Date
test_val = Cells(row, 1).Value
On Error Resume Next
For files2handle = 4 To ActiveWorkbook.Sheets.Count
last_column = last_column + next_last_column - 1
Sheets(files2handle).Activate
Cells.End(xlEnd).Select
next_last_column = ActiveCell.Column
Range("A1").Select
Cells.Find(What:=test_val, After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
If ActiveCell.row <> 1 Then
mat_row = ActiveCell.row
Cells(mat_row, 1).Activate
Range(Cells(mat_row, 2), Cells(mat_row, next_last_column)).Copy
Sheets(3).Activate
Cells(row, last_column).Activate
ActiveCell.PasteSpecial xlPasteAll
End If
done:

Next
Next
Sheets(3).Select
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Replace What:="", Replacement:="NA", LookAt:=xlWhole, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Range("B3").Select
Sheets(4).Select
For i = 4 To ActiveWorkbook.Sheets.Count
Sheets(i).Select False
Next
Application.DisplayAlerts = False
ActiveWindow.SelectedSheets.Delete
Application.DisplayAlerts = True
Sheets(2).Select
Application.ScreenUpdating = False
If Sheet1.FwdFillYes.Value Then
FwdFill = True
ElseIf Sheet1.FwdFillNo.Value Then
FwdFill = False
Else
MsgBox Prompt:="Select Whether to forward fill or not", Buttons:=vbCritical
Exit Sub
End If
If Sheet1.BusDaysYes.Value Then
BusDays = True
ElseIf Sheet1.BusDaysNo.Value Then
BusDays = False
Else
MsgBox Prompt:="Select Whether to have only business days or not", Buttons:=vbCritical
Exit Sub
End If




Sheets(3).Select
Range("B1").Select
Dim lastRow As Integer
lastRow = Selection.End(xlDown).row
Range("A1").Select
Dim lastCol As Integer
lastCol = Selection.End(xlToRight).Column
If FwdFill Then
Dim previousRow As Integer
Dim previousCol As Integer
previousRow = 0
'Cells.Find(What:="NA", After:=ActiveCell, LookIn:=xlValues, LookAt _
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
'While (ActiveCell.row <= lastRow And (ActiveCell.row > previousRow) Or _
(ActiveCell.row = previousRow And ActiveCell.Column > previousCol))
For row = 1 To lastRow
For col = 2 To lastCol
Cells(row, col).Select
If (ActiveCell.Value = "NA") Then
previousRow = ActiveCell.row
previousCol = ActiveCell.Column
If (IsNumeric(ActiveCell.Offset(-1, 0).Value)) Then
ActiveCell.Value = ActiveCell.Offset(-1, 0).Value
End If
End If
'Cells.Find(What:="NA", After:=ActiveCell, LookIn:=xlValues, LookAt _
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
Next
Next
End If
'den:
Range("A1").Select
'On Error Resume Next
If BusDays Then
Range("A1").Select
'Dim i As Integer
For i = 1 To lastRow
If (IsDate(Cells(i, 1).Value)) Then
If (DatePart("w", Cells(i, 1).Value) = 1 Or DatePart("w", Cells(i, 1).Value) = 7) Then
Rows(i & ":" & i).Select
Selection.Delete Shift:=xlUp
i = i - 1
End If
End If
Next
End If
Application.ScreenUpdating = True
Sheets(3).Select
Range("B3").Select
Cells.EntireColumn.AutoFit
Range("B3").Select
ActiveWindow.FreezePanes = True
Exit Sub






























Application.ScreenUpdating = True
If (DateDiff("d", smallest_date, largest_date) <= 0) Then
MsgBox Prompt:="Issue with data. Max date can not be less than or Equal to Min date. Check!!", Buttons:=vbCritical
Exit Sub
End If
If MsgBox("Date Range:- " & smallest_date & " To " & largest_date, vbOKCancel) = vbCancel Then
Exit Sub
End If
Call alignFiles(X(), smallest_date, largest_date, FwdFill, BusDays, fileName)
Windows(fileName).Activate
If Sheet1.CollDataYes.Value Then
If Sheet1.BusDaysYes.Value = True Then
If inputDate = True Then
For Z = 4 To ActiveWorkbook.Sheets.Count
If Z = 4 Then
Sheets(Z).Activate
Cells.Copy
Sheets(3).Activate
Range("A1").PasteSpecial (xlPasteAll)
Else
Sheets(Z).Activate
Range("B1").Select
Application.CutCopyMode = False
Range("IV1").Select
Selection.End(xlToLeft).Select
Range(Selection, "B1").Select
Range(Selection, Selection.End(xlDown)).Copy
Sheets(3).Activate
Range("A1").Select
Selection.End(xlToRight).Offset(0, 1).Select
ActiveSheet.Paste
End If
Next
Sheets(3).Activate
If IsDate(ActiveSheet.Range("A2").Value) Then
Range("B2").Select
Else
Range("B3").Select
End If
Cells.EntireColumn.AutoFit
ActiveWindow.FreezePanes = True
Else
MsgBox "Data Can not be Collated if date range has been given as input by user"
End If
Else
MsgBox "Data can be collated only if OnlyBusinessDays is True"
End If
Else
Sheets("Run").Range("A4").Select
End If
Application.DisplayAlerts = False
For Z = 4 To ActiveWorkbook.Sheets.Count
Sheets(4).Delete
Next
Application.DisplayAlerts = True
Application.ScreenUpdating = True
'If Sheet1.CollDataNo Or Not (inputDate) Then
Sheets("Run").Activate
'End If
End Sub
Private Function minDateCSV(X() As Variant) As Date
Dim smallDates As Date
Dim smallDate As Date
For Y = 1 To UBound(X)
Workbooks.Open X(Y)
Sheets(1).Activate
' Assumption: The Csv file has atleast one line of header and the date is in the 1st column itself. Phew!wat a relief
If IsDate(ActiveSheet.Range("A2").Value) Then
smallDates = ActiveSheet.Range("A2").Value
Else
'If the date is not in the A2 then it is definitely in A3.
smallDates = ActiveSheet.Range("A3").Value
End If
If Y > 1 Then
If (DateDiff("d", smallDates, smallDate) > 0) Then
smallDate = smallDates
End If
Else
smallDate = smallDates
End If
ActiveWorkbook.Close
Next
minDateCSV = smallDate
End Function
Private Function maxDateCSV(X() As Variant) As Date
Dim largeDates As Date
Dim largeDate As Date
Dim sheet_index As Integer
For Y = 1 To UBound(X)
Workbooks.Open X(Y)
Sheets(1).Activate
' Assumption: The Csv file has more than two lines of input and the date is in column A
' and the data is continuous
largeDates = ActiveSheet.Range("A1").End(xlDown).Value
If Y > 1 Then
If (DateDiff("d", largeDates, largeDate) < 0) Then
largeDate = largeDates
End If
Else
largeDate = largeDates
End If
ActiveWorkbook.Close
Next
maxDateCSV = largeDate
End Function

Private Sub alignFiles(X() As Variant, smallest_date As Date, largest_date As Date, FwdFill As Boolean, BusDays As Boolean, fileName As String)
smallest_value = smallest_date
largest_value = largest_date
sheet_index = 1
tdate = smallest_value
'Populating NA and aligning the data
For Y = 1 To UBound(X)
'Workbooks.Open X(Y)
'fileName1 = ActiveWorkbook.Name
For sheet_index = 1 To ActiveWorkbook.Sheets.Count
row = Row_Col(sheet_index)
col = 1
tdate = smallest_value
If row = 0 Then
GoTo x2
End If
Do Until tdate > largest_value
If row = 65537 Then
GoTo x2:
End If
If Sheets(sheet_index).Cells(row, col).Value <= tdate And Sheets(sheet_index).Cells(row, col).Value <> "" Then
GoTo X:
'Ignoring Saturdays and Sundays
Else 'If (DatePart("w", tdate) <> 1 And DatePart("w", tdate) <> 7) Then
Sheets(sheet_index).Cells(row, col).EntireRow.Insert
Sheets(sheet_index).Cells(row, col) = tdate
Sheets(sheet_index).Activate
Sheets(sheet_index).Range(Cells(row, 2), Cells(row, _
Cells(row - 1, 1).End(xlToRight).Column)).Value = "NA"
End If
X:
If (tdate = Sheets(sheet_index).Cells(row, col).Value) Or DatePart("w", tdate) = 1 Or DatePart("w", tdate) = 7 Then
tdate = DateAdd("d", 1, tdate)
End If
If DatePart("w", tdate) <> 1 And DatePart("w", tdate) <> 7 Then
row = row + 1
End If
Loop
x2:
Next
'On Error GoTo den
Range("B1").Select
Dim lastRow As Integer
lastRow = Selection.End(xlDown).row
Range("A1").Select
Dim lastCol As Integer
lastCol = Selection.End(xlToRight).Column
If FwdFill Then
Dim previousRow As Integer
Dim previousCol As Integer
previousRow = 0
'Cells.Find(What:="NA", After:=ActiveCell, LookIn:=xlValues, LookAt _
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
'While (ActiveCell.row <= lastRow And (ActiveCell.row > previousRow) Or _
(ActiveCell.row = previousRow And ActiveCell.Column > previousCol))
For row = 1 To lastRow
For col = 2 To lastCol
Cells(row, col).Select
If (ActiveCell.Value = "NA") Then
previousRow = ActiveCell.row
previousCol = ActiveCell.Column
If (IsNumeric(ActiveCell.Offset(-1, 0).Value)) Then
ActiveCell.Value = ActiveCell.Offset(-1, 0).Value
End If
End If
'Cells.Find(What:="NA", After:=ActiveCell, LookIn:=xlValues, LookAt _
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
Next
Next
End If
'den:
Range("A1").Select
'On Error Resume Next
If BusDays Then
Range("A1").Select
Dim i As Integer
For i = 1 To lastRow
If (IsDate(Cells(i, 1).Value)) Then
If (DatePart("w", Cells(i, 1).Value) = 1 Or DatePart("w", Cells(i, 1).Value) = 7) Then
Rows(i & ":" & i).Select
Selection.Delete Shift:=xlUp
i = i - 1
End If
End If
Next
Workbooks(fileName1).Sheets(1).Copy After:=Workbooks(fileName).Sheets(2 + Y)
Windows(fileName1).Activate
Range("A1").Select
End If
Next
End Sub
Private Function Row_Col(i) As Integer
Dim row, col As Integer
row = 1
col = 1
Do Until Sheets(i).Cells(row, col).Value = ""
If IsDate(Sheets(i).Cells(row, col).Value) Then
Row_Col = row
Exit Function
Else
row = row + 1
End If
Loop
End Function
Private Function minDateXL(X() As Variant, shtArr() As Integer) As Date
Dim smallDates As Date
Dim smallDate As Date
For Y = 1 To UBound(X)
Workbooks.Open X(Y)
For sheet_index = 1 To ActiveWorkbook.Sheets.Count
Sheets(sheet_index).Activate
If (MsgBox("Do you want to include the tab " & ActiveSheet.Name & " in alignment process?", vbYesNo) = vbNo) Then
GoTo hmmm
End If
' Assumption: The Csv file has atleast one line of header and the date is in the 1st column itself. Phew!wat a relief
If IsDate(ActiveSheet.Range("A2").Value) Then
smallDates = ActiveSheet.Range("A2").Value
Else
'If the date is not in the A2 then it is definitely in A3.
smallDates = ActiveSheet.Range("A3").Value
End If
If Y > 1 Then
If (DateDiff("d", smallDates, smallDate) > 0) Then
smallDate = smallDates
End If
Else
smallDate = smallDates
End If
hmmm:
Next
ActiveWorkbook.Close
Next
minDateXL = smallDate
End Function
Private Function maxDateXL(X() As Variant, shtArr() As Integer) As Date
Dim largeDates As Date
Dim largeDate As Date
For Y = 1 To UBound(X)
Workbooks.Open X(Y)
For sheet_index = 1 To ActiveWorkbook.Sheets.Count
Sheets(sheet_index).Activate
If (MsgBox("Do you want to include the tab " & ActiveSheet.Name & " in alignment process?", vbYesNo) = vbNo) Then
GoTo hmmm
End If
' Assumption: The Csv file has more than two lines of input and the date is in column A
' and the data is continuous
largeDates = ActiveSheet.Range("A1").End(xlDown).Value
If Y > 1 Then
If (DateDiff("d", largeDates, largeDate) < 0) Then
largeDate = largeDates
End If
Else
largeDate = largeDates
End If
hmmm:
Next
ActiveWorkbook.Close
Next
maxDateXL = largeDate
End Function

Wednesday, August 20, 2008

VBA-Alignment of dates

Public Sub AlignDate()
Dim X() As Variant
Dim shtArr() As Integer
Dim smallest_date As Date
Dim largest_date As Date
Dim fwdFill As Boolean
Application.ScreenUpdating = False
Start:
If Sheet1.OptionButton1.Value Then
fileType = Sheet1.OptionButton1.Caption
mulSel = True
X = Application.GetOpenFilename(filefilter:=fileType & " Files,*." & fileType, _
MultiSelect:=mulSel, Title:="File(s) to be aligned")
'Tests the variable X to see if it is valid
If UBound(X) = 0 Then Exit Sub
ReDim shtArr(1)
shtArr(1) = 1
smallest_date = minDateCSV(X(), shtArr())
largest_date = maxDateCSV(X(), shtArr())
ElseIf Sheet1.OptionButton2.Value Then
fileType = Sheet1.OptionButton2.Caption
mulSel = False
Target = Application.GetOpenFilename(filefilter:=fileType & " Files,*." & fileType, _
MultiSelect:=mulSel, Title:="File(s) to be aligned")
If Target = False Then Exit Sub
ReDim X(1) As Variant
X(1) = Target
smallest_date = minDateXL(X(), shtArr())
largest_date = maxDateXL(X(), shtArr())
Else
MsgBox Prompt:="Select a File Type First", Buttons:=vbCritical
Exit Sub
End If
If Sheet1.OptionButton3.Value Then
fwdFill = True
ElseIf Sheet1.OptionButton4.Value Then
fwdFill = False
Else
MsgBox Prompt:="Select Whether to forward fill or not", Buttons:=vbCritical
Exit Sub
End If
MsgBox smallest_date
Application.ScreenUpdating = True
MsgBox largest_date
If (DateDiff("d", smallest_date, largest_date) <= 0) Then
MsgBox Prompt:="Issue with data. Max date can not be less than or Equal to Min date. Check!!", Buttons:=vbCritical
Exit Sub
End If
If MsgBox("Date Range:- " & smallest_date & " To " & largest_date, vbOKCancel) = vbCancel Then
Exit Sub
End If
Call alignFiles(X(), smallest_date, largest_date, fwdFill)
End Sub
Private Function minDateCSV(X() As Variant, shtArr() As Integer) As Date
Dim smallDates As Date
Dim smallDate As Date
For Y = 1 To UBound(X)
Workbooks.Open X(Y)
Sheets(1).Activate
' Assumption: The Csv file has atleast one line of header and the date is in the 1st column itself. Phew!wat a relief
If IsDate(ActiveSheet.Range("A2").Value) Then
smallDates = ActiveSheet.Range("A2").Value
Else
'If the date is not in the A2 then it is definitely in A3.
smallDates = ActiveSheet.Range("A3").Value
End If
If Y > 1 Then
If (DateDiff("d", smallDates, smallDate) > 0) Then
smallDate = smallDates
End If
Else
smallDate = smallDates
End If
ActiveWorkbook.Close
Next
minDateCSV = smallDate
End Function
Private Function maxDateCSV(X() As Variant, shtArr() As Integer) As Date
Dim largeDates As Date
Dim largeDate As Date
Dim sheet_index As Integer
For Y = 1 To UBound(X)
Workbooks.Open X(Y)
Sheets(1).Activate
' Assumption: The Csv file has more than two lines of input and the date is in column A
' and the data is continuous
largeDates = ActiveSheet.Range("A1").End(xlDown).Value
If Y > 1 Then
If (DateDiff("d", largeDates, largeDate) < 0) Then
largeDate = largeDates
End If
Else
largeDate = largeDates
End If
ActiveWorkbook.Close
Next
maxDateCSV = largeDate
End Function
Private Sub alignFiles(X() As Variant, smallest_date As Date, largest_date As Date, fwdFill As Boolean)
smallest_value = smallest_date
largest_value = largest_date
sheet_index = 1
tdate = smallest_value
'Populating NA and aligning the data
For Y = 1 To UBound(X)
Workbooks.Open X(Y)
For sheet_index = 1 To ActiveWorkbook.Sheets.Count
row = Row_Col(sheet_index)
col = 1
tdate = smallest_value
If row = 0 Then
GoTo x2
End If
Do Until tdate > largest_value
If row = 65537 Then
GoTo x2:
End If
If Sheets(sheet_index).Cells(row, col).Value <= tdate And Sheets(sheet_index).Cells(row, col).Value <> "" Then
GoTo X:
'Ignoring Saturdays and Sundays
ElseIf (DatePart("w", tdate) <> 1 And DatePart("w", tdate) <> 7) Then
Sheets(sheet_index).Cells(row, col).EntireRow.Insert
Sheets(sheet_index).Cells(row, col) = tdate
Sheets(sheet_index).Activate
For count_col = 2 To Sheets(sheet_index).Cells(row - 1, 2).End(xlToRight).Column
If fwdFill Then
If IsNumeric(Sheets(sheet_index).Cells(row - 1, count_col).Value) Then
Sheets(sheet_index).Cells(row, count_col).Value = _
Sheets(sheet_index).Cells(row - 1, count_col).Value
Else
Sheets(sheet_index).Cells(row, count_col).Value = "NA"
End If
Else
Sheets(sheet_index).Cells(row, count_col).Value = "NA"
End If
Next
End If
X:
If (tdate = Sheets(sheet_index).Cells(row, col).Value) Or DatePart("w", tdate) = 1 Or DatePart("w", tdate) = 7 Then
tdate = DateAdd("d", 1, tdate)
End If
If DatePart("w", tdate) <> 1 And DatePart("w", tdate) <> 7 Then
row = row + 1
End If
Loop
x2:
Next
Next
End Sub
Private Function Row_Col(i) As Integer
Dim row, col As Integer
row = 1
col = 1
Do Until Sheets(i).Cells(row, col).Value = ""
If IsDate(Sheets(i).Cells(row, col).Value) Then
Row_Col = row
Exit Function
Else
row = row + 1
End If
Loop
End Function
Private Function minDateXL(X() As Variant, shtArr() As Integer) As Date
Dim smallDates As Date
Dim smallDate As Date
For Y = 1 To UBound(X)
Workbooks.Open X(Y)
For sheet_index = 1 To ActiveWorkbook.Sheets.Count
Sheets(sheet_index).Activate
If (MsgBox("Do you want to include the tab " & ActiveSheet.Name & " in alignment process?", vbYesNo) = vbNo) Then
GoTo hmmm
End If
' Assumption: The Csv file has atleast one line of header and the date is in the 1st column itself. Phew!wat a relief
If IsDate(ActiveSheet.Range("A2").Value) Then
smallDates = ActiveSheet.Range("A2").Value
Else
'If the date is not in the A2 then it is definitely in A3.
smallDates = ActiveSheet.Range("A3").Value
End If
If Y > 1 Then
If (DateDiff("d", smallDates, smallDate) > 0) Then
smallDate = smallDates
End If
Else
smallDate = smallDates
End If
hmmm:
Next
ActiveWorkbook.Close
Next
minDateXL = smallDate
End Function
Private Function maxDateXL(X() As Variant, shtArr() As Integer) As Date
Dim largeDates As Date
Dim largeDate As Date
For Y = 1 To UBound(X)
Workbooks.Open X(Y)
For sheet_index = 1 To ActiveWorkbook.Sheets.Count
Sheets(sheet_index).Activate
If (MsgBox("Do you want to include the tab " & ActiveSheet.Name & " in alignment process?", vbYesNo) = vbNo) Then
GoTo hmmm
End If
' Assumption: The Csv file has more than two lines of input and the date is in column A
' and the data is continuous
largeDates = ActiveSheet.Range("A1").End(xlDown).Value
If Y > 1 Then
If (DateDiff("d", largeDates, largeDate) < 0) Then
largeDate = largeDates
End If
Else
largeDate = largeDates
End If
hmmm:
Next
ActiveWorkbook.Close
Next
maxDateXL = largeDate
End Function

VBA-Netting

Sub netting()
'
' Macro netting
'
'
'------------------------------------------------------------------------------------------
'Prepairing the tabs to receive the data. The older data from the tabs will be cleared out.
'------------------------------------------------------------------------------------------
Sheets("Full").Select 'Clearing the Contents of Full tab
Cells.Select
Selection.ClearContents
Selection.ClearContents 'Cleared
Sheets("Validation").Select 'Clearing the Validation Tab
Range("A2:Q2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.ClearContents
Selection.ClearContents
Sheets("Long").Select 'Clearing the contents of Long tab
Cells.Select
Selection.ClearContents
Selection.ClearContents 'Cleared
Sheets("Short").Select 'Clearing the contents of Short tab
Cells.Select
Selection.ClearContents
Selection.ClearContents 'Cleared
Sheets("Short_Re").Select 'Clearing the contents of Short_Re tab
Cells.Select
Selection.ClearContents
Selection.ClearContents 'Cleared
Sheets("Long_Re").Select 'Clearing the contents of Long_Re tab
Cells.Select
Selection.ClearContents
Selection.ClearContents 'Cleared
Sheets("Result").Select 'Clearing the contents of Result tab
Cells.Select
Selection.ClearContents
Selection.ClearContents 'Cleared
Sheets("Input").Select 'Copying Header from the Input Tab
Rows("1:1").Select
Selection.Copy
Sheets("Result").Select
Range("A1").Select
ActiveSheet.Paste 'Pasted the header in the Result Tab
Selection.Font.Bold = True
Range("Y1").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.ClearContents 'Clearing the end part of header after column Y
Range("A1").Select
Sheets("Input").Select
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range("A1:X1").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Sheets("Full").Select
Range("A1").Select
ActiveSheet.Paste ' Copying all the data to Full tab. We will use this tab and not the Input tab now
'------------------------------------------------------------------------------------------------
'The data from the Full tab will be moved to Short and Long tab based on the LONG/SHORT Column
'------------------------------------------------------------------------------------------------
Sheets("Full").Select
Selection.AutoFilter Field:=21, Criteria1:="Short" 'Selecting the short trades
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Short").Select
Range("A1").Select
ActiveSheet.Paste
Sheets("Full").Select
Selection.AutoFilter Field:=21, Criteria1:="Long" 'Selecting the long trades
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Long").Select
Range("A1").Select
ActiveSheet.Paste
'------------------------------------------------------------------------------------------
'Calculating the coupon in column L from the PAYFORMULA in Long Tab
'------------------------------------------------------------------------------------------
Columns("L:L").Select
Selection.Insert shift:=xlToRight
Range("L1").Select
ActiveCell.FormulaR1C1 = "Coupon"
Range("L2").Select
ActiveCell.FormulaR1C1 = "=LEFT(RC[6],SEARCH(""%"",RC[6])-1)"
Range("A1").Select
lastRow = Selection.End(xlDown).Row
Range("L2").Select
Selection.AutoFill Destination:=Range("L2:L" & lastRow)
Range("L2:L" & lastRow).Select
'------------------------------------------------------------------------------------------
'Calculating Residual Maturity=Maturity-today in Column AC in Long Tab
'------------------------------------------------------------------------------------------
Range("AC1").Select
ActiveCell.FormulaR1C1 = "Residual Maturity"
Range("AD1").Select
ActiveCell.FormulaR1C1 = "Maturity"
Range("AD2").Select
ActiveCell.FormulaR1C1 = _
"=DATE(LEFT(RC[-10],4),MID(RC[-10],5,2),RIGHT(RC[-10],2))"
Range("AC2").Select
ActiveCell.FormulaR1C1 = "=RC[1]-TODAY()"
Range("AC2").Select
Selection.NumberFormat = "General"
Range("AC2:AD2").Select
Selection.AutoFill Destination:=Range("AC2:AD" & lastRow)
ActiveSheet.Calculate
Range("AC2:AD" & lastRow).Copy
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
xlNone, SkipBlanks:=False, Transpose:=False
Sheets("Short").Select
'------------------------------------------------------------------------------------------
'Calculating the coupon in column L from the RECFORMULA in Short Tab
'------------------------------------------------------------------------------------------
Columns("L:L").Select
Selection.Insert shift:=xlToRight
Range("L1").Select
ActiveCell.FormulaR1C1 = "Coupon"
Range("L2").Select
ActiveCell.FormulaR1C1 = "=LEFT(RC[-1],SEARCH(""%"",RC[-1])-1)"
Range("A1").Select
lastRow = Selection.End(xlDown).Row
Range("L2").Select
Selection.AutoFill Destination:=Range("L2:L" & lastRow)
Range("L2:L" & lastRow).Select
'------------------------------------------------------------------------------------------
'Calculating Residual Maturity=Maturity-today in Column AC in Short Tab
'------------------------------------------------------------------------------------------
Range("AC1").Select
ActiveCell.FormulaR1C1 = "Residual Maturity"
Range("AD1").Select
ActiveCell.FormulaR1C1 = "Maturity"
Range("AD2").Select
ActiveCell.FormulaR1C1 = _
"=DATE(LEFT(RC[-10],4),MID(RC[-10],5,2),RIGHT(RC[-10],2))"
Range("AC2").Select
ActiveCell.FormulaR1C1 = "=RC[1]-TODAY()"
Range("AC2").Select
Selection.NumberFormat = "General"
Range("AC2:AD2").Select
Selection.AutoFill Destination:=Range("AC2:AD" & lastRow)
ActiveSheet.Calculate
Range("AC2:AD" & lastRow).Copy
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
xlNone, SkipBlanks:=False, Transpose:=False
Range("L14").Select
Range("A1").Select
Range("A2:AD2").Select
'Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
'--------------------------------------------------------------------------------------------------------
'Sorting the data in the Short tab. The sort order is by PAYNotional,ResidualMaturity and then by Coupon
'--------------------------------------------------------------------------------------------------------
Selection.Sort Key1:=Range("U2"), Order1:=xlAscending, Key2:=Range _
("AC2"), Order2:=xlAscending, Key3:=Range("L2"), Order3:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:= _
xlTopToBottom, DataOption1:=xlSortNormal, DataOption2:=xlSortTextAsNumbers _
, DataOption3:=xlSortNormal
Sheets("Long").Select
Range("O10").Select
Range("A2:AD2").Select
'Selection.End(xlToRight).Select
Range(Selection, Selection.End(xlDown)).Select
'--------------------------------------------------------------------------------------------------------
'Sorting the data in the Long tab. The sort order is by PAYNotional,ResidualMaturity and then by Coupon
'--------------------------------------------------------------------------------------------------------
Selection.Sort Key1:=Range("U2"), Order1:=xlAscending, Key2:=Range _
("AC2"), Order2:=xlAscending, Key3:=Range("L2"), Order3:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:= _
xlTopToBottom, DataOption1:=xlSortNormal, DataOption2:=xlSortTextAsNumbers _
, DataOption3:=xlSortNormal
'-------------------------------------------------------------------------------------------------------------
'The netting process starts here.
'The Long and Short tab gets netted for exact maturity and rest trades are marked as Not Netted.
'These not netted trades will be netted off once again in the LOng_Re and Short_Re tabs using the maturity band
'-------------------------------------------------------------------------------------------------------------
Application.ScreenUpdating = False
Dim longCoupon, shortCoupon, longNotional, shortNotional, longMaturity, shortMaturity, longPV01, shortPV01 As Double
Dim shortResidualMaturity, longResidualMaturity As Double
Dim bigL, smallL, notnettedPoint, bigloopCount, smallloopCount, finalFlag, sm_i As Integer
Dim vali_Row_Ct As Integer
finalFlag = 0
Sheets("Short").Select
Range("A1").Select
shortRows = ActiveCell.End(xlDown).Row
Sheets("Long").Select
Range("A1").Select
longrows = ActiveCell.End(xlDown).Row
bigloopCount = longrows
smallloopCount = shortRows
notnettedPoint = 2
Sheets(1).Select
vali_Row_Ct = 2
For bigL = 2 To bigloopCount
For smallL = notnettedPoint To smallloopCount
If (bigL = bigloopCount And finalFlag = 1) Then
For sm_i = smallL To smallloopCount
Sheets("Short").Activate
Range("Z" & sm_i).Value = "N"
Next sm_i
Exit For
End If
Sheets("Long").Activate
longCoupon = Range("L" & bigL).Value + 0
longNotional = Range("U" & bigL).Value
longMaturity = Range("J" & bigL).Value
longResidualMaturity = Range("AC" & bigL).Value
Sheets("Short").Activate
shortCoupon = Range("L" & smallL).Value + 0
shortNotional = Range("U" & smallL).Value
shortMaturity = Range("J" & smallL).Value
shortResidualMaturity = Range("AC" & smallL).Value
If (longNotional = shortNotional) Then
If (longResidualMaturity = shortResidualMaturity) Then
If ((longCoupon - shortCoupon) > 0.15) Then
Sheets("Short").Activate
Range("z" & smallL).Value = "N"
notnettedPoint = smallL + 1
ElseIf ((shortCoupon - longCoupon) > 0.15) Then
Sheets("Long").Activate
Range("z" & bigL).Value = "N"
If (bigL = bigloopCount) Then
Sheets("Short").Activate
Range("z" & smallL).Value = "N"
Else
Exit For
End If
Else
Sheets("Long").Activate
longPV01 = Range("Y" & bigL).Value
Sheets("Short").Activate
shortPV01 = Range("Y" & smallL).Value
If ((longPV01 - shortPV01) > 0) Then
Sheets("Long").Select
Range("z" & bigL).Value = "Y"
Range("AA" & bigL).Value = Sheets("Short").Range("B" & smallL).Value
'--------------------------For Validation --------------------------------------
Sheets("Validation").Range("A" & vali_Row_Ct).Value = Sheets("Long").Range("B" & bigL).Value
Sheets("Validation").Range("B" & vali_Row_Ct).Value = Sheets("Short").Range("B" & smallL).Value
Sheets("Validation").Range("I" & vali_Row_Ct).Value = Sheets("Long").Range("L" & bigL).Value
Sheets("Validation").Range("J" & vali_Row_Ct).Value = Sheets("Short").Range("L" & smallL).Value
Sheets("Validation").Range("M" & vali_Row_Ct).Value = Sheets("Long").Range("AC" & bigL).Value
Sheets("Validation").Range("N" & vali_Row_Ct).Value = Sheets("Short").Range("AC" & smallL).Value
vali_Row_Ct = vali_Row_Ct + 1
'-------------------------------------------------------------------------------
If (bigL = bigloopCount) Then
finalFlag = 1
Else
Exit For
End If
Else
Sheets("Short").Select
Range("z" & smallL).Value = "Y"
Range("AA" & smallL).Value = Sheets("Long").Range("B" & bigL).Value
notnettedPoint = smallL + 1
'--------------------------For Validation --------------------------------------
Sheets("Validation").Range("A" & vali_Row_Ct).Value = Sheets("Short").Range("B" & smallL).Value
Sheets("Validation").Range("B" & vali_Row_Ct).Value = Sheets("Long").Range("B" & bigL).Value
Sheets("Validation").Range("I" & vali_Row_Ct).Value = Sheets("Short").Range("L" & smallL).Value
Sheets("Validation").Range("J" & vali_Row_Ct).Value = Sheets("Long").Range("L" & bigL).Value
Sheets("Validation").Range("M" & vali_Row_Ct).Value = Sheets("Short").Range("AC" & smallL).Value
Sheets("Validation").Range("N" & vali_Row_Ct).Value = Sheets("Long").Range("AC" & bigL).Value
vali_Row_Ct = vali_Row_Ct + 1
'-------------------------------------------------------------------------------
If (bigL = bigloopCount) Then
finalFlag = 1
Else
Exit For
End If
End If
End If
Else
If ((longResidualMaturity - shortResidualMaturity) > 0) Then
Sheets("Short").Activate
Range("z" & smallL).Value = "N"
notnettedPoint = smallL + 1
Else
Sheets("Long").Activate
Range("z" & bigL).Value = "N"
If (bigL = bigloopCount) Then
Sheets("Short").Activate
Range("z" & smallL).Value = "N"
Else
Exit For
End If
End If
End If
Else
If ((longNotional - shortNotional) > 0) Then
Sheets("Short").Range("Z" & smallL).Value = "N"
notnettedPoint = smallL + 1
Else
Sheets("Long").Range("Z" & bigL).Value = "N"
If (bigL = bigloopCount) Then
Sheets("Short").Activate
Range("z" & smallL).Value = "N"
Else
Exit For
End If
End If
End If
Next smallL
Next bigL
'----------------------------------------------------------------------------
' we need to do the netting of band of maturity after the full netting is over.
'
'------------------------------------------------------------------------------
Sheets("Long").Select
Range("A1:AD1").Select
Selection.AutoFilter
Range("K1").Select
Selection.End(xlToRight).Select
Range("Z1").Select
Selection.AutoFilter Field:=26, Criteria1:="N"
Cells.Select
Range("S1").Activate
Selection.Copy
Sheets("Long_Re").Select
Cells.Select
Application.CutCopyMode = False
Selection.ClearContents
'-------------------------------------------------------------------------------
' Copying not netted trades from Long tab to Long_Re tab
'-------------------------------------------------------------------------------
Sheets("Long").Select
Selection.Copy
Sheets("Long_Re").Select
Range("A1").Select
ActiveSheet.Paste
Sheets("Short").Select
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range("A1:AD1").Select
Application.CutCopyMode = False
Selection.AutoFilter
Selection.AutoFilter Field:=26, Criteria1:="N"
Cells.Select
Selection.Copy
'-------------------------------------------------------------------------------
'Copying not netted trades from Short tab to Short_Re tab
'-------------------------------------------------------------------------------
Sheets("Short_Re").Select
Cells.Select
Application.CutCopyMode = False
Selection.ClearContents
Sheets("Short").Select
Selection.Copy
Sheets("Short_Re").Select
Range("A1").Select
ActiveSheet.Paste
'--------------------------------------------------------------------------------
Sheets("Short_Re").Select
Range("A1").Select
shortRows = ActiveCell.End(xlDown).Row
Sheets("Long_Re").Select
Range("A1").Select
longrows = ActiveCell.End(xlDown).Row
bigloopCount = longrows
smallloopCount = shortRows
notnettedPoint = 2
For bigL = 2 To bigloopCount
For smallL = notnettedPoint To smallloopCount
Sheets("Long_Re").Activate
longCoupon = Range("L" & bigL).Value + 0
longNotional = Range("U" & bigL).Value
longMaturity = Range("J" & bigL).Value
longNettedFlag = Range("Z" & bigL).Value
longResidualMaturity = Range("AC" & bigL).Value
Sheets("Short_Re").Activate
shortCoupon = Range("L" & smallL).Value + 0
shortNotional = Range("U" & smallL).Value
shortMaturity = Range("J" & smallL).Value
shortNettedFlag = Range("Z" & smallL).Value
shortResidualMaturity = Range("AC" & smallL).Value
If (longNettedFlag = "Y") Then
Exit For
End If
If (longNettedFlag = "N") Then
If (shortNettedFlag = "N") Then
If (longNotional = shortNotional) Then
If ((longCoupon - shortCoupon) > 0.15) Then
Sheets("Short_Re").Activate
'Range("z" & smallL).Value = "N"
'notnettedPoint = smallL + 1
ElseIf ((shortCoupon - longCoupon) > 0.15) Then
Sheets("Long_Re").Activate
Range("z" & bigL).Value = "N"
'Exit For
Else
Sheets("Long_Re").Activate
longPV01 = Range("Y" & bigL).Value
Sheets("Short_Re").Activate
shortPV01 = Range("Y" & smallL).Value
Range("AT" & smallL).Value = "Diff is less than 0.15"
If (longResidualMaturity < 30) Then
Exit For
ElseIf (shortResidualMaturity < 30) Then
'notnettedPoint = smallL + 1
ElseIf ((longResidualMaturity < 365 And shortResidualMaturity < 365 _
And (((longResidualMaturity - shortResidualMaturity) <> 0) _
Or ((shortResidualMaturity - longResidualMaturity) <> 0))) _
_
Or (longResidualMaturity > 365 And shortResidualMaturity > 365 _
And (((longResidualMaturity - shortResidualMaturity) <> 0) _
Or ((shortResidualMaturity - longResidualMaturity) <> 0)))) Then
If ((longPV01 - shortPV01) > 0) Then
Sheets("Long_Re").Select
Range("z" & bigL).Value = "Y"
Range("AA" & bigL).Value = Sheets("Short_Re").Range("B" & smallL).Value
Sheets("Short_Re").Select
Range("z" & smallL).Value = ""
'notnettedPoint = smallL + 1
'--------------------------For Validation --------------------------------------
Sheets("Validation").Range("A" & vali_Row_Ct).Value = Sheets("Long_Re").Range("B" & bigL).Value
Sheets("Validation").Range("B" & vali_Row_Ct).Value = Sheets("Short_Re").Range("B" & smallL).Value
Sheets("Validation").Range("I" & vali_Row_Ct).Value = Sheets("Long_Re").Range("L" & bigL).Value
Sheets("Validation").Range("J" & vali_Row_Ct).Value = Sheets("Short_Re").Range("L" & smallL).Value
Sheets("Validation").Range("M" & vali_Row_Ct).Value = Sheets("Long_Re").Range("AC" & bigL).Value
Sheets("Validation").Range("N" & vali_Row_Ct).Value = Sheets("Short_Re").Range("AC" & smallL).Value
vali_Row_Ct = vali_Row_Ct + 1
'-------------------------------------------------------------------------------
Exit For
Else
Sheets("Short_Re").Select
Range("z" & smallL).Value = "Y"
Range("AA" & smallL).Value = Sheets("Long_Re").Range("B" & bigL).Value
Sheets("Long_Re").Select
Range("z" & bigL).Value = ""
'notnettedPoint = smallL + 1
'--------------------------For Validation --------------------------------------
Sheets("Validation").Range("A" & vali_Row_Ct).Value = Sheets("Short_Re").Range("B" & smallL).Value
Sheets("Validation").Range("B" & vali_Row_Ct).Value = Sheets("Long_Re").Range("B" & bigL).Value
Sheets("Validation").Range("I" & vali_Row_Ct).Value = Sheets("Short_Re").Range("L" & smallL).Value
Sheets("Validation").Range("J" & vali_Row_Ct).Value = Sheets("Long_Re").Range("L" & bigL).Value
Sheets("Validation").Range("M" & vali_Row_Ct).Value = Sheets("Short_Re").Range("AC" & smallL).Value
Sheets("Validation").Range("N" & vali_Row_Ct).Value = Sheets("Long_Re").Range("AC" & bigL).Value
vali_Row_Ct = vali_Row_Ct + 1
'-------------------------------------------------------------------------------
Exit For
End If
End If
End If
Else
If ((longNotional - shortNotional) > 0) Then
'Sheets("Short_Re").Range("Z" & smallL).Value = "N"
'notnettedPoint = smallL + 1
Else
'Sheets("Long_Re").Range("Z" & bigL).Value = "N"
Exit For
End If
End If
Else
'notnettedPoint = smallL + 1
End If
End If
Next
Next
'--------------------------------------------------------------------------------------
' Data needs to be moved from the Long and Short tabs to the Result tab
'--------------------------------------------------------------------------------------
Sheets("Long_Re").Select
Range("A1:AA1").Select
Selection.AutoFilter
Selection.AutoFilter Field:=26, Criteria1:="N"
'Range(Selection, Selection.End(xlToRight)).Select
Range("A1:AA1").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Sheets("Result").Select
Range("A2").Select
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
xlNone, SkipBlanks:=False, Transpose:=False
Rows("2:2").Select
Selection.Delete shift:=xlUp
Sheets("Short_Re").Select
Range("A1:AA1").Select
Selection.AutoFilter
Selection.AutoFilter Field:=26, Criteria1:="N"
'Range(Selection, Selection.End(xlToRight)).Select
Range("A1:AA1").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Sheets("Result").Select
Range("A65536").Select
Selection.End(xlUp).Select
Selection.Offset(1, 0).PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
xlNone, SkipBlanks:=False, Transpose:=False
Range("Z2").Select
row_delete = Selection.End(xlDown).Row + 1
If (row_delete >= 65536) Then
row_delete = 2
End If
Cells(row_delete, 1).Select
Range(Selection, "AB" & row_delete).Select
Application.CutCopyMode = False
Selection.Cut
Rows("1:1").Select
ActiveSheet.Paste
Cells(row_delete, 1).Select
Range(Selection, "AB" & row_delete).Select
Selection.Delete shift:=xlUp
Rows("1:1").Select
Selection.Font.Bold = True
Range("A1").Select
'----------------------------------------Validation Sheet Checks ----------------------------
Sheets("Validation").Select
Range("C2").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-2],Input!C2:C24,23,0)"
Range("D2").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-2],Input!C2:C24,23,0)"
Range("E2").Select
ActiveCell.FormulaR1C1 = "=RC[-2]+RC[-1]"
Range("F2").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-5],Input!C2:C10,9,0)"
Range("G2").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-5],Input!C2:C10,9,0)"
Range("H2").Select
ActiveCell.FormulaR1C1 = _
"=DATE(LEFT(RC[-2],4),MID(RC[-2],5,2),RIGHT(RC[-2],2))-DATE(LEFT(RC[-1],4),MID(RC[-1],5,2),RIGHT(RC[-1],2))"
Range("H3").Select
Range("C2:H2").Select
If vali_Row_Ct > 3 Then Selection.AutoFill Destination:=Range("C2:H" & vali_Row_Ct - 1)
Range("K2").Select
ActiveCell.FormulaR1C1 = "=IF(ABS(RC[-2]-RC[-1])<0.15,""Ok"",""Check"")"
Range("L2").Select
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-11],Input!C[-10]:C[2],13,0)-VLOOKUP(RC[-10],Input!C[-10]:C[2],13,0)"
Range("K2:L2").Select
If vali_Row_Ct > 3 Then Selection.AutoFill Destination:=Range("K2:L" & vali_Row_Ct - 1)
Range("O2").Select
ActiveCell.FormulaR1C1 = _
"=IF(RC[-1]>365,IF(ABS(RC[-1]-RC[-2])<31,""ok"",""check""),if(rc[-1]>30,IF(ABS(RC[-1]-RC[-2])<8,""Ok"",""Check""),IF(RC[-1]=RC[-2],""Ok"",""Check"")))"
Range("O2").Select
If vali_Row_Ct > 3 Then Selection.AutoFill Destination:=Range("O2:O" & vali_Row_Ct - 1)
ActiveSheet.Calculate
Range("A1").Select
'----------------------------------Validation in results sheets ------------------------------
Application.ScreenUpdating = True
Sheets("Result").Select
Range("A1").Select
fin_row = Selection.End(xlDown).Row
Range("Z1").Select
ActiveCell.FormulaR1C1 = "PV01 Orig"
Range("AA1").Select
ActiveCell.FormulaR1C1 = "PV01 Check with Orig"
Range("AB1").Select
ActiveCell.FormulaR1C1 = "Check for inclusion of netted deals"
Range("AC1").Select
ActiveCell.FormulaR1C1 = "Zone Orig"
Range("AD1").Select
ActiveCell.FormulaR1C1 = "Zone Check"
Range("Z2").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-24],Input!C[-24]:C[-2],23,0)"
Range("AA2").Select
ActiveCell.FormulaR1C1 = "=RC[-2]-RC[-1]"
Range("AB2").Select
ActiveCell.FormulaR1C1 = _
"=IF(ISERROR(VLOOKUP(RC[-26],Validation!C[-27],1,0)),""Ok"",""Check"")"
Range("AB3").Select
Range("AC2").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-27],Input!C[-27]:C[-6],22,0)"
Range("AD2").Select
ActiveCell.FormulaR1C1 = "=RC[-6]=RC[-1]"
Range("Z2:AD2").Select
Selection.AutoFill Destination:=Range("Z2:AD" & fin_row)
ActiveSheet.Calculate
Range("A1").Select
End Sub

Tuesday, July 29, 2008

Excel to csv Vb

Dim fso
Set fso = CreateObject("scripting.filesystemobject")
Dim fldr
Dim extn
Dim flename
Dim oxlApp
Set oxlApp =CreateObject("Excel.Application")
Dim oxlWB
Set fldr = fso.GetFolder("Folder path")
oxlApp.Visible = True
For Each flename In fldr.Files
extn = Right(flename.Name, 4)
If extn = ".xls" Then
Set oxlWB = oxlApp.Workbooks.Open(flename)
for j = 1 to oxlWB.Sheets.Count
oxlWB.Sheets(j).Activate
Dim Name
Name = oxlWB.Sheets(j).Name
Name = "Folder Path" & Name & ".csv"
oxlWB.SaveAs Name, -4158
Next
oxlWB.Close False
End If
Next
oxlApp.Quit
Set oxlApp = Nothing

Monday, June 16, 2008

--

There are ppl who tend to be curious by nature and there are ppl who are curiosity solver. There is a bit of difference between the two seemingly close groups. One will raise question and lot of questions. The other will try to give an answe to these. Many a times we get to know sth and then have some doubt. Certain ppl will immediately go to smbdy who gave them the initial knowledge regarding the subject and will get the matter clarified/ask the question there and will ask for an explanation. Some ppl will look for the answers themselves and will try not to ask anybdy regarding these. Then, they may get an answer or may not. Both these kinds have their benefit and drawbacks. The first group knows the answer more easily and quickly and probably the discussion with some knowledgeable person helps them get a better understanding. The other group will know all the hurdles while looking for the solution. Sometimes this grp will not have a solution and will know abt a lot more problems. But, the time will be definitely large.

Monday, June 02, 2008

Does every thing which bothers us really a part of our thought process or we are made to think about these things by other factors? Are we really concerned about certain things or are we responding to an external stimuli?
For example, are we really concerned when a boy goes down in a well or are we just responding to the sensationalization of the news being fed down our throat by the all powerful media?
Do all the ppl taking out a march/protest/dharna really believe in its cause? Ya many poor come to these because they are lured by leaders to come. But, are the so called educated ones support the causes because these are right as per their conscience? Or are there conscience skewed because of external factors like friends, society, media, etc.? We keep on hearing that India has not made much of development/has made sufficient development and we will find a lot of ppl supporting both part of it. But, how many percentage of both these groups really have cared to get the data on their own to validate their support? I hope majority does!!
There are a few things where one turns blind eye to a part of issue and raise a lot of concern to the other part of the same issue:
Politicans - they are in general bad ppl and they make huge amt of money and make undue advantage of their power and positions. PPl think they shd be removed but nobody is ready to take their place even if they are removed. The ppl who are ready to take their place are in the same category as the current set of politicians. So what will happend even if the current politicians go? The new set will be same only the faces will be changed!
Reservations: These should go as India has come too far and these are not at all useful in current scenario and are creating much problem. Well what about the reservations given by religion? It seems the priests post is 100% reserved.

Wednesday, May 28, 2008

Thoughts

Rent in powai -18k for a 2BHK last year, owner changes in a yr. New owner asks for 25k. Some corporate is ready to pay!!

Work in a I-Bank - Fill some data in some excel , graph it and then send to different ppl...wow, interesting high end work!!

Raw Petrol Price increases - Govt cant increase the price in mkt, the elections are near. Put a surcharge in the income tax => The common man travelling on bus is paying for a business man travelling in Merc.