




























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Tests your ability to use Python programming for financial analysis and data manipulation. Topics include financial data analysis, algorithmic trading, and the use of libraries like Pandas and NumPy for financial modeling.
Typology: Exams
1 / 100
This page cannot be seen from the preview
Don't miss anything!





























































































Question 1. Which Python statement correctly creates a virtual environment named finance_env? A) python - m venv finance_env B) pip install finance_env C) conda create - n finance_env python=3. D) pyenv virtualenv finance_env Answer: A Explanation: python - m venv finance_env creates a standard virtual environment; option C uses Conda, which also works but the question asks for the Python built‑in method. Question 2. In Jupyter Notebook, which magic command lists all installed packages? A) %pip list B) %conda list C) %show packages D) %env Answer: A Explanation: %pip list runs pip inside the notebook and displays installed packages. Question 3. Which of the following is the correct way to import the numpy library with the conventional alias? A) import numpy as np B) import np as numpy C) import numpy as numpy_lib D) from numpy import *
Answer: A Explanation: The conventional alias for NumPy is np. Question 4. What is the output type of type(5/2) in Python 3? A) int B) float C) bool D) complex Answer: B Explanation: The division operator / always returns a float in Python 3. Question 5. Which statement converts the string '123.45' to a floating‑point number? A) int('123.45') B) float('123.45') C) str('123.45') D) complex('123.45') Answer: B Explanation: float() parses a numeric string into a float. Question 6. Which of the following expressions correctly checks if a variable price is greater than 100 and less than 200? A) price > 100 and price < 200
Explanation: def defines a function; if no return is executed, Python returns None by default. Question 9. In the function definition def calc(a, b=10, *args, **kwargs):, which parameter can be supplied positionally after args? A) a only B) b only C) Both a and b D) Neither Answer: A Explanation: Positional arguments must appear before the first *. a can be positional; b has a default and must be supplied positionally before *args. Question 10. Which scope rule places a variable defined inside a nested function before a global statement? A) Local B) Enclosing C) Global D) Built‑in Answer: B Explanation: The LEGB rule: Local → Enclosing → Global → Built‑in. A nested function first looks in its enclosing scope. Question 11. Which list method removes and returns the element at index 3?
A) pop(3) B) remove(3) C) del(3) D) slice(3) Answer: A Explanation: list.pop(index) removes and returns the element at the given index. Question 12. Given prices = [100, 105, 110], what does prices[1:] return? A) [100] B) [105, 110] C) [100, 105] D) [] Answer: B Explanation: Slicing from index 1 to the end yields the sub‑list [105, 110]. Question 13. Which of the following creates an immutable ordered collection? A) list B) dict C) tuple D) set Answer: C Explanation: Tuples are immutable ordered sequences.
D) Both A and B Answer: D Explanation: Both np.eye and np.identity generate an identity matrix. Question 17. What is the result of np.array([1, 2, 3]) + 5? A) array([6, 7, 8]) B) array([5, 7, 8]) C) array([1, 2, 3, 5]) D) Error Answer: A Explanation: NumPy broadcasts the scalar 5 to each element (vectorized addition). Question 18. Which NumPy universal function computes the natural logarithm element‑wise? A) np.log B) np.ln C) np.exp D) np.sqrt Answer: A Explanation: np.log applies the natural log to each array element. Question 19. Given arr = np.arange(12).reshape(3,4), what does arr[:,2] return?
A) First column B) Third column as a 1‑D array C) Third row D) All rows, third column as a 2‑D array Answer: B Explanation: : selects all rows; 2 selects column index 2 (third column), yielding a 1‑D view. Question 20. Which Pandas object is best suited for a single column of time‑series data with labeled dates? A) DataFrame B) Series C) Panel D) Index Answer: B Explanation: A Series holds one‑dimensional labeled data, ideal for a single price series. Question 21. How do you select rows where column 'Sector' equals 'Technology' using loc? A) df.loc[df['Sector'] == 'Technology'] B) df.iloc[df['Sector'] == 'Technology'] C) df.loc['Sector' == 'Technology'] D) df['Sector' == 'Technology']
B) fillna(method='bfill') C) interpolate() D) dropna() Answer: A Explanation: ffill stands for forward fill. Question 25. Which operation converts a column of strings representing numbers to floats in place? A) df['col'] = df['col'].astype(float) B) df['col'].convert(float) C) df['col'].to_float() D) df['col'] = float(df['col']) Answer: A Explanation: astype(float) casts the Series to float dtype. Question 26. What does df.melt(id_vars='Date', var_name='Ticker', value_name='Price') accomplish? A) Turns wide format into long format with one price per row B) Pivots long format to wide C) Drops the 'Date' column D) Sorts the DataFrame by 'Ticker' Answer: A
Explanation: melt unpivots columns into rows, preserving Date. Question 27. Which Pandas method merges prices and fundamentals on column 'Ticker' keeping all rows from prices? A) pd.merge(prices, fundamentals, on='Ticker', how='left') B) pd.merge(prices, fundamentals, on='Ticker', how='right') C) pd.concat([prices, fundamentals], axis=1) D) prices.join(fundamentals, on='Ticker') Answer: A Explanation: A left join retains all rows from the left DataFrame (prices). Question 28. In a groupby operation, which function computes the standard deviation of each group? A) std() B) var() C) mean() D) count() Answer: A Explanation: std() returns the sample standard deviation per group. Question 29. Which Pandas function creates a pivot table that shows the average 'Return' for each 'Sector' and 'Month'? A) df.pivot_table(values='Return', index='Sector', columns='Month', aggfunc='mean') B) df.pivot(values='Return', index='Sector', columns='Month')
Question 32. Which of the following statements correctly adds a title and axis labels to a Matplotlib plot? A) plt.title('Price'), plt.xlabel('Date'), plt.ylabel('USD') B) plt.add_title('Price') C) plt.label('Price') D) plt.axes('Price') Answer: A Explanation: title, xlabel, and ylabel set the corresponding annotations. Question 33. What is the formula for a simple (arithmetic) return between price P₀ and P₁? A) (P₁ - P₀) / P₀ B) ln(P₁ / P₀) C) (P₁ / P₀) - 1 D) Both A and C Answer: D Explanation: Both expressions are algebraically equivalent. Question 34. Which function from NumPy computes the future value of an investment with compounding? A) np.fv(rate, nper, pmt, pv) B) np.pv(rate, nper, pmt, fv) C) np.npv(rate, cashflows)
D) np.irr(cashflows) Answer: A Explanation: np.fv calculates future value given rate, periods, payment, and present value. Question 35. In a discounted cash flow model, which variable represents the discount rate? A) r B) n C) PV D) CF Answer: A Explanation: The discount rate is commonly denoted by r. Question 36. Which Python code correctly computes the Net Present Value (NPV) of cash flows cf = [-1000, 200, 300, 400] at a discount rate of 5%? A) np.npv(0.05, cf) B) np.npv(0.05, np.array(cf)) C) np.npv(0.05, np.array(cf[1:]), cf[0]) D) np.npv(0.05, np.array(cf[1:])) + cf[0] Answer: D Explanation: NumPy’s np.npv assumes the first cash flow occurs at t=1; therefore the initial outflow must be added separately.
Answer: D Explanation: All three functions produce standard normal samples. Question 40. Which method computes the 5‑day rolling standard deviation of a Pandas Series returns? A) returns.rolling(5).std() B) returns.rolling(window=5).var() C) returns.rolling(5).mean() D) returns.rolling(5).sum() Answer: A Explanation: .std() calculates the rolling standard deviation. Question 41. Which of the following correctly extracts the month component from a Pandas DateTimeIndex? A) df.index.month B) df.index['month'] C) df['month'] = df.index.month D) Both A and C Answer: D Explanation: df.index.month returns an array of month numbers; assigning it creates a new column.
Question 42. In a groupby operation on column 'Year', which aggregation returns the cumulative sum of 'Profit' within each year? A) df.groupby('Year')['Profit'].cumsum() B) df.groupby('Year')['Profit'].sum().cumsum() C) df.groupby('Year').apply(lambda x: x['Profit'].cumsum()) D) Both A and C Answer: D Explanation: Both approaches compute cumulative profit per year. Question 43. Which Pandas method converts a DataFrame from wide to long format while preserving column 'Date' as identifier? A) df.melt(id_vars='Date') B) df.stack() C) df.unstack() D) df.transpose() Answer: A Explanation: melt reshapes the DataFrame while keeping specified identifier columns. Question 44. Which Python package provides the yfinance module for downloading historical market data? A) pip install yfinance B) conda install yfinance C) Both A and B D) None of the above
B) sns.scatterplot(x='X', y='Y', data=df) C) sns.lineplot(x='X', y='Y', data=df) D) sns.boxplot(x='X', y='Y', data=df) Answer: A Explanation: regplot adds a linear regression fit. Question 48. Which Python statement correctly defines a class Portfolio with an initializer that accepts a list of tickers? A) class Portfolio: def init(self, tickers): self.tickers = tickers B) class Portfolio(): def init(self, tickers=[]): self.tickers = tickers C) Both A and B D) Neither Answer: C Explanation: Both syntaxes are valid; the empty list default in B should be avoided for mutable defaults, but syntactically correct. Question 49. In object‑oriented finance code, which keyword is used to inherit from a base class Asset? A) extends B) inherits
C) (Asset) after the class name D) :Asset Answer: C Explanation: class Equity(Asset): indicates inheritance. Question 50. Which method inside a Portfolio class would most naturally compute the total market value given a dictionary prices? A) def total_value(self, prices): return sum(prices[t] * self.weights[t] for t in self.tickers) B) def total_value(self): self.prices = prices C) def compute(self): pass D) def value(self, prices): return self.tickers * prices Answer: A Explanation: The method multiplies each ticker’s price by its weight and sums the result. Question 51. Which Python decorator is used to define a static method inside a class? A) @staticmethod B) @classmethod C) @property D) @abstractmethod