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:
- Matrix multiplication:
- Matrix transpose:
- Matrix inverse: (only for invertible matrices)
Eigenvalue Decomposition
- Eigenvalue equation:
- Eigendecomposition:
- Diagonalization condition: Matrix must have n linearly independent eigenvectors
2. Probability Theory and Statistics Fundamentals
Random Variables and Probability Distributions
- Expected value:
- Variance:
- Covariance:
Bayes’ Theorem
- Bayes’ formula:
- Chain rule for conditional probability:
3. State-Space Model Fundamentals
Basic Structure
State-space models consist of two core equations:
- State equation:
- Observation equation:
Where:
- : State vector
- : Observation vector
- : State transition matrix
- : Observation matrix
- , : Process noise and observation noise
4. Financial Time Series Characteristics
Statistical Properties of Returns
- Log returns:
- 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
| Concept | Linear Algebra | Probability & Statistics | Financial Application |
|---|---|---|---|
| Vector | Collection of numbers | Random variable vector | Asset price vector |
| Matrix | Linear transformation | Covariance matrix | Risk factor loading |
| Eigenvalue | Principal direction | Principal component | Risk factor weight |
| Expected value | - | Probability-weighted average | Expected return |
| Variance | - | Uncertainty measure | Risk 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:
- Linear algebra tools: Preparation for matrix operations and state-space representation
- Probability and statistics theory: Foundation for uncertainty modeling and Bayesian inference
- State-space concepts: Introduction to mathematical description framework for dynamic systems
- 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.