fmshedge Issue Tracker Rss Feedhttps://fmshedge.codeplex.com/workitem/list/basicfmshedge Issue Tracker Rss DescriptionCreated Unassigned: Double barrier hitting time approximation [1677]http://fmshedge.codeplex.com/workitem/1677Attached is a write up I did on approximating symmetric double barrier hitting times.<br /><br />Long story short, use t = (a/(sigma N^{-1}(1 - p/4)))^2 where p is uniform [0,1]. That should be a little faster :-)<br /><br />You can check it against the existing routine using a q-q plot. E.g. [NIST](http://www.itl.nist.gov/div898/handbook/eda/section3/qqplot.htm)<br />keithalewisMon, 25 Nov 2013 18:29:19 GMTCreated Unassigned: Double barrier hitting time approximation [1677] 20131125062919PCreated Unassigned: Report coordinator [1668]http://fmshedge.codeplex.com/workitem/1668Make sure all the data going into the report is in a consistent format and the presentation effectively communicates what we are trying to establish. Do not underestimate the importance of this.<br />keithalewisSat, 16 Nov 2013 03:25:58 GMTCreated Unassigned: Report coordinator [1668] 20131116032558ACreated Unassigned: More statistics [1667]http://fmshedge.codeplex.com/workitem/1667Use consistent parameters for the delta, slsg, and gamma hedges. Create multiple copies of spreadsheets to capture the data generated. <br /><br />We still need to establish the relationship between the delta hedge interval and the limit order epsilon.<br /><br />The time between re-hedging is constant for the current implementation of delta. We can collect statistics on the distribution of re-hedging times that occur using the gamma strategy. Use the mean as the delta hedge interval to compare respective P&L.<br />keithalewisSat, 16 Nov 2013 03:17:47 GMTCreated Unassigned: More statistics [1667] 20131116031747ACreated Unassigned: Optimize double_hitting_cdf [1666]http://fmshedge.codeplex.com/workitem/1666I updated https://fmsgjr.codeplex.com/SourceControl/latest#distribution.h to clarify the tolerance logic.<br />The root finding algorithm is the bottleneck. Finding a better initial guess can help with that.<br />Using secant instead of bisect will also speed that up.<br />keithalewisSat, 16 Nov 2013 02:53:16 GMTCreated Unassigned: Optimize double_hitting_cdf [1666] 20131116025316ACreated Unassigned: Add try ... catch wrappers to add-ins [1665]http://fmshedge.codeplex.com/workitem/1665As Yuanqin pointed out, it is no big deal to do this by hand. Attached are some code snippets you may or may not find useful. Unzip them into Documents\Visual Studio 2012\Code Snippets\Visual C++ and they will show up when you right click in Visual Studio.<br />keithalewisSat, 16 Nov 2013 02:47:11 GMTCreated Unassigned: Add try ... catch wrappers to add-ins [1665] 20131116024711ACreated Unassigned: P&L reporting [1647]http://fmshedge.codeplex.com/workitem/1647Given account info A_j at t_j, write functions for the following:<br /><br />(Familiarize yourself with std::accumulate and std::partial_sum from <numeric>.)<br /><br />- Final balance.<br />- max/min/mean balance.<br />- drawdown/up<br />- variance of account<br />- move per day ([sum_1^n |A_j|/dt_j]/n)<br />keithalewisFri, 18 Oct 2013 22:02:11 GMTCreated Unassigned: P&L reporting [1647] 20131018100211PCreated Unassigned: Add tests for each function in header [1646]http://fmshedge.codeplex.com/workitem/1646E.g. nextHit(). Work out a couple of example on paper and then write code to assert/ensure you are getting the same results.<br />keithalewisFri, 18 Oct 2013 21:40:11 GMTCreated Unassigned: Add tests for each function in header [1646] 20131018094011PCommented Task: How good is the hedge? [1642]http://fmshedge.codeplex.com/workitem/1642Write a function that takes a simulation and uses the account function to compute the difference between the hedge and the option payoff at expiration assuming the hedge is self-financing.<br /><br />Calculate distributions for various parameters. (Width)<br /><br />Start on classic delta hedge.<br />Comments: ** Comment from web user: keithalewis ** <p>Looking at the diffs now from what you guys have been up to. I learned at Morgan Stanley that is how your boss figures out who is getting a bonus. It is not the amount of code you write, it is about how useful it is. Complex and unmaintainable code is a big problem for them. </p><p>I was worried about everyone being able to deal with C++ code and using subversion. It was a two character change to get revision 25814 by Alice to fix that. C++ is funny that way.</p><p>Yudi has been checking in code to deal with the lognormal case. You will have to get me up to speed on Friday with this. `doubleBarrierHittingTime` seems to be on the right track.</p><p>Revison 25618: Jin fixed more than a few typos. She is too modest and the rest of the team can learn from her.</p><p>The next step is to turn the code you wrote into data on how well hedges work. That is where Excel comes in useful. </p>keithalewisThu, 17 Oct 2013 04:05:12 GMTCommented Task: How good is the hedge? [1642] 20131017040512ACommented Task: How good is the hedge? [1642]http://fmshedge.codeplex.com/workitem/1642Write a function that takes a simulation and uses the account function to compute the difference between the hedge and the option payoff at expiration assuming the hedge is self-financing.<br /><br />Calculate distributions for various parameters. (Width)<br /><br />Start on classic delta hedge.<br />Comments: ** Comment from web user: keithalewis ** <p> double interval = 1/365;<br>in `test_delta_simulation` is the problem. This evaluates to 0 since 1/365 = 0 (in integer arithmetic) on the right hand side and you get an infinite loop. Change to 1.0/365 and this will run fine.</p>keithalewisWed, 16 Oct 2013 21:24:42 GMTCommented Task: How good is the hedge? [1642] 20131016092442PCommented Task: How good is the hedge? [1642]http://fmshedge.codeplex.com/workitem/1642Write a function that takes a simulation and uses the account function to compute the difference between the hedge and the option payoff at expiration assuming the hedge is self-financing.<br /><br />Calculate distributions for various parameters. (Width)<br /><br />Start on classic delta hedge.<br />Comments: ** Comment from web user: YuanqinWei ** <p>We have finished the delta hedging part and changed rest of the code to implement log-normal underlying. But when we try to debug and run the code, Excel opens and pops up a warning saying: bad allocation. Do you happen to know what that means and how could we fix it? </p>YuanqinWeiWed, 16 Oct 2013 14:16:38 GMTCommented Task: How good is the hedge? [1642] 20131016021638PClosed Task: Generate a simulation [1640]http://fmshedge.codeplex.com/workitem/1640Use nextHit and hittingTime to generate one simulation of positions (Xi) and prices (X) for the money market account and underlying.<br />keithalewisFri, 27 Sep 2013 20:17:30 GMTClosed Task: Generate a simulation [1640] 20130927081730PClosed Task: Test (and fix) account function [1637]http://fmshedge.codeplex.com/workitem/1637Flesh out ```test_account()``` in slsg.cpp and fix ```account()``` in slsg.h.<br />keithalewisFri, 27 Sep 2013 20:16:46 GMTClosed Task: Test (and fix) account function [1637] 20130927081646PCommented Task: How good is the hedge? [1642]http://fmshedge.codeplex.com/workitem/1642Write a function that takes a simulation and uses the account function to compute the difference between the hedge and the option payoff at expiration assuming the hedge is self-financing.<br />Comments: ** Comment from web user: keithalewis ** <p>You are a little ahead of the rest of the team. Step 1 is to make sure the code is correct. After that we can speed it up.<br>You can always branch off from the trunk if you want to experiment with new code.</p>keithalewisThu, 26 Sep 2013 20:44:30 GMTCommented Task: How good is the hedge? [1642] 20130926084430PCommented Task: How good is the hedge? [1642]http://fmshedge.codeplex.com/workitem/1642Write a function that takes a simulation and uses the account function to compute the difference between the hedge and the option payoff at expiration assuming the hedge is self-financing.<br />Comments: ** Comment from web user: YuanqinWei ** <p>Are we constructing the simulate function such that it only does one simulation? If that's the case, could we just put the diff calculation within the simulate function? </p>YuanqinWeiThu, 26 Sep 2013 17:55:07 GMTCommented Task: How good is the hedge? [1642] 20130926055507PEdited Task: How good is the hedge? [1642]http://fmshedge.codeplex.com/workitem/1642Write a function that takes a simulation and uses the account function to compute the difference between the hedge and the option payoff at expiration assuming the hedge is self-financing.<br />keithalewisTue, 24 Sep 2013 01:53:11 GMTEdited Task: How good is the hedge? [1642] 20130924015311ACreated Task: How good is the hedge? [1642]http://fmshedge.codeplex.com/workitem/1642Write a function that takes a simulation and uses the account function to compute the difference between the hedge and the option payoff at expiration assuming the hedge is self-financing.<br />keithalewisTue, 24 Sep 2013 01:53:09 GMTCreated Task: How good is the hedge? [1642] 20130924015309ACommented Issue: Brownian motion exiting a corridor [1641]http://fmshedge.codeplex.com/workitem/1641My interpretation is that you want to know how long it takes a Brownian motion without drift B(t) to exit (−α,α) . This is quite different from the exit time from (−∞,α) which is discussed in some of the references you mention. I think this is a standard problem, but I'll just work out some of the properties from first principles.<br /><br />Full details at:<br /><br />http://math.stackexchange.com/questions/32302/first-exit-time-for-brownian-motion-without-drift<br /><br />If T = inf {t > 0 : B_t > a or B_t < -b} then 0 = B(0) = E B(t) = a p_a - b (1 - p_a), where p_a it the probability of exiting at a, hence p_a = b/(a + b). However this does not give us the distribution of T.<br />Comments: ** Comment from web user: keithalewis ** <p>Ignore my equation above. It should be </p><p> P(T < t) = P(T < t, B_T = a) + P(T < t, B_T = -b) <br> = P(B_T = a)P(T < t | B_T = a) + P(B_T = -b)P(T < t | b_T = -b). </p><p>We know P(B_T = a) and P(B_T = -b). It is not clear how to compute P(T < t | B_T = a) and the similar term involving -b.</p><p>The link has the formula. It involves theta functions. Maybe we should try for an approximation.</p><p>See [Reflection Principle](http://kalx.net/fms/rough/pp/rp.html) for the reflections principle. You can find more things [here](http://kalx.net/fms/rough/pp.html).</p><p>For the symmetric barrier we can use the fact B_t^2 - t is a martingale (why?) and the optional sampling theorem, 0 = EB^_T - T = a^2 - ET, so ET = a^2. </p><p>If u(t, x) satisfies u_t + (1/2) u_xx = 0, then u(t, B_t) is a martingale. (E.g., u(t, x) = x^2 - t).</p><p>Show u(t, x) = x^4 - 6 x^2 t + 3 t^2 is a solution and use that to find E[T^2].</p><p>More generally, show </p><p> u(t,x) = sum_0^k (-1/2)^j p^(2j)(x) t^j/j!</p><p>is a solution for any polynomial of degree 2k. This can be used to find all moments of T by taking p(x) = x^{2k}.</p><p>If we can find a tractable distribution matching the first couple of moments we can just use that.</p>keithalewisMon, 23 Sep 2013 20:36:17 GMTCommented Issue: Brownian motion exiting a corridor [1641] 20130923083617PCommented Issue: Brownian motion exiting a corridor [1641]http://fmshedge.codeplex.com/workitem/1641My interpretation is that you want to know how long it takes a Brownian motion without drift B(t) to exit (−α,α) . This is quite different from the exit time from (−∞,α) which is discussed in some of the references you mention. I think this is a standard problem, but I'll just work out some of the properties from first principles.<br /><br />Full details at:<br /><br />http://math.stackexchange.com/questions/32302/first-exit-time-for-brownian-motion-without-drift<br /><br />If T = inf {t > 0 : B_t > a or B_t < -b} then 0 = B(0) = E B(t) = a p_a - b (1 - p_a), where p_a it the probability of exiting at a, hence p_a = b/(a + b). However this does not give us the distribution of T.<br />Comments: ** Comment from web user: jw945 ** <p>should this be 4*P(Bt>a) - 4*P(Bt>3a)?</p><p>4*(Bt>3a) is the probability of brownian motion hit a and -a both within time t..</p>jw945Mon, 23 Sep 2013 17:20:43 GMTCommented Issue: Brownian motion exiting a corridor [1641] 20130923052043PCommented Issue: Brownian motion exiting a corridor [1641]http://fmshedge.codeplex.com/workitem/1641My interpretation is that you want to know how long it takes a Brownian motion without drift B(t) to exit (−α,α) . This is quite different from the exit time from (−∞,α) which is discussed in some of the references you mention. I think this is a standard problem, but I'll just work out some of the properties from first principles.<br /><br />Full details at:<br /><br />http://math.stackexchange.com/questions/32302/first-exit-time-for-brownian-motion-without-drift<br /><br />If T = inf {t > 0 : B_t > a or B_t < -b} then 0 = B(0) = E B(t) = a p_a - b (1 - p_a), where p_a it the probability of exiting at a, hence p_a = b/(a + b). However this does not give us the distribution of T.<br />Comments: ** Comment from web user: keithalewis ** <p>Let's stick with symmetric corridors for now. Even the closed form solution for that case will have to be inverted with 1-d root finding.</p><p>It is easy to generate stopping times for one sided barriers (even including drift) so it might be worthwhile figuring out how to use that to simulate 2 sided barriers. We know the probability which barrier will be hit, so we could generate that first, and look at the hitting time for that barrier. Unfortunately that includes paths that hit the other barrier first, so a more subtle analysis will be required.</p><p>Let T = T_a,b be the double sided (non-symmetric) hitting time. Then P(T < t) = P(T < t, B_T = a) + P(T < t, BT =b) = P(T < t) [ P(B_T = a | T < t) + P(B_T = b | T < t) ]. </p>keithalewisMon, 23 Sep 2013 01:27:29 GMTCommented Issue: Brownian motion exiting a corridor [1641] 20130923012729ACommented Task: Generate a simulation [1640]http://fmshedge.codeplex.com/workitem/1640Use nextHit and hittingTime to generate one simulation of positions (Xi) and prices (X) for the money market account and underlying.<br />Comments: ** Comment from web user: keithalewis ** <p>You are correct. This would be more optimal. The most important thing about the first cut of software is that you write simple code that you are sure is correct. We can optimize once we get it up and running and have the tests in. </p><p>If you don't know about this guy, you should: http://en.wikiquote.org/wiki/Donald_Knuth. One of his quotes is "We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil"</p>keithalewisMon, 23 Sep 2013 00:50:37 GMTCommented Task: Generate a simulation [1640] 20130923125037A