Code
import numpy as np
import matplotlib.pyplot as plt
import scipy.stats
np.set_printoptions(precision=4)import numpy as np
import matplotlib.pyplot as plt
import scipy.stats
np.set_printoptions(precision=4)Join me as I learn Quantitative Finance via the CQF and Coursera’s Financial Engineering and Risk Management specialization offered by Columbia University. This will be a companion document serving as both a journal of my progress as well as a basic introduction to Quant Fin in general.
The structure of this document will roughly follow the topics introduced by both programs, distilled to serve as a quick reference for basic concepts and application. The content will not directly reference that of either of the two courses, but will be my own interpretation and explanation. The purpose of this project is to ‘learn by explaining’ the central concepts in my own words. Basic knowledge of calculus, probability and statistics is assumed.
Discrete Random Variables and Distributions
1. Probability Distribution Function (PDF)
Consider a process, visualized below, that generates outcomes according to a Student’s t-distribution. This distribution is defined by its degrees of freedom, which is set at 20 for the plot below. The x-axis is the possible outcomes of the process, here ranging from \(-4\) to \(4\). The y-axis is the probability of getting a particular outcome. As we can see, this generates a symmetric, unimodal distribution with a mean of \(0\).
# Create the distribution
t_dist = scipy.stats.t(20)
t_values = np.linspace(-4, 4, 1000)
# Plot the PDF
plt.figure(figsize=(8, 2))
plt.plot(t_values, t_dist.pdf(t_values))
plt.axvline(x = 0, color = 'b')
plt.xlabel('t value')
plt.ylabel('probability for t value')
plt.title('PDF for t distribution with df=20')
plt.show()2. Cumulative Distribution Function (CDF)
A CDF is a function that determines the probability that the outcome \(X\) of some process is less than a given value \(x\):
\(F(x) := P(X \le x)\)
Below we consider three different \(X\) values for the above distribution: -1.5, 0, 1.5. The probability of getting an outcome below these values is represented by the grey shaded area to the left of the value, under the PDF. As we can see the probability of getting an outcome below(or above) the mean \(0\) is \(0.5\).
example_values = (-1.5, 0, 1.5)
pdf_values = t_dist.pdf(t_values)
fill_color = (0, 0, 0, 0.1) # Light gray in RGBA format.
line_color = (0, 0, 0, 0.5) # Medium gray in RGBA format.
fig, axes = plt.subplots(1, len(example_values), figsize=(10, 2))
for i, x in enumerate(example_values):
pdf_ax = axes[i]
pdf_ax.plot(t_values, pdf_values)
# Fill area at and to the left of x.
pdf_ax.fill_between(t_values, pdf_values,
where=t_values <= x,
color=fill_color)
pd = t_dist.pdf(x) # Probability density at this value.
# Line showing position of x on x-axis of PDF plot.
pdf_ax.plot([x, x],[0, pd], color=line_color)
cd = t_dist.cdf(x)
pdf_ax.set_title('x = {:.1f}, p = {:.2f}'.format(x, cd))
pdf_ax.spines['right'].set_visible(False)
pdf_ax.spines['top'].set_visible(False)
pdf_ax.yaxis.set_ticks_position('left')
pdf_ax.xaxis.set_ticks_position('bottom')The CDF itself would look like this
# Plot the CDF
plt.figure(figsize=(8, 2))
plt.plot(t_values, t_dist.cdf(t_values))
plt.xlabel('t value')
plt.ylabel('probability for t value <= t')
plt.title('CDF for t distribution with df=20')
plt.show()PMF
Expected Value
Variance
Binomial Distribution
Poisson Distribution