Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public double GetCorrelation(Indice a, Indice b)
- {
- double iSum = 0.0;
- for (int i = 0; i < a.Composition.Length; i++)
- {
- double sigmaA = _underlyingVolatilities[a.Composition.Names[i]];
- double alphaA = a.Composition[i];
- double jSum = 0.0;
- for (int j = 0; j < b.Composition.Length; j++)
- {
- double sigmaB = _underlyingVolatilities[b.Composition.Names[j]];
- double alphaB = b.Composition[j];
- double componentsCorrelation = _underlyingCorrelations[a.Composition.Names[i], b.Composition.Names[j]];
- double jTerm = alphaB * sigmaB * componentsCorrelation;
- jSum += jTerm;
- }
- double iTerm = alphaA * sigmaA * jSum;
- iSum += iTerm;
- }
- if (a.Volatility == 0.0)
- {
- GetVolatility(a);
- }
- if (b.Volatility == 0.0)
- {
- GetVolatility(b);
- }
- double correlation = iSum / (a.Volatility * b.Volatility);
- return correlation;
- }
Add Comment
Please, Sign In to add comment