Linear independence

Two vectors are considered to be linearly dependent if and only if they are collinear, that is to say, if one can be expressed as a scalar multiple of the other. Furthermore, any set containing the zero vector is also deemed to be linearly dependent.

Mathematically, this is expressed as: w = α1v1 + α2v2  where α1 and α2 are scalars (real numbers in this context).

It means that vector 

2
6
4

can be expressed as a linear combination of two other vectors:

2
6
4
= 2 ×
1
1
0
+ 4 ×
0
1
1

This demonstrates that the vector

2
6
4

is linearly dependent on the vectors

1
1
0
and
0
1
1

Also linear dependence is called a linear combination or being within the linear span of the vectors.

A set of vectors v = [v₁ v₂ ... vₙ] is said to be linearly independent if no vector vᵢ within the set can be written as a linear combination of the others.

Linear Dependence Python Example

import numpy as np 

# Define the vectors 

v1 = np.array([1, 1, 0]) 

v2 = np.array([0, 1, 1]) 

w = np.array([2, 6, 4]) 


# Coefficients for the linear combination 

alpha1 = 2 

alpha2 = 4 


# Linear combination 

w_combination = alpha1 * v1 + alpha2 * v2 


# Check if the combination equals w 

print("w:", w) 

print("w_combination:", w_combination) 

print("Are they equal?", np.array_equal(w, w_combination))


w: [2 6 4] w_combination: [2 6 4] Are they equal? True

np.array - create an array.

Now let's test if a set of vectors are linearly independent.

from sympy import Matrix 


# Define the set of vectors as columns in a matrix 

v1 = np.array([1, 1, 0]) 

v2 = np.array([0, 1, 1]) 

v3 = np.array([1, 2, 1]) 


# Combine the vectors into a matrix 

A = Matrix(np.column_stack([v1, v2, v3])) 


# Check if the matrix has full rank 

print("Matrix A:") display(A) 

print("Rank of A:", A.rank()) 

print("Are the vectors linearly independent?", A.rank() == A.shape[1])


Matrix A:
[101112011]
Rank of A: 2
Are the vectors linearly independent? False


numpy.column_stack - stack 1D arrays as columns to make a 2D array. 2D arrays are stacked as-is. 1D arrays are turned into 2D columns first.

sympy - is a Python library for symbolic mathematics.

The concept of linear dependence has a variety of applications in finance, particularly in portfolio management, factor models and risk management. This article will explain how linear dependence is relevant in these areas and provide a Python example to illustrate the concept.

In portfolio management, linear dependence means that two assets move in the same way. If they are dependent, there is no benefit in holding both since they move together.

In factor models, asset returns are often expressed as a combination of factors. If one factor is dependent on others, it adds no new information.

The concept of linear dependence can also be employed to evaluate the risk profile of a portfolio. In the event that multiple assets within a portfolio exhibit linear dependence, it suggests that they may react in a similar manner to market shifts, thereby amplifying the overall risk.

Let us consider a scenario in which we have three stocks and wish to ascertain whether their daily returns are linearly dependent.

import numpy as np

import pandas as pd

from sympy import Matrix


# Sample data: Daily returns of 3 stocks

data = {

    'Stock_A': [0.02, 0.01, 0.03, 0.02, 0.01],

    'Stock_B': [0.03, 0.015, 0.045, 0.03, 0.015],

    'Stock_C': [0.04, 0.02, 0.06, 0.04, 0.02]

}


# Create a DataFrame

returns_df = pd.DataFrame(data)


# Display the returns

print("Daily Returns:")

print(returns_df)


# Convert the DataFrame to a matrix for linear dependence check

returns_matrix = Matrix(returns_df.values)


# Check the rank of the returns matrix

print("\nMatrix of Returns:")

display(returns_matrix)

rank = returns_matrix.rank()

print(f"Rank of the returns matrix: {rank}")


# Determine if the stock returns are linearly independent

if rank == returns_matrix.shape[1]:

    print("The stock returns are linearly independent.")

else:

    print("The stock returns are linearly dependent.")


Daily Returns:
   Stock_A  Stock_B  Stock_C
0     0.02    0.030     0.04
1     0.01    0.015     0.02
2     0.03    0.045     0.06
3     0.02    0.030     0.04
4     0.01    0.015     0.02

Matrix of Returns:
[0.020.030.040.010.0150.020.030.0450.060.020.030.040.010.0150.02]
Rank of the returns matrix: 1
The stock returns are linearly dependent.

The returns matrix has a rank of 1, meaning the vectors (columns) are linearly dependent. In financial terms, this means the returns of these stocks are not unique, so diversification has less potential benefit.

References:

  1. "Financial Engineering and Risk Management". Coursera, www.coursera.org/specializations/financialengineering. Last accessed 24 Aug. 2024.

  2. "NumPy documentation — NumPy v2.1 Manual". NumPy -, numpy.org/doc/stable. Last accessed 24 Aug 2024.

  3. "WQU | Master of Science in Financial Engineering · WQU". WQU | A Leader in Global Education · WQU, www.wqu.edu/mscfe?utm_term=worldquant%20university&utm_campaign=GA_MScFE_SEA_GKW+BKW_WW&utm_source=adwords&utm_medium=ppc&hsa_acc=1450481729&hsa_cam=18879661171&hsa_grp=142652472959&hsa_ad=634265330876&hsa_src=g&hsa_tgt=kwd-365833978550&hsa_kw=worldquant%20university&hsa_mt=b&hsa_net=adwords&hsa_ver=3&gad_source=1&gclid=CjwKCAjwiaa2BhAiEiwAQBgyHk5oR6aQvbAQDkK_znzHUT5523KyleBQZJW2wiqJB_x6reoBOECdGRoCPIsQAvD_BwE. Last accessed 24 Aug 2024.


Коментарі

Популярні дописи з цього блогу

Basis

Learn how to build games with HTML

Four Stances of Zhan Zhuang