GoodScores

Programming for Finance and Fintech – Flashcards & Quiz Questions

Teaches Python programming for financial work: data structures, NumPy and pandas, financial calculations, charts and simple backtests.

280 flashcards · 138 quiz questions · 7 topics

Get all 280 cards with Lifetime

1. Python Basics

Python Fundamentals and Finance Context · Variables, Indentation and Core Data Types · Operators, Expressions and Input Output · Control Flow with Conditions and Loops · Functions and Importing Modules

What does it mean to say that Python is an interpreted language?
Python code is executed line by line by an interpreter at run time instead of being compiled into a separate program beforehand. This makes it quick to write, run and test small pieces of code.
What does it mean that Python is a high-level programming language?
A high-level language hides low-level details such as memory management from the programmer. Python's syntax is close to everyday English, making it easier to read and learn.
Why is Python widely used for financial data analysis?
Python has readable syntax and a wide range of data-analysis libraries, so analysts can clean, explore and model financial data efficiently. The same language handles both quick calculations and larger analysis tasks.

Which statement correctly describes Python as a programming language?

  1. A. A markup language used only for describing document layout
  2. B. A compiled language that must be built into an executable before it runs
  3. C. An interpreted, high-level language that executes code at run time
  4. D. A low-level language that gives direct control over computer memory

Python is interpreted, meaning it runs code line by line at execution time rather than compiling it first, and it is high-level because it hides low-level machine details from the programmer.

A student saves code in a file called report.py and wants to run it and see its output. What should they do?

  1. A. Compile the file into a separate program before it can produce output
  2. B. Open the file in a text editor and read the code without running it
  3. C. Type python report.py in a terminal with Python installed
  4. D. Rename the file to report.txt and open it in a browser

Typing python report.py starts the interpreter, which reads and executes the saved code line by line and displays anything the program prints.

40 flashcards and 19 quiz questions in this topic.

2. Data Structures

Lists: Ordered and Mutable Collections · Indexing and Slicing Sequences · Tuples: Ordered and Immutable Collections · Dictionaries: Storing and Looking Up Values · Sets and Choosing Data Structures

What is a list in Python, and how is it written?
A list is an ordered, changeable collection written in square brackets. Its items are separated by commas, such as [10, 20, 30].
What does it mean that a list is ordered?
Ordered means each item has a fixed position, and that position is kept until you change it. The items stay in the sequence you placed them, so you can access an item by its position.
What does it mean that a list is changeable (mutable)?
Changeable means you can add items to it, replace an existing item, or remove an item after the list is created. The list object itself stays the same while its contents change.

Which statement correctly describes how a list is written in Python?

  1. A. An unordered collection of key-value pairs written in braces
  2. B. A changeable collection of unique items written in angle brackets
  3. C. An ordered, changeable collection written in square brackets
  4. D. An ordered collection written in parentheses that cannot be changed

A list is defined as an ordered, changeable collection written in square brackets, so this is the correct description.

A variable holds marks = [50, 60, 70]. The statement marks.append(80) is then run. What does marks contain afterwards?

  1. A. [80, 50, 60, 70]
  2. B. [50, 60, 80]
  3. C. [50, 60, 70]
  4. D. [50, 60, 70, 80]

The append method adds the new value as the last item, so 80 is placed after 70 and the other items keep their positions.

40 flashcards and 20 quiz questions in this topic.

3. NumPy

Introduction to NumPy and Arrays · Creating Arrays and Inspecting Shape · Indexing, Slicing and Reshaping · Vectorisation and Array Operations · Statistical Functions on Arrays

What is NumPy and what is it used for?
NumPy is the Python library for numerical computing. It provides efficient arrays and tools for working with numbers.
What is the core object of NumPy?
NumPy's core object is the n-dimensional array, called the ndarray. It is the main structure used to store and process data.
What does 'n-dimensional' mean in the name ndarray?
It means the array can arrange data along any number of dimensions, such as a single row or a two-dimensional table. The 'n' stands for any count.

Why is a NumPy array faster than a Python list for numerical work?

  1. A. It wraps every number in a separate Python object
  2. B. It stores items of one data type in continuous memory
  3. C. It keeps each value in a linked list node
  4. D. It converts numbers to text before doing math

NumPy keeps all elements the same type in a continuous block of memory, so it avoids the repeated type checks that slow down Python lists during numerical work.

A student must run a long series of arithmetic calculations on a set of numbers. What does switching to a NumPy array change about the work?

  1. A. The calculations are guaranteed correct without any checks
  2. B. The calculations run faster because the array holds one data type
  3. C. The numbers are automatically displayed as a chart
  4. D. The data is uploaded to a remote server

Because a NumPy array holds one data type in continuous memory, arithmetic on long series of numbers runs faster than with a Python list.

40 flashcards and 19 quiz questions in this topic.

4. Pandas and Financial Data

Pandas Series and DataFrame Structures · Reading and Inspecting Data in Pandas · Handling Missing Values in DataFrames · Grouping and Aggregating Financial Data · Date Indexing and Time Series Resampling

What is a pandas Series and how is it structured?
A Series is a one-dimensional labelled array. It holds a sequence of values together with an index that labels each value.
What is a pandas DataFrame and how is it structured?
A DataFrame is a two-dimensional table with labelled rows and labelled columns. Each value is located by its row label and its column label.
What is the main structural difference between a Series and a DataFrame?
A Series has one labelled axis, its index. A DataFrame has two labelled axes, a row index and a column index.

Which statement correctly distinguishes a pandas Series from a pandas DataFrame?

  1. A. Having one index of labels in a Series, and both row and column labels in a DataFrame
  2. B. Being one-dimensional for a DataFrame and two-dimensional for a Series
  3. C. Storing only numbers in a Series and only text in a DataFrame
  4. D. Having no labels in a DataFrame and two labelled axes in a Series

