Exercise Plotting
Exercise Plotting
Task:
• Given a dataset with daily stock returns for a portfolio of 10 stocks over a year,
your students need to calculate:
1. The daily portfolio return (weighted average return of the stocks in the portfolio).
2. The cumulative return of the portfolio over time.
3. The portfolio volatility (standard deviation of returns).
• Use seaborn to plot:
• A line plot showing both cumulative return and volatility over time.
• A distribution plot (kernel density estimate) of daily portfolio returns.
Instructions:
1. Load the stock returns and portfolio structure data using pandas.
2. Calculate the weighted daily returns of the portfolio.
3. Use seaborn.lineplot() to show cumulative return and volatility on the same plot.
4. Use seaborn.kdeplot() for the distribution of daily portfolio returns.
Key Concepts:
Task:
• Students are provided with a dataset containing various financial ratios (e.g.,
Profit Margin, ROE, Current Ratio, Debt-to-Equity) for multiple firms.
• They need to:
1. Compute the correlation matrix between the financial ratios.
2. Visualize this correlation matrix using a heatmap (seaborn.heatmap()).
3. Perform hierarchical clustering of the firms based on their financial ratios.
4. Create a cluster map (seaborn.clustermap()) to visualize the clustering results
and the financial ratio correlations.
Instructions:
Task:
• Given a dataset containing monthly transaction volumes for a set of banks over
the past 5 years, students need to:
1. Perform time series decomposition to separate the trend, seasonality, and
residuals.
2. Visualize the decomposed components using matplotlib.
3. Use seaborn to create a seasonal plot that shows the average transaction volume
for each month across all years (e.g., using seaborn.boxplot() or seaborn.lineplot()).
Instructions:
Key Concepts:
Task:
• Your students are provided with data on different investment strategies (e.g.,
value, growth, momentum, and dividend strategies) and their historical returns.
1. Calculate the risk (volatility) and return (average return) of each strategy.
2. Use seaborn.scatterplot() to create a scatter plot of risk vs. return, with strategy
type as a hue (color-coded by strategy).
3. Add error bars representing the confidence interval of the returns for each
strategy.
Instructions:
Key Concepts:
Task:
• Given data on the number of transactions and average waiting time at different
bank branches, students need to:
1. Use a pivot table to summarize the data for different branches.
2. Visualize the efficiency of each branch using a heatmap, where the color
represents the number of transactions per minute (transaction rate).
3. Create a line plot to visualize how the average waiting time changes as
transaction rates increase.
Instructions:
Key Concepts:
These exercises require deeper data analysis and multi-step visualization processes, providing a
more challenging experience for students to fully understand the use of matplotlib and seaborn
in finance and banking applications.
Your students are provided with a dataset containing capital structures (equity and debt ratios)
of different companies across various industries, along with total assets, net income, and
market capitalization data. They are required to perform the following tasks:
Task:
Business Sense: Analyze how a company’s debt strategy affects its financial performance, and
how it varies by industry.
Task:
• Students are provided with a dataset containing company cash flow statements
categorized by business segments (operating, investing, and financing). They need to:
1. Clean the dataset and remove any non-relevant segments.
2. Calculate the total cash flow for each segment.
3. Visualize cash flow across different business segments using a stacked bar chart.
4. Perform a trend analysis by visualizing cash flows over time.
Business Sense: Evaluate cash flow efficiency in different segments and how it impacts a
company’s liquidity.
Task:
• Students are provided with data on equity, assets, and net income for various
companies. They need to:
1. Calculate both ROE and ROA for each company.
2. Visualize the relationship between ROE and ROA using a scatter plot.
3. Perform a regression analysis to understand the relationship between ROA and
ROE.
4. Create a grouped bar plot to compare the average ROE and ROA across
industries.
Business Sense: Understand how efficiently companies are using their equity and assets to
generate profit.
Task:
• Given data on revenue and EBIT for different firms, students should:
1. Calculate the EBIT margin for each firm.
2. Remove any outliers in the EBIT margins.
3. Visualize EBIT margins across industries using box plots to show distribution.
4. Create a histogram to show the distribution of EBIT margins across all firms.
Business Sense: Analyze the profitability of firms before financing costs and taxes, comparing
profitability across industries.
Task:
• Students are given data on current assets, current liabilities, and revenue for
multiple firms. They should:
1. Calculate working capital and working capital ratio for each firm.
2. Handle missing or negative working capital values.
3. Visualize the relationship between working capital and revenue using a scatter
plot.
4. Group firms by industry and create a box plot to compare the distribution of
working capital ratios.
Business Sense: Evaluate the efficiency of a firm’s short-term liquidity and how it impacts its
operational capabilities.
Ex. 12. Capital Expenditure (CapEx) vs. Free Cash Flow Analysis
Task:
• Given data on free cash flow and capital expenditures for companies, students
should:
1. Calculate the CapEx to Free Cash Flow ratio.
2. Remove firms with negative free cash flow.
3. Create a heatmap to show the correlation between CapEx, Free Cash Flow, and
Total Assets.
4. Plot the relationship between CapEx and Free Cash Flow using a scatter plot.
Business Sense: Assess how well companies are investing their cash flows in growth
opportunities.
Task:
• Provided with data on dividends paid, net income, and retained earnings for
various companies, students need to:
1. Calculate the dividend payout ratio for each company.
2. Handle missing or erroneous values in the dataset.
3. Create a line plot showing the dividend payout ratio trend over time for selected
companies.
4. Create a scatter plot comparing the dividend payout ratio and retained earnings.
Business Sense: Explore how dividend distribution impacts retained earnings and long-term
financial stability.
Task:
• Students are given data on debt, equity, cost of debt, and cost of equity for
various firms. They need to:
1. Calculate the WACC for each firm.
2. Remove firms with incomplete or missing data.
3. Create a bar plot showing WACC across different industries.
4. Visualize the relationship between WACC and company size (total assets) using a
scatter plot.
Business Sense: Assess the cost of financing and how it impacts the value and risk profile of a
firm.
Ex 15. Leverage Ratio and Profitability
Task:
• Provided with data on a firm’s liabilities, equity, and profitability metrics (e.g.,
EBIT, net income), students need to:
1. Calculate the leverage ratio for each company.
2. Handle missing or inconsistent data.
3. Create a grouped bar plot to compare the leverage ratio and profitability across
industries.
4. Use a regression plot to analyze the relationship between leverage and
profitability.
Business Sense: Explore how leveraging affects a firm’s profitability and financial risk.
Task:
• Given data on capital expenditures (CapEx), R&D spending, and revenue growth,
students should:
1. Clean the data and handle missing or anomalous values.
2. Calculate the CapEx-to-Revenue and R&D-to-Revenue ratios.
3. Create a scatter plot to compare CapEx-to-Revenue and R&D-to-Revenue ratios,
colored by industry.
4. Visualize the correlation between CapEx, R&D, and revenue growth using a
heatmap.
Business Sense: Evaluate how corporate investment strategies (CapEx and R&D) drive revenue
growth and innovation.
Task:
• Given a dataset with daily sales data for various product categories, students
need to:
1. Handle any missing dates by filling in gaps with zeros or interpolation.
2. Calculate weekly and monthly rolling averages for each category.
3. Visualize sales trends and seasonality over time for each category using line plots
and seasonality plots (e.g., average sales per month).
Business Sense: Understand sales seasonality and trends to forecast demand and optimize
inventory.
Task:
• Provided with monthly customer sign-up, cancellation, and usage data, students
need to:
1. Preprocess the data to calculate monthly churn and retention rates.
2. Create a cumulative count of active customers over time.
3. Use line plots to visualize churn rate trends and compare retention across
customer segments.
Task:
Business Sense: Evaluate expense allocation and identify areas where costs could be optimized.
Task:
• Students are given quarterly revenue and cost of goods sold (COGS) for multiple
regions. They need to:
1. Calculate gross margin for each region.
2. Handle outliers and any negative gross margin values.
3. Create a box plot to compare gross margins across regions and a bar plot to
display the revenue trends per region.
Business Sense: Assess regional profitability and identify high-margin regions to prioritize
investment.
Ex 21. Sales Performance by Employee and Product Line
Task:
• Given sales data for various employees across different product lines, students
should:
1. Calculate total sales per employee and average sales per product line.
2. Create a pivot table to summarize sales by employee and product line.
3. Visualize sales distributions for each product line and create a heatmap to
highlight top-performing employees.
Business Sense: Identify top performers and product lines to reward employees and focus on
high-demand products.
Task:
Business Sense: Understand stock efficiency, reduce inventory costs, and minimize stockouts.
Task:
• Students are given monthly spend and revenue data for various marketing
channels. They should:
1. Calculate the ROI for each channel.
2. Handle missing or zero revenue data (e.g., when a channel didn’t yield results).
3. Create a bar plot comparing the average ROI across channels and a trend line to
show ROI changes over time.
Task:
Business Sense: Identify equipment with frequent downtime and prioritize maintenance to
increase productivity.
Task:
• Given data on loan amounts, interest rates, repayment statuses, and risk
categories, students should:
1. Calculate the average interest rate and default rate for each risk category.
2. Handle missing or incomplete repayment data.
3. Visualize the distribution of loan performance across risk categories using bar
plots for default rates and scatter plots for loan amounts versus interest rates.
Business Sense: Assess risk-adjusted returns to optimize lending decisions and mitigate
defaults.
Task:
• Students are given data on product sales, return counts, and customer ratings.
They need to:
1. Calculate the return rate for each product and analyze the average customer
rating.
2. Handle missing or inconsistent ratings (e.g., extremely low or high values).
3. Visualize return rates using bar plots by product category and a scatter plot for
return rate versus customer rating.
Business Sense: Evaluate product quality and customer satisfaction to reduce return rates and
improve product design.