Correlation Matrix

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

Correlation Matrix

digiplant
Hello.  I am trying to compute the correlation matrix, from a set of time series (say 3 seperate series for simplicity).  I am a new user to quantlib, and I cannot seem to figure out how to do this exactly using the library.  It seems like I should be using the GenericSequenceStatistics class, bit I am unsure how.  Can anyone provide me with a few pointers?  A simple, yet complete example would be extremely appreciated.
 
Please let me know if you need additional information.
Thanks
-a

------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Correlation Matrix

simone pilozzi
Hi,
try this two methods (they are part of a larger class called financial time series), they should work
Cheers
Simone
inline shared_ptr<SequenceStatistics> createsequence(TimeSeries<vector<Real>>jointds)
{
boost::shared_ptr<SequenceStatistics> gss(new SequenceStatistics);
for (it = jointds.begin();it !=jointds.end();++it)
{
p = it->second;
gss->add(p.begin(),p.end());
}

return gss;

}
inline Disposable<Matrix> getCorrelation(boost::shared_ptr<SequenceStatistics> g)
{
return g->correlation();
}

On 1 July 2010 20:50, Andrew Hill <[hidden email]> wrote:
Hello.  I am trying to compute the correlation matrix, from a set of time series (say 3 seperate series for simplicity).  I am a new user to quantlib, and I cannot seem to figure out how to do this exactly using the library.  It seems like I should be using the GenericSequenceStatistics class, bit I am unsure how.  Can anyone provide me with a few pointers?  A simple, yet complete example would be extremely appreciated.
 
Please let me know if you need additional information.
Thanks
-a

------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users



------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Correlation Matrix

oknbnaba
In reply to this post by digiplant
Try this; in C# .Net SWIG env.

        public QuantLib.Matrix CalculateCorrelation(DataSet MarketPriceChanges) // this dataset has series you want to correlate
        {
            uint UInstrumentCount = Convert.ToUInt32(MarketPriceChanges.Tables.Count);
            int InstrumentCount = MarketPriceChanges.Tables.Count;

            QuantLib.SequenceStatistics priceValuesCorreration = new QuantLib.SequenceStatistics(0);
            QuantLib.Matrix CorrelationMatrix = new QuantLib.Matrix(UInstrumentCount, UInstrumentCount);

            for (int i = 1; i < MarketPriceChanges.Tables[0].Rows.Count; i++)
            {
                QuantLib.DoubleVector vector = new QuantLib.DoubleVector();

                for (int j = 0; j < UInstrumentCount; j++)
                {
                    vector.Add(Convert.ToDouble(MarketPriceChanges.Tables[j].Rows[i]["PRICE_CHANGE"]));
                }
                priceValuesCorreration.add(vector);
            }
           
            CorrelationMatrix = priceValuesCorreration.correlation();
            return CorrelationMatrix;
        }

2010/7/1 Andrew Hill <[hidden email]>
Hello.  I am trying to compute the correlation matrix, from a set of time series (say 3 seperate series for simplicity).  I am a new user to quantlib, and I cannot seem to figure out how to do this exactly using the library.  It seems like I should be using the GenericSequenceStatistics class, bit I am unsure how.  Can anyone provide me with a few pointers?  A simple, yet complete example would be extremely appreciated.
 
Please let me know if you need additional information.
Thanks
-a

------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users



------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Sobol skipTo()

Fabien Le Floc'h-3
Hello,

I believe there might be a small mistake in Quantlib 1.01 sobolrsg.cpp
SobolRsg::skipTo method. The method starts with:
  void SobolRsg::skipTo(unsigned long skip) {
        unsigned long N = skip+1;
        unsigned int ops = (unsigned int)(std::log((double)N)/M_LN2)+1;

It should be:
  void SobolRsg::skipTo(unsigned long skip) {
        unsigned long N = skip<<1;
        unsigned int ops = (unsigned int)(std::log((double)N)/M_LN2)+1;

Regards,

Fabien Le Floc'h.

------------------------------------------------------------------------------
Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!
Finally, a world-class log management solution at an even better price-free!
Download using promo code Free_Logger_4_Dev2Dev. Offer expires
February 28th, so secure your free ArcSight Logger TODAY!
http://p.sf.net/sfu/arcsight-sfd2d
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Sobol skipTo()

Fabien Le Floc'h-3
Sorry for the annoyance, it's a mistake in my test, QL code is correct.

Le 01/02/2011 18:37, Fabien Le Floc'h a écrit :

> Hello,
>
> I believe there might be a small mistake in Quantlib 1.01 sobolrsg.cpp
> SobolRsg::skipTo method. The method starts with:
>   void SobolRsg::skipTo(unsigned long skip) {
>         unsigned long N = skip+1;
>         unsigned int ops = (unsigned int)(std::log((double)N)/M_LN2)+1;
>
> It should be:
>   void SobolRsg::skipTo(unsigned long skip) {
>         unsigned long N = skip<<1;
>         unsigned int ops = (unsigned int)(std::log((double)N)/M_LN2)+1;
>
> Regards,
>
> Fabien Le Floc'h.
>
> ------------------------------------------------------------------------------
> Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!
> Finally, a world-class log management solution at an even better price-free!
> Download using promo code Free_Logger_4_Dev2Dev. Offer expires
> February 28th, so secure your free ArcSight Logger TODAY!
> http://p.sf.net/sfu/arcsight-sfd2d
> _______________________________________________
> QuantLib-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/quantlib-users


--
Fabien LE FLOC'H
Financial Engineer
.................................................
C A L Y P S O
106-108 rue de la Boétie 75008 Paris
OFFICE   +33 (0)1 44 50 01 84
FAX       +33 (0)1 44 50 12 84
.................................................


------------------------------------------------------------------------------
Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!
Finally, a world-class log management solution at an even better price-free!
Download using promo code Free_Logger_4_Dev2Dev. Offer expires
February 28th, so secure your free ArcSight Logger TODAY!
http://p.sf.net/sfu/arcsight-sfd2d
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users