Random number generation
Results 1 to 8 of 8

Thread: Random number generation

  1. #1
    Hi all, figured I might begin with a question which isn't directly associated with trading forex.

    How can I generate normal random variables (3 or more) which are aribtrarily related?

    The way MATLAB seems to use, specifically:
    1. Generate uncorrelated random normal observations.
    2. Establish correlation matrix.
    3. Find Cholesky decomposition L.L^T of the correlation matrix.
    4. Multiply the uncorrelated data by L

    doesn't work too well with an random correlation matrix, as no element (barring the main diagonal) must be positive, as well as non-negative.

    Thus, out of the way, how can I go about generating random variables of random correlation?

  2. #2
    Quote Originally Posted by ;
    Hi , figured I might start with a query which is not directly related to trading FX.

    How do I generate normal random factors (3 or more) which are aribtrarily correlated?

    The way MATLAB appears to use, namely:
    1. Generate uncorrelated random ordinary observations.
    2. Define correlation matrix.
    3. Loe Cholesky decomposition L.L^T of the correlation matrix.
    4. Assessing the uncorrelated information by L

    doesn't work too well with an arbitrary correlation matrix, as no element (barring the key diagonal) must be optimistic, or perhaps non-negative.

    So, out of the way, how would I go about generating random variables of arbitrary correlation?
    Maybe trading doesn't require that much mathematics so that I cannot reply it.May be some Einstien incarnate might be trading so he could answer it.

  3. #3
    Quote Originally Posted by ;
    wow RoBik you're the Einstien incarnate concerning whom I had been talking.Because I attempted to reply the post before anyone can reply once you worked together with speed of light....LoL

  4. #4
    Thank you for the replies. Now to grok copulas.

  5. #5
    Quote Originally Posted by ;
    Hi all, figured I would begin with a query which isn't directly related to trading forex.

    How do I generate normal random variables (3 or more) which are aribtrarily correlated?

    The way MATLAB appears to use, namely:
    1. Generate uncorrelated observations that are normal.
    2. Establish correlation matrix.
    3. Loe Cholesky decomposition L.L^T of the correlation matrix.
    4. Multiply the uncorrelated information by L

    doesn't work too well with an random correlation matrix, so as no element (barring the main diagonal) is required to be optimistic, or perhaps non-negative.

    So, with that out of the way, how would I go about generating random variables of random correlation?
    On the second thought, just what does not work? Maybe there's something wrong with your
    correlation matrix? By definition correlation matrix has to be positive semi-definite.

  6. #6
    Well, I had been working from the logarithm of successive closing prices for the following 5 pairs (I've put them into indirect to make it simpler on self):
    AUD/GBP, AUD/MXP, AUD/CHF, AUD/NZD and AUD/ISK, with the following sample correlations

    AUD/GBP - AUD/MXP: -0.452885
    AUD/GBP - AUD/CHF: 0.905765
    AUD/GBP - AUD/NZD: 0.023389
    AUD/GBP - AUD/ISK: -0.466430
    AUD/MXP - AUD/CHF: -0.497812
    AUD/MXP - AUD/NZD: 0.103609
    AUD/MXP - AUD/ISK: 0.609864
    AUD/CHF - AUD/NZD: -0.006788
    AUD/CHF - AUD/ISK: -0.456123
    AUD/NZD - AUD/ISK: 0.036772

    As all of the pairs have mixed signs, simply inverting any of them won't address my problem.

    Bopik's copula suggestion worked fine when there is just one correlated pair of pairs, but fell apart with two and more.

  7. #7
    Quote Originally Posted by ;
    Well, I had been working out of the logarithm of consecutive closing prices for the following 5 pairs (I've put them into indirect to make it easier on self):
    AUD/GBP, AUD/MXP, AUD/CHF, AUD/NZD and AUD/ISK, together with the following sample correlations

    AUD/GBP - AUD/MXP: -0.452885
    AUD/GBP - AUD/CHF: 0.905765
    AUD/GBP - AUD/NZD: 0.023389
    AUD/GBP - AUD/ISK: -0.466430
    AUD/MXP - AUD/CHF: -0.497812
    AUD/MXP - AUD/NZD: 0.103609
    AUD/MXP - AUD/ISK: 0.609864
    AUD/CHF - AUD/NZD: -0.006788
    AUD/CHF - AUD/ISK: -0.456123
    AUD/NZD - AUD/ISK: 0.036772

    As all the pairs have mixed signals, just inverting some of these won't solve my issue.

    Bopik's copula proposal worked fine when there is one correlated pair of pairs, but fell apart with 2 and much more.
    Hi!

    Sorry that I answer so late, but I have been out for the weekend.
    I do not know just what your problem is. I have no porblems to generate arbitrary corelated values using the cholesky decomposition.
    Here's my matlab session

    Inserted Code #91;font=Fixedsys#93;gt;gt; C=#91;1 -0.452885 0.905765 0.023389 -0.466430; -0.452885 1 -0.497812 0.103609 0.609864; 0.905765 -0.497812 1 -0.006788 -0.456123; 0.023389 0.103609 -0.006788 1 0.036772; -0.466430 0.609864 -0.456123 0.036772 1#93; C = 1.0000 -0.45290.90580.0234 -0.4664 -0.45291.0000 -0.49780.10360.6099 0.9058 -0.49781.0000 -0.0068 -0.4561 0.02340.1036 -0.00681.00000.0368 -0.46640.6099 -0.45610.03681.0000 gt;gt; XU = rand(1000, 5); gt;gt; L=chol(C) L = 1.0000 -0.45290.90580.0234 -0.4664 00.8916 -0.09830.12810.4471 0 00.4122 -0.03730.0249 0 00.9908 -0.0087 0 0 00.7628 gt;gt; X=XU*L; gt;gt; corr(X) ans = 1.0000 -0.47370.91190.0535 -0.4511 -0.47371.0000 -0.50830.08430.6187 0.9119 -0.50831.00000.0024 -0.4386 0.05350.08430.00241.00000.0348 -0.45110.6187 -0.43860.03481.0000Number 91;/font#93;
    C is the correlation matrix, XU are the uncorrelated random values (1000x5 matrix), L is caused by cholesky factorization, X is the resulting product of multiplying the uncorelated values together with the factorization result. The final command is that the check, the result is connected as wanted (the amounts Aren't exactly the same as the input signal matrix - we're still calculating with arbitrary vallues - but that the resultant correlation is pretty close to the desired person )

    cheers

  8. #8

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
This website uses cookies
We use cookies to store session information to facilitate remembering your login information, to allow you to save website preferences, to personalise content and ads, to provide social media features and to analyse our traffic. We also share information about your use of our site with our social media, advertising and analytics partners.