A Series carries one index of labels, while a DataFrame carries both row and column labels. Their difference is the number of labelled axes, not a restriction on the kind of data stored.

From a DataFrame of daily prices, which operation returns a one-dimensional object whose index is the DataFrame's row labels?

  1. A. The head method of the DataFrame
  2. B. The columns attribute of the DataFrame
  3. C. The shape attribute of the DataFrame
  4. D. Selecting one column by its label

Selecting a single column returns a Series, and that Series uses the DataFrame's row labels as its index. The shape attribute gives a tuple, head gives a DataFrame, and columns gives the column labels themselves.

40 flashcards and 20 quiz questions in this topic.

5. Financial Calculations

Simple Returns from Price Series · Log Returns and Additivity · Cumulative and Compounded Returns · Present Value and Net Present Value · Rolling Averages and Moving Windows

What is the formula for the simple return of a price series over one period?
The simple return is (Pt − Pt−1) / Pt−1: the change in price divided by the price in the previous period. It measures the percentage gain or loss from one period to the next.
What does pandas' pct_change() produce when applied to a price series?
It returns the fractional change between each price and the price immediately before it, which is the simple return for each period. The values are decimals, so 0.05 means a 5% move.
Why does the first entry of a pct_change() result have no numeric value?
The first price has no earlier price to act as Pt−1, so the denominator is missing. pandas therefore leaves the first return as a missing value (NaN).

What does pandas' pct_change() return when applied to a price series?

  1. A. The average of a fixed window of recent prices
  2. B. The fractional change between each price and the one before it
  3. C. The absolute difference between each price and the one before it
  4. D. The natural log of the ratio of consecutive prices

pct_change() divides the change in price by the previous price, giving the simple return as a fraction. An absolute difference, a log ratio and a windowed average are different calculations.

A stock closes at 80 and the next day at 88. What is the simple return for the second day?

  1. A. 0.88
  2. B. −0.10
  3. C. 0.10
  4. D. 0.08

The change of 8 divided by the starting price of 80 equals 0.10, a 10% gain. The other figures either reuse the wrong base or carry the wrong sign.

40 flashcards and 20 quiz questions in this topic.

6. Risk and Portfolio Measures

Return and Volatility Fundamentals · Portfolio Return and Portfolio Risk · Correlation, Covariance and Diversification · Sharpe Ratio and Risk-Adjusted Performance · Drawdown and Downside Risk Measures

How is the simple return on an asset over a period defined and calculated?
Simple return is the percentage change in price: (ending price − starting price) / starting price. It is the gain divided by what you originally paid.
What is the log return of an asset and how is it computed?
Log return is the natural logarithm of the price ratio: ln(ending price / starting price). It is also called the continuously compounded return.
Why are log returns convenient when analysing returns over multiple periods?
Log returns are additive across time: the log return over two periods is the sum of the two single-period log returns. Simple returns are not additive and instead combine by multiplication.

What does volatility measure when applied to a series of asset returns?

  1. A. The standard deviation of those returns
  2. B. The arithmetic average of those returns
  3. C. The difference between the highest and lowest return
  4. D. The cumulative gain over the whole period

Volatility is defined as the standard deviation of a series of returns, capturing how far returns typically scatter around their mean.

A stock is bought at RM50 and sold one year later at RM57.50, with no dividends paid. What is the simple return?

  1. A. 15%
  2. B. 13.04%
  3. C. 13.98%
  4. D. 7.5%

The simple return is the price change divided by the purchase price: (57.50 − 50) / 50 = 0.15, or 15%.

40 flashcards and 20 quiz questions in this topic.

7. Visualisation, Data Sources and Backtesting

Plotting Financial Data with Matplotlib · Fetching Market Data from APIs · Building a Backtest · Avoiding Look-Ahead Bias · Detecting and Preventing Overfitting

What is Matplotlib and what does the plt.plot() function do?
Matplotlib is the standard Python plotting library. The plt.plot() function draws a line chart from the data values passed to it.
How do you draw a simple price line chart with plt.plot() and make it appear on screen?
Pass the x values (such as dates) and the y values (such as prices) to plt.plot(), then call plt.show() to display the figure.
Which Matplotlib function adds a title to a chart?
plt.title() sets the title text of the current chart and places it above the plot.

In Matplotlib, which sequence of calls draws a line chart from two arrays of values and displays it?

  1. A. Pass the x values and y values to plt.subplots(), which draws the line and displays it automatically
  2. B. Pass the x values and y values to plt.plot(), then call plt.show() to render the figure
  3. C. Pass the x values and y values to plt.grid(), then call plt.title() to render the figure
  4. D. Pass the x values to plt.title() and the y values to plt.legend() to render the figure

plt.plot() takes the data points as arguments and draws the line chart, while plt.show() renders the figure so it can be seen. The other calls add titles, grids, legends, or axes but do not draw and display the line.

To make plt.legend() show a meaningful name for each plotted price series, what should you do?

  1. A. Call plt.grid() before plt.legend() so the legend can read the grid lines
  2. B. Set the title with plt.title() because the legend copies the title text
  3. C. Use plt.subplots() to build a legend automatically for every axes object
  4. D. Give each plot a label using the label argument so the legend has text to display

The legend displays the label text attached to each plot, so supplying a label argument gives it something meaningful to show. Grids, titles, and subplots do not provide legend labels.

40 flashcards and 20 quiz questions in this topic.

Study every card

Every card and question in this course comes with the Lifetime package. Add it to GoodScores and practise with flashcards, quizzes and spaced review.

Get all 280 cards with Lifetime