Myplaceonnet

Sunday, September 11, 2011

link for regular expressions in vba

http://www.tmehta.com/regexp/add_code.htm

Friday, August 26, 2011

Levenshtein distance

Function Lev(s As String, t As String) As Variant
Dim i As Integer ' iterates through s
Dim j As Integer ' iterates through t
Dim s_i As String ' ith character of s
Dim t_j As String ' jth character of t
Dim cost As Integer ' cost
' Step 1
Dim n As Integer
n = Len(s)
'length of s
Dim m As Integer
m = Len(t)
'length of t
If n = 0 Then
Lev = m
End If
If m = 0 Then
Lev = n
End If
Dim d(0 To 10, 0 To 10) As Integer
' Step 2
For i = 0 To n
d(i, 0) = i
Next i
For j = 0 To m
d(0, j) = j
Next j
' Step 3
For i = 1 To n
s_i = Mid(s, i, 1)
' Step 4
For j = 1 To m
t_j = Mid(t, j, 1)
' Step 5
If s_i = t_j Then
cost = 0
Else
cost = 1
End If
' Step 6
d(i, j) = Application.WorksheetFunction.Min(Application.WorksheetFunction.Min((d((i - 1), j) + 1), (d(i, (j - 1)) + 1)), (d((i - 1), (j - 1)) + cost))
Next j
Next i
' Step 7
Lev = d(n, m) / Application.WorksheetFunction.Max(m, n)
End Function

Monday, March 14, 2011

Some interview Questions..

Interview Questions that are brain teasers that I encountered:
(read wip = what is probability)

1. x1,x2,x3 iid from roll of dice. wip that sum(w^xi)=0 where w is
complex cube root of 1.

2. Regression-x,y are financial time series. x=b1y+c1; y=b2x+c2. What
is b1/b2 approx.

3. Price of call when: sigma = 30% vs. E(sigma)=30%. which is
greater-(Ans: depends on curvature)

4. Early excercise of American call? whats better than early excercise
(Sell the call/stock)

5. Derive E(coin tosses for 1 head| Pr(success)=p). Do the same for 2
consecutive heads.

6. integrate (-inf to inf)(exp(-x^2) cos x) (Ans: Helps to know complex numbers)

7. What are eigen values of exp(A) where A is a matrix.

8. 10 Pirates with a ranks 1 to 10 have a loot of 10 coins. Assume
infinite intelligence and rational. Highest rank proposes division. If
accepted (>=50% including highest rank) they divide otherwise kill
highest rank. Whats the division. (Ans: start with two pirates and
work your way up).

9. 2D BM. (1,1) is starting point. WIP that you hit +ve x-axis before
-ve. (Ans: use symmetry of y-axis. final answer =3/4). Extend it to
arbitrary points.

10. An infinite matrix filled with +ve integers s.t. each integer
occurs atmost 10 times. Prove there exist i,j s.t aij>ij for some i,j
(Ans:Prove by contradiction. Use entries that are constrained to be
less than n i.e. ij10n for large n).

11. what is i^i where i^2=-1

12. If you can only go up or right from origin how many ways can you
reach (5,5).

13. Draw a graph of (1/(2-x))*exp(1/x).

14. You randomly cut a 1m long rod at 2 places. WIP that you can make
a triangle

15. A,B play a game. A picks a number between [1,10]. Gives it to B. B
pics [1,10] and adds it to the existing sum and gives back to A. The
person to first get 60 loses. Who wins.

16. C++: how do you allocate memory to an object.

Here are some slightly higher quality questions:
1. If the price of an European binary call is x what is the price of American binary.
2. If X and Y follow a Geometric Brownian motion show that X/Y also follows a GBM.
3. How do you create an arbitrage when the Put price is not a convex function of the strike.
4. Does short selling restriction change the put call prices in absence of trasaction costs.
5. WIP that on a infinite sequence of die throws you get 2 evens in a row before you get 3 or 5.
6. Can you create an event with a probability of m/n (a rational) with a fair coin.
7. If you have a fair die how would you estimate pi.
8. how would you replicate a digital option using vanillas.
9. Solve the OU process(mean reverting weiner process).

Interview Questions on Brownian Motion: I got them at a final round BB bank most of these are conceptual..

i. KL transformation on BM
ii. Explain local time.. Give the SDE satisfied by |B| or Tanakas formula
iii. Derive Focker Plank Equation.. Backward kolmogorov etc..
iv. Some thing to do with method of iterated images I didnt fully understand it, but it apparently gives the probablity that a BM will not hit two boundaries in a given time had no idea how to do it.
v. Questions on HJM model and on some mathematics behind it. Something about how the drift term represents correlation between two quantities.. I will post answers on it soon..

Tuesday, October 23, 2007

song

Wednesday, September 13, 2006

Antham song

This is a song in the movie Antham (అంతం) I particularly like the innocence of the lyrics written by Sirivennela and it wonderfully fits the tune of RD Burman. If you have trouble viewing the telugu script goto the view icon and click on the encoding button and click unicode

