Challenge - 5 Problems
Financial Data Analysis Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Calculate Moving Average of Stock Prices
Given daily closing prices of a stock, what is the output of the following code that calculates a 3-day moving average?
Data Analysis Python
import pandas as pd prices = pd.Series([100, 102, 101, 105, 107]) moving_avg = prices.rolling(window=3).mean() print(moving_avg.tolist())
Attempts:
2 left
💡 Hint
Think about how rolling averages handle the first few values when the window is not full.
✗ Incorrect
The rolling function with window=3 calculates the mean of the current and previous two values. The first two values are NaN because there are not enough data points to fill the window.
❓ data_output
intermediate2:00remaining
Identify the Date with Highest Daily Return
Given a DataFrame of stock closing prices indexed by date, which date has the highest daily return calculated by percentage change?
Data Analysis Python
import pandas as pd data = {'Close': [100, 105, 103, 110, 108]} dates = pd.to_datetime(['2024-01-01', '2024-01-02', '2024-01-03', '2024-01-04', '2024-01-05']) df = pd.DataFrame(data, index=dates) df['Return'] = df['Close'].pct_change() max_return_date = df['Return'].idxmax() print(max_return_date.strftime('%Y-%m-%d'))
Attempts:
2 left
💡 Hint
Calculate percentage change between consecutive days and find the max.
✗ Incorrect
The highest daily return is on 2024-01-04 because the price jumped from 103 to 110, which is the largest percentage increase.
❓ visualization
advanced3:00remaining
Plot Cumulative Returns Over Time
Which option produces the correct plot of cumulative returns from daily returns in a DataFrame?
Data Analysis Python
import pandas as pd import matplotlib.pyplot as plt returns = pd.Series([0.01, -0.005, 0.02, -0.01, 0.015]) cum_returns = (1 + returns).cumprod() - 1 plt.plot(cum_returns) plt.title('Cumulative Returns') plt.xlabel('Days') plt.ylabel('Cumulative Return') plt.show()
Attempts:
2 left
💡 Hint
Cumulative returns multiply daily returns over time, showing growth trend.
✗ Incorrect
The code calculates cumulative returns and plots them as a line chart showing growth over days.
🔧 Debug
advanced2:00remaining
Identify the Error in Volatility Calculation
What error does the following code raise when calculating volatility (standard deviation of returns)?
Data Analysis Python
import pandas as pd prices = pd.Series([100, 102, 101, 105]) returns = prices.pct_change() volatility = returns.std(ddof=0) print(volatility.values)
Attempts:
2 left
💡 Hint
Check the type of the volatility variable before accessing .values.
✗ Incorrect
The std() method returns a float, which does not have a .values attribute, causing an AttributeError.
🚀 Application
expert2:30remaining
Determine the Number of Trading Days with Positive Returns
Given a DataFrame of daily closing prices, how many days have positive returns?
Data Analysis Python
import pandas as pd prices = pd.Series([100, 101, 99, 102, 104, 103]) returns = prices.pct_change() positive_days = returns[returns > 0].count() print(positive_days)
Attempts:
2 left
💡 Hint
Count how many daily returns are greater than zero, ignoring the first NaN.
✗ Incorrect
The positive returns occur on days where price increased compared to previous day: from 100 to 101, 99 to 102, and 102 to 104, totaling 3 days.