Chapter 1: Mathematical Foundations and Financial Preliminaries

Haiyue
8min

Chapter 1: Mathematical Foundations and Financial Preliminaries

Learning Objectives
  • Master linear algebra fundamentals (vectors, matrix operations, eigenvalue decomposition)
  • Understand probability theory and statistics fundamentals (random variables, probability distributions, Bayes’ theorem)
  • Familiarize with basic concepts of state-space models
  • Learn the basic characteristics and statistical properties of financial time series

Knowledge Summary

1. Linear Algebra Fundamentals

Vector and Matrix Operations

  • Vector dot product: ab=i=1naibi\mathbf{a} \cdot \mathbf{b} = \sum_{i=1}^{n} a_i b_i
  • Matrix multiplication: (AB)ij=k=1nAikBkj(AB)_{ij} = \sum_{k=1}^{n} A_{ik}B_{kj}
  • Matrix transpose: (AT)ij=Aji(A^T)_{ij} = A_{ji}
  • Matrix inverse: AA1=IAA^{-1} = I (only for invertible matrices)

Eigenvalue Decomposition

  • Eigenvalue equation: Av=λvA\mathbf{v} = \lambda\mathbf{v}
  • Eigendecomposition: A=QΛQ1A = Q\Lambda Q^{-1}
  • Diagonalization condition: Matrix must have n linearly independent eigenvectors

2. Probability Theory and Statistics Fundamentals

Random Variables and Probability Distributions

  • Expected value: E[X]=xf(x)dxE[X] = \int_{-\infty}^{\infty} x f(x) dx
  • Variance: Var(X)=E[(XE[X])2]=E[X2](E[X])2Var(X) = E[(X - E[X])^2] = E[X^2] - (E[X])^2
  • Covariance: Cov(X,Y)=E[(XE[X])(YE[Y])]Cov(X,Y) = E[(X-E[X])(Y-E[Y])]

Bayes’ Theorem

  • Bayes’ formula: P(AB)=P(BA)P(A)P(B)P(A|B) = \frac{P(B|A)P(A)}{P(B)}
  • Chain rule for conditional probability: P(A,B)=P(AB)P(B)P(A,B) = P(A|B)P(B)

3. State-Space Model Fundamentals

Basic Structure

State-space models consist of two core equations:

  • State equation: xt+1=Ftxt+Gtut+wt\mathbf{x}_{t+1} = F_t \mathbf{x}_t + G_t \mathbf{u}_t + \mathbf{w}_t
  • Observation equation: yt=Htxt+vt\mathbf{y}_t = H_t \mathbf{x}_t + \mathbf{v}_t

Where:

  • xt\mathbf{x}_t: State vector
  • yt\mathbf{y}_t: Observation vector
  • FtF_t: State transition matrix
  • HtH_t: Observation matrix
  • wt\mathbf{w}_t, vt\mathbf{v}_t: Process noise and observation noise

4. Financial Time Series Characteristics

Statistical Properties of Returns

  • Log returns: rt=ln(Pt)ln(Pt1)r_t = \ln(P_t) - \ln(P_{t-1})
  • Volatility clustering: High volatility periods tend to be followed by high volatility periods
  • Fat-tailed distribution: Financial return distributions have fatter tails than normal distributions
  • Autocorrelation: Price changes typically exhibit weak autocorrelation

Example Code

Matrix Operations Example

import numpy as np
import matplotlib.pyplot as plt

# Basic matrix operations example
A = np.array([[2, 1], [1, 3]])
B = np.array([[1, 2], [0, 1]])

# Matrix multiplication
C = np.dot(A, B)
print("Matrix multiplication result A*B:")
print(C)

# Eigenvalue decomposition
eigenvalues, eigenvectors = np.linalg.eig(A)
print(f"Eigenvalues: {eigenvalues}")
print(f"Eigenvectors:\n{eigenvectors}")

# Verify eigenvalue decomposition
reconstructed = eigenvectors @ np.diag(eigenvalues) @ np.linalg.inv(eigenvectors)
print(f"Reconstruction error: {np.max(np.abs(A - reconstructed))}")

Probability Distributions and Bayesian Inference

import scipy.stats as stats

