Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Apprendre Challenge: Analyze Asset Correlations | Financial Data Analysis with Python
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
Python for Investors

bookChallenge: Analyze Asset Correlations

Tâche

Swipe to start coding

You are given a pandas DataFrame called returns that contains daily returns for five different stocks: AAPL, MSFT, GOOG, AMZN, and TSLA.

Complete the following steps:

  • Calculate the correlation matrix for the DataFrame of returns and store it in a variable called corr_matrix.
  • Visualize the correlation matrix using a seaborn heatmap. Make sure the heatmap has a title.
  • Identify the pair of stocks with the highest positive correlation (excluding self-correlation), and the pair with the lowest (most negative) correlation.
  • Print the names of these pairs in the following format:
    • Highest correlation: STOCK1 and STOCK2
    • Lowest correlation: STOCK3 and STOCK4

Replace STOCK1, STOCK2, etc. with the actual stock names from the DataFrame.

Use only the libraries provided in the starter code. Do not fetch any data online or use additional datasets.

Solution

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 1. Chapitre 7
single

single

Demandez à l'IA

expand

Demandez à l'IA

ChatGPT

Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion

Suggested prompts:

Can you explain this in simpler terms?

What are the main takeaways from this?

Can you give me a real-world example?

close

bookChallenge: Analyze Asset Correlations

Glissez pour afficher le menu

Tâche

Swipe to start coding

You are given a pandas DataFrame called returns that contains daily returns for five different stocks: AAPL, MSFT, GOOG, AMZN, and TSLA.

Complete the following steps:

  • Calculate the correlation matrix for the DataFrame of returns and store it in a variable called corr_matrix.
  • Visualize the correlation matrix using a seaborn heatmap. Make sure the heatmap has a title.
  • Identify the pair of stocks with the highest positive correlation (excluding self-correlation), and the pair with the lowest (most negative) correlation.
  • Print the names of these pairs in the following format:
    • Highest correlation: STOCK1 and STOCK2
    • Lowest correlation: STOCK3 and STOCK4

Replace STOCK1, STOCK2, etc. with the actual stock names from the DataFrame.

Use only the libraries provided in the starter code. Do not fetch any data online or use additional datasets.

Solution

Switch to desktopPassez à un bureau pour une pratique réelleContinuez d'où vous êtes en utilisant l'une des options ci-dessous
Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 1. Chapitre 7
single

single

some-alt