Challenge: Automate Portfolio Metrics Calculation
Swipe to start coding
You are given a DataFrame of daily closing prices for several assets and a list of portfolio weights. Your task is to automate the calculation of three key portfolio metrics:
- Calculate the expected annual return of the portfolio (assume 252 trading days in a year);
- Calculate the annualized volatility (standard deviation) of the portfolio;
- Calculate the Sharpe Ratio of the portfolio (assume the risk-free rate is 0).
Implement the function calculate_portfolio_metrics(prices_df, weights) to return a dictionary with keys 'expected_annual_return', 'annual_volatility', and 'sharpe_ratio', each mapped to the corresponding float value.
Use only the allowed libraries. The function will be tested with different price data and weights.
Ratkaisu
Kiitos palautteestasi!
single
Kysy tekoälyä
Kysy tekoälyä
Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme
Can you explain this in simpler terms?
What are the main points I should remember?
Can you give me an example?
Mahtavaa!
Completion arvosana parantunut arvoon 4.76
Challenge: Automate Portfolio Metrics Calculation
Pyyhkäise näyttääksesi valikon
Swipe to start coding
You are given a DataFrame of daily closing prices for several assets and a list of portfolio weights. Your task is to automate the calculation of three key portfolio metrics:
- Calculate the expected annual return of the portfolio (assume 252 trading days in a year);
- Calculate the annualized volatility (standard deviation) of the portfolio;
- Calculate the Sharpe Ratio of the portfolio (assume the risk-free rate is 0).
Implement the function calculate_portfolio_metrics(prices_df, weights) to return a dictionary with keys 'expected_annual_return', 'annual_volatility', and 'sharpe_ratio', each mapped to the corresponding float value.
Use only the allowed libraries. The function will be tested with different price data and weights.
Ratkaisu
Kiitos palautteestasi!
single