Least Square Monte Carlo

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Least Square Monte Carlo

Neil P Firth
Hi,

I've done a first cut for a one dimensional least squares monte carlo
implementation and have a few questions before checking anything in:

1. I cannot see an implementation of the overloaded operator std::cout <<
for the Matrix class. dataformatters.cpp has the overload for Array, but
Matrix is in ql/Math/ leading to the unpleasant include ql/math/matrix.hpp
Are there any other formatter utilities. Does anyone strongly object to
checking it in as is?

2. To implement the Singular Value Decomposition (SVD) for the least
squares I have adapted the TNT / JAMA library
http://math.nist.gov/tnt/
which is in the public domain. Any objections to checking this in?

3. For the function abs() there is QL_FABS in qldefines.hpp. What is the
recommend macro, etc for max and min?

4. I am going to add an AmericanOption example to the source tree.

Let me know what you think.

Cheers,
Neil

---------------------------------------------------
  Neil Firth
  Brasenose College Oxford OX1 4AJ United Kingdom
  Office: 01865 280616
  [hidden email]
  http://www.maths.ox.ac.uk/~firth
---------------------------------------------------


Reply | Threaded
Open this post in threaded view
|

Re: Least Square Monte Carlo

Luigi Ballabio-2
At 12:51 PM 7/23/03 +0100, Neil P Firth wrote:
>I've done a first cut for a one dimensional least squares monte carlo
>implementation and have a few questions before checking anything in:

Great. It starts to looks like one hell of a release...

>1. I cannot see an implementation of the overloaded operator std::cout <<
>for the Matrix class. dataformatters.cpp has the overload for Array, but
>Matrix is in ql/Math/ leading to the unpleasant include ql/math/matrix.hpp
>Are there any other formatter utilities. Does anyone strongly object to
>checking it in as is?

No problem.

>2. To implement the Singular Value Decomposition (SVD) for the least
>squares I have adapted the TNT / JAMA library
>http://math.nist.gov/tnt/
>which is in the public domain. Any objections to checking this in?

How big that is?

>3. For the function abs() there is QL_FABS in qldefines.hpp. What is the
>recommend macro, etc for max and min?

QL_MAX and QL_MIN.


>4. I am going to add an AmericanOption example to the source tree.

Good.

Later,
         Luigi



Reply | Threaded
Open this post in threaded view
|

CapeTools.net web site containing QuantLib based calculations

Toyin Akin-4
Hi guys,

For the last 4 months I've been playing around with QuantLib, converting
this to C#.NET and building web financial pricers
using quantLib as the main pricing engine.

The initial result is hosted at : www.capetools.net, and for now this is
simply a hobby project!!

Here various financial derivatives can be priced online (I'm sure there are
many bugs.)

You may find on accessing the pricers the first time there is a bit of a lag
(can be upto 20 secs) as the pricers are
being dynamically complied on the server. After this first initial hit,
pricing should be reasonable.

There is a forum on the site if anybody wants to post any
suggestions/bugs/comments.

You can also email me @ [hidden email].

I would say that 70% of the calculations uses QuantLib functionality
directly, the other 30% are my own extensions
(Constant Maturity swaps, Libor in arrears with convexity adjustments
etc...)

I have not used the QuantLib.NET version as there seems to be a different
licence attached to it and in addition it is out of date with the C++
version. The version used on this site has all the functionality of the C++
version.

Please feel free to browse...

Best Regards,
Toyin Akin.



Reply | Threaded
Open this post in threaded view
|

Re: CapeTools.net web site containing QuantLib based calculations

Sadruddin Rejeb-4
Hi Toyin,

> The initial result is hosted at : www.capetools.net, and for now this is
> simply a hobby project!!

Wonderful! QuantLib definitely needed this kind of online "demo" application.

Thanks a lot for this great work,
Sad


Reply | Threaded
Open this post in threaded view
|

Re: CapeTools.net web site containing QuantLib based calculations

