0
0
Data Analysis Pythondata~20 mins

Financial data analysis pattern in Data Analysis Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Financial Data Analysis Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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())
A[nan, nan, 101.0, 103.0, 106.0]
B[100, 102, 101, 105, 107]
C[100.0, 101.0, 101.0, 102.66666666666667, 104.33333333333333]
D[nan, nan, 101.0, 102.66666666666667, 104.33333333333333]
Attempts:
2 left
💡 Hint
Think about how rolling averages handle the first few values when the window is not full.
data_output
intermediate
2: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'))
A2024-01-04
B2024-01-02
C2024-01-05
D2024-01-03
Attempts:
2 left
💡 Hint
Calculate percentage change between consecutive days and find the max.
visualization
advanced
3: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()
ALine plot starting near 0 and ending around 0.03 showing cumulative growth
BBar plot showing daily returns as bars
CScatter plot of daily returns with no cumulative calculation
DPie chart showing proportion of positive vs negative returns
Attempts:
2 left
💡 Hint
Cumulative returns multiply daily returns over time, showing growth trend.
🔧 Debug
advanced
2: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)
AValueError: std() got an unexpected keyword argument 'ddof'
BTypeError: pct_change() missing required argument
CAttributeError: 'float' object has no attribute 'values'
DNo error, prints the volatility value
Attempts:
2 left
💡 Hint
Check the type of the volatility variable before accessing .values.
🚀 Application
expert
2: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)
A5
B3
C2
D4
Attempts:
2 left
💡 Hint
Count how many daily returns are greater than zero, ignoring the first NaN.