# Normal distribution example
mu, sigma = 0, 1
x = np.linspace(-4, 4, 100)
pdf = stats.norm.pdf(x, mu, sigma)

# Bayesian update example (conjugate prior)
# Prior: Normal distribution N(μ₀, σ₀²)
mu_0, sigma_0 = 0, 2
# Observation data
observations = np.array([1.2, 0.8, 1.5, 0.9])
n = len(observations)
sample_mean = np.mean(observations)

# Posterior parameters (known variance case)
sigma_obs = 1  # Assume observation noise variance is known
precision_prior = 1 / sigma_0**2
precision_obs = n / sigma_obs**2

# Posterior mean and variance
mu_posterior = (precision_prior * mu_0 + precision_obs * sample_mean) / (precision_prior + precision_obs)
sigma_posterior = 1 / np.sqrt(precision_prior + precision_obs)

print(f"Prior mean: {mu_0}, Posterior mean: {mu_posterior:.3f}")
print(f"Prior std: {sigma_0}, Posterior std: {sigma_posterior:.3f}")

Financial Time Series Analysis

# Simulate stock price data and calculate statistical features
np.random.seed(42)
T = 252  # Trading days in a year
dt = 1/252
mu = 0.1  # Annualized expected return
sigma = 0.2  # Annualized volatility

# Geometric Brownian motion to simulate stock prices
returns = np.random.normal(mu*dt, sigma*np.sqrt(dt), T)
log_prices = np.cumsum(returns)
prices = 100 * np.exp(log_prices)  # Starting price 100

# Calculate return statistics
daily_returns = np.diff(log_prices)
print(f"Average daily return: {np.mean(daily_returns):.6f}")
print(f"Daily return std: {np.std(daily_returns):.6f}")
print(f"Annualized volatility: {np.std(daily_returns) * np.sqrt(252):.3f}")

# Test for normality (Jarque-Bera test)
from scipy.stats import jarque_bera
jb_stat, jb_pvalue = jarque_bera(daily_returns)
print(f"Jarque-Bera statistic: {jb_stat:.3f}, p-value: {jb_pvalue:.3f}")

# Plot price and return distribution
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(12, 4))

ax1.plot(prices)
ax1.set_title('Simulated Stock Price')
ax1.set_xlabel('Trading Day')
ax1.set_ylabel('Price')

ax2.hist(daily_returns, bins=30, alpha=0.7, density=True)
x_norm = np.linspace(daily_returns.min(), daily_returns.max(), 100)
ax2.plot(x_norm, stats.norm.pdf(x_norm, np.mean(daily_returns), np.std(daily_returns)), 'r-', label='Normal Distribution Fit')
ax2.set_title('Daily Return Distribution')
ax2.set_xlabel('Return')
ax2.set_ylabel('Density')
ax2.legend()

plt.tight_layout()
plt.show()

State-Space Model Framework Diagram

🔄 正在渲染 Mermaid 图表...

Important Concept Comparison

ConceptLinear AlgebraProbability & StatisticsFinancial Application
VectorCollection of numbersRandom variable vectorAsset price vector
MatrixLinear transformationCovariance matrixRisk factor loading
EigenvaluePrincipal directionPrincipal componentRisk factor weight
Expected value-Probability-weighted averageExpected return
Variance-Uncertainty measureRisk measure
Important Reminder

The core of Kalman filtering is optimal estimation in uncertain environments, so a solid foundation in probability and statistics is crucial. In financial applications, we often deal with non-stationary, non-linear data, and these mathematical tools lay the foundation for subsequent advanced techniques.

Precautions
  • Pay attention to dimension matching in matrix operations
  • Financial data often does not satisfy the normal distribution assumption
  • Consider numerical stability issues in practical applications
  • Covariance matrices must be positive definite (or positive semi-definite)

Chapter Summary

This chapter establishes the mathematical foundations needed to learn Kalman filtering, including:

  1. Linear algebra tools: Preparation for matrix operations and state-space representation
  2. Probability and statistics theory: Foundation for uncertainty modeling and Bayesian inference
  3. State-space concepts: Introduction to mathematical description framework for dynamic systems
  4. Financial data characteristics: Understanding the special properties of data in practical applications

These foundational knowledge will be fully applied in subsequent chapters, especially when constructing dynamic models of financial markets.

Categories