Toyin Akin-4
Thanks,

The C++ to C# conversion was hard work, but at least I understand the
structure of quantLib fully!!
The code for the SABR function was actually taken from a Forum within the
wilmott site (contributed by a junior
quant). I am no quant myself and certainly do not understand the mathematics
so it was a rare gem to find this.

If you guys want the link or for me to send you the VB code, let me know.

Toy out.

----- Original Message -----
From: "Sad" <[hidden email]>
To: <[hidden email]>
Sent: Thursday, July 24, 2003 7:57 AM
Subject: Re: [Quantlib-users] CapeTools.net web site containing QuantLib
based calculations


> Hi Toyin,
>
> > The initial result is hosted at : www.capetools.net, and for now this is
> > simply a hobby project!!
>
> Wonderful! QuantLib definitely needed this kind of online "demo"
application.

>
> Thanks a lot for this great work,
> Sad
>
>
> -------------------------------------------------------
> This SF.Net email sponsored by: Free pre-built ASP.NET sites including
> Data Reports, E-commerce, Portals, and Forums are available now.
> Download today and enter to win an XBOX or Visual Studio .NET.
>
http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
> _______________________________________________
> Quantlib-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/quantlib-users



Reply | Threaded
Open this post in threaded view
|

Re: CapeTools.net web site containing QuantLib based calculations

Luigi Ballabio-2
In reply to this post by Toyin Akin-4
At 10:44 PM 7/23/03 +0100, Toyin Akin wrote:
>For the last 4 months I've been playing around with QuantLib, converting
>this to C#.NET and building web financial pricers
>using quantLib as the main pricing engine.
>
>The initial result is hosted at : www.capetools.net, and for now this is
>simply a hobby project!!

Great!


>I have not used the QuantLib.NET version as there seems to be a different
>licence attached to it and in addition it is out of date with the C++
>version. The version used on this site has all the functionality of the C++
>version.

Is there any chance you and Jens can get together on this? It seems a lot
of duplicated work the two of you are doing here...

Bye,
         Luigi



Reply | Threaded
Open this post in threaded view
|

Re: CapeTools.net web site containing QuantLib based calculations

Toyin Akin-4
In reply to this post by Sadruddin Rejeb-4
Hi all,
As there are quite a few requests for this already here is the VB code of
the SABR model, extracted from the SABR FORUM on the wilmott site.

I have also adding a "what is a SWAP?" link on the web site so that users
can have a better idea of what and how this contract and it's various
derivatives are used for.

############################################################################
#######

            Public Function sabr(alpha As Double, forward As Double, k As
Double, beta As Double, volvol As Double, rho As Double, time As Double) As
Double
                '// sabr model from Managing Smile Risk by Patrick Hagan,
Deep Kumar, Andrew Lesniewski and Diana Woodward
                ' This will return vols which can be used in Black Scholes
formula

                'alpha=volatility, volvol controls smile, rho controls skew

                Dim sabr1 As Double, sabr2 As Double, sabr3 As Double, sabrz
As Double, sabrxofz As Double

                Dim a1 As Double, a2 As Double, a3 As Double, a4 As Double

                a1 = (volvol / alpha)
                a2 = (forward * k)
                a3 = (1 - beta)
                sabrz = a1 * a2 ^ (a3 / 2) * WorksheetFunction.Ln(forward /
k)
                sabrxofz = WorksheetFunction.Ln(((1 - 2 * rho * sabrz +
sabrz ^ 2) ^ 0.5 + sabrz - rho) / (1 - rho))
                sabr1 = alpha / (forward * k) ^ (a3 / 2) * (1 + ((a3 ^ 2) /
24) * (WorksheetFunction.Ln(forward / k) ^ 2) + ((1 - beta) ^ 4 / 1920) *
(WorksheetFunction.Ln(forward / k) ^ 4))
                sabr2 = sabrz / sabrxofz
                sabr3 = 1 + (((a3 ^ 2 / 24) * alpha ^ 2 / (forward * k) ^
a3) + 0.25 * rho * beta * volvol * alpha / ((forward * k) ^ a3 / 2) + (2 - 3
* rho ^ 2) * volvol ^ 2 / 24) * time
                sabr = sabr1 * sabr2 * sabr3
            End Function