ఓ మైనా
నీ గానం నేవిన్నా
ఎటు వున్నా ఎటవాలు పాట వెంట రాన
కమ్మని గీతాలే పంపి రమ్మని పిలిచావే
మరి రావే ఇకనైనా
కొమ్మలనడిగానే ప్రతి రెమ్మన్ని వెతికానే
కనిపించవు కాస్తైనా
నీ కొసం వచ్చానే సావసం తెచ్చానే
ఏది రా మరి ఏ మూలున్నా

కమ్మని గీతాలే!!

ఎవరైనా చూసారా ఎప్పుడైనా
ఉదయాన కురిసే వన్నెల వాన
కరి మబ్బులాంటి నడి రేయి కరిగి కురిసింది కిరణాలుగా
ఒక్కొక తార చినుకల్లె జారి వెలిసింది తొలి కాంతిగా
కరి మబ్బులాంటి నడి రేయి కరిగి కురిసింది కిరణాలుగా
ఒక్కొక తార చినుకల్లే జారి వెలిసింది తొలి కాంతిగా
నీలాకాశంలో వెండి సముద్రంలా పొంగే

కమ్మని గీతాలే!!

నన్నేనా కోరుకుంది ఈ వరాల కూన
ఏలుకోనా కళ్ళ ముందు విందు ఈ క్షనానా
సీతాకోక చిలుక తీసుకుపో నీ వెనుక వనమంతా చూపించగా
ఆ మొక్క ఈ మొల్లక అన్ని తెలుసుగనక వివరించు ఇంచక్కగా
సీతకోక చిలుక తీసుకుపో నీ వెనుకు వనమంతా చూపించగా
ఆ మొక్క ఈ మొల్లక అన్ని తెలుసుగనక విరరించు ఇంచక్కగా
ఈ కారున్యంలో నీరెక్కేదిక్కై రానా

కమ్మని గీతాలే!!

Friday, August 11, 2006

Problem solving at Sangam

Here is an interesting problem:

There is a wierd man who goes to a noodle shop and orders noodle soup. He asks for exactly 100 noodles in his soup. Once his noodle soup arrives, he gets to work. He extracts two noodle ends from under the soup, ties a knot and lets it slip into the soup again. He does the above 100 times so that now all the noodle ends are tied.

Now he reaches his hand into the soup. What is the probability that he would extract a garland containing all the 100 noodles.


Well let me tell you why this problem is so interesting.

On the first glance if you were asked to guess what the probability would be what would you say? I would say that it is close to zero. Or it would be one in a million. If you thought like I did you couldn't be more wrong. (But if you didn't then hats off!). I left the problem for a long time and didn't attempt to solve it untill I showed it to Mr. DVS Ravikant over dinner at Sangam and within a minute he said: " Oh I see.. ". (Well you cant be JEE 13 for nothing)

So I decided to give it another try and I got the way to do it in about a day. I was surprised at the result: it was 8.87% !!

The point of telling the story is that if you have the right intuition of what is going on in the problem then you already solved the problem. The rest is routine algebra.

My intuition was that there are so many outcomes to the problem, i.e the end result of the knot tying can be one of the plethora of possibilities that can be realized. And I thought all are equally probable. But later I realized I was wrong. The fact is it is more probable that the man ends up with a 100 noodle garland than any of the other possible combinations(Can you guess why?).

Let me tell you another example(Its a cheeky problem. Don't curse me after you read the solution. Ravi thought it couldn't be solved, But I persisted on it for a while and then it struck me..)

A Pack of cards has 52 cards. You are in a dark room with this pack of cards. You have been told that inside the pack there are 42 cards facing down, 10 cards facing up. You have been asked to reorganize this pack of cards into two decks so that eack deck contains an equal number of cards that face up.

Remember you are in darkness and can't see. How will you do it?

Hint:(It was given so in the problem although I wouldn't call it a hint)
The two decks need not contain an equal number of cards.


Well Ravi and me were going over this again in sangam and it was quite obvious to Ravi right in the first sight that it cannot be split since no matter how you slpit the pack you can never ensure that there are equal number of cards facing up.

But then that is the problem isn't it?

I pondered on it for a while and then it struck me. You can flip the cards can you not? There was the solution. Just pick 10 cards at random and flip them. The remaining 42 cards and this pack of 10 would contain an equal number of cards that face up.(can you guess why?)

more of these can be found at
http://www.cisl.columbia.edu/grads/tuku/brainteasers.html

Monday, March 13, 2006

Cornell: Experiences

Ok. I have had enough experience now looking at blogs of different people to write up a blog of my own. So I decided to post some of my experiences at cornell. This is just a draft so please bear with some mistakes. I will improve on this. Suggestions are welcome.

Firstly Grad school a fun place to be for a variety of reasons. You can have a variety of different experiences. But grad study is not like undergrad where life after it is what you chose to be. You become much more constrained. I got an offer from a similarly rated univ for a Masters and I chose this since at that point of time I decided that I was meant for a Phd and went ahead with the decision. But I realised that decisions in life are not made so easily. Well you cannot make a decision from India. Grad study can be a challenging experience, it can make you a better person but there is a chance that it could degrade you Market worth. Lets say what happens when your advisor forces you to work on something that nobody in the industry cares about. Phd is a gamble. It is a nonstandardised degree something one would find hard to judge. Well then it is left to see where I am going to end up. I am seriously debating whether my decision to come here is right or not. I have definitely become better but have I or have I not done the 'right' thing? Only time will tell.