<jupyter_start><jupyter_text>Covariance Matrix  Install libraries<jupyter_code>import sys
!{sys.executable} -m pip install -r requirements.txt<jupyter_output><empty_output><jupyter_text>Imports<jupyter_code>import numpy as np
import quiz_tests<jupyter_output><empty_output><jupyter_text>Quiz Solution<jupyter_code>import numpy as np

def covariance_matrix(returns):
    """
    Create a function that takes the return series of a set of stocks
    and calculates the covariance matrix.
    
    Parameters
    ----------
    returns : numpy.ndarray
        2D array containing stock return series in each row.
                
    Returns
    -------
    x : np.ndarray
        A numpy ndarray containing the covariance matrix
    """
    cov = np.cov(returns) 
    return cov

quiz_tests.test_covariance_matrix(covariance_matrix)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08372093023255814, 'fraction_numerical': 0.0011627906976744186, 'mean_word_length': 3.507853403141361, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '665561', 'license': 'Apache-2.0', 'n_tokens_mistral': 272, 'n_tokens_neox': 258, 'n_words': 67, 'path': 'Quiz/m3_funds_etfs_portfolio_optimization/l3_portfolio_risk_and_return/m3l3_covariance_solution.ipynb', 'repo_name': 'scumabo/AI4Trading', 'size': '860'}