############################################################################
###########

I have not modified it and take no responsibility as to it's accuracy.
Best Regards,
Toyin Akin.



----- Original Message -----
From: "Sad" <[hidden email]>
To: <[hidden email]>
Sent: Thursday, July 24, 2003 7:57 AM
Subject: Re: [Quantlib-users] CapeTools.net web site containing QuantLib
based calculations


> Hi Toyin,
>
> > The initial result is hosted at : www.capetools.net, and for now this is
> > simply a hobby project!!
>
> Wonderful! QuantLib definitely needed this kind of online "demo"
application.

>
> Thanks a lot for this great work,
> Sad
>
>
> -------------------------------------------------------
> This SF.Net email sponsored by: Free pre-built ASP.NET sites including
> Data Reports, E-commerce, Portals, and Forums are available now.
> Download today and enter to win an XBOX or Visual Studio .NET.
>
http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
> _______________________________________________
> Quantlib-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/quantlib-users



Reply | Threaded
Open this post in threaded view
|

Re: CapeTools.net web site containing QuantLib based calculations

Toyin Akin-4
In reply to this post by Luigi Ballabio-2
Hi,

I agree about the duplication of work, however I wanted to reach stage #1 of
this project before the end of July and there was no way I could have done
this without the use of commercial .NET libraries. Also QuantLib has changed
significantly since the start of QuantLib.NET and it was a pain for me to
bridge the gap especially since I didn't really understand the C++ version
from the basic classes. In order to aid my understanding, I decided a
rewrite would be beneficial for my own understanding.

No matter how many times I've tried to debug the C++ and C# version I still
could not fully understand it to the lowest detail.

After the rewrite, painful as it was(!!) I now do.

Thus as far as I'm concerned, Jens library, with a bit more work can also
produce the same end goal and so I see his library as
the official C# library that users should refer too. Jens has done a
brilliant job and has some sexy features that I have dropped
(event handling, COM attributes and XML documentation). The latter you
certainly need for users to understand the code fully.

The next piece of work will be simple pricers along with market viewers FRA,
swap rate calculators (via a simple grid).
The current pricers although packed with useful information that a
trader/marketer could probably trade off, looks very busy, so for
developer's who simply want to view swap rates, option premiums the simple
pricers should suffice.

Best Regards.
Toyin Akin.
www.capetools.net

----- Original Message -----
From: "Luigi Ballabio" <[hidden email]>
To: "Toyin Akin" <[hidden email]>;
<[hidden email]>
Sent: Thursday, July 24, 2003 9:12 AM
Subject: Re: [Quantlib-users] CapeTools.net web site containing QuantLib
based calculations


> At 10:44 PM 7/23/03 +0100, Toyin Akin wrote:
> >For the last 4 months I've been playing around with QuantLib, converting
> >this to C#.NET and building web financial pricers
> >using quantLib as the main pricing engine.
> >
> >The initial result is hosted at : www.capetools.net, and for now this is
> >simply a hobby project!!
>
> Great!
>
>
> >I have not used the QuantLib.NET version as there seems to be a different
> >licence attached to it and in addition it is out of date with the C++
> >version. The version used on this site has all the functionality of the
C++

> >version.
>
> Is there any chance you and Jens can get together on this? It seems a lot
> of duplicated work the two of you are doing here...
>
> Bye,
>          Luigi
>
>
>
> -------------------------------------------------------
> This SF.Net email sponsored by: Free pre-built ASP.NET sites including
> Data Reports, E-commerce, Portals, and Forums are available now.
> Download today and enter to win an XBOX or Visual Studio .NET.
>
http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
> _______________________________________________
> Quantlib-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/quantlib-users
>