这是用户在 2024-10-31 12:46 为 https://app.immersivetranslate.com/pdf-pro/121715c1-f8b1-4088-b2e2-a357d0396a17 保存的双语快照页面,由 沉浸式翻译 提供双语支持。了解如何保存?
In [1]: import pandas as pd
在 [1] 中:导入 pandas 为 pd

import numpy as np 导入 numpy 为 np
import matplotlib.pyplot as plt
import seaborn as sns
import scipy.stats as stats
导入 scipy.stats 为 stats

data = pd.read_csv(r’D:\USYD\Math2070\Computer project\project_data.csv’)
data = pd.read_csv(r'D:\USYD\Math2070\Computer project\project_data.csv')

Question 1  问题 1

In [3]: print(data.head(10))
在 [3] 中: print(data.head(10))

print(data.shape)
Date 日期 BHP CBA CSL NAB WBC ANZ MQG WES quad\quad \ WES quad\quad \
0 2022 07 01 2022 07 01 2022-07-012022-07-01 33.62 81.91 260.65 24.64 17.21 19.16 151.74 38.63
1 2022 07 04 2022 07 04 2022-07-042022-07-04 33.49 82.59 266.04 24.85 17.43 19.40 154.43 39.60
2 2022 07 05 2022 07 05 2022-07-052022-07-05 33.57 82.39 270.05 24.77 17.43 19.33 155.85 39.82
3 2022 07 06 2022 07 06 2022-07-062022-07-06 31.69 83.09 277.01 25.22 17.59 19.51 156.75 40.47
4 2022 07 07 2022 07 07 2022-07-072022-07-07 32.68 84.06 277.85 25.22 17.72 19.86 157.67 41.04
5 2022 07 08 2022 07 08 2022-07-082022-07-08 32.92 83.62 278.19 25.18 17.67 19.77 157.70 41.02
6 2022 07 11 2022 07 11 2022-07-112022-07-11 31.90 83.58 278.81 24.87 17.67 19.67 155.08 40.73
7 2022 07 12 2022 07 12 2022-07-122022-07-12 31.44 84.56 283.36 25.20 17.81 19.77 154.91 41.04
8 2022 07 13 2022 07 13 2022-07-132022-07-13 30.99 85.46 284.44 25.48 17.86 19.53 158.36 41.53
9 2022 07 14 2022 07 14 2022-07-142022-07-14 31.39 84.19 286.76 25.35 17.67 19.10 157.99 41.71
Date BHP CBA CSL NAB WBC ANZ MQG WES quad \ 0 2022-07-01 33.62 81.91 260.65 24.64 17.21 19.16 151.74 38.63 1 2022-07-04 33.49 82.59 266.04 24.85 17.43 19.40 154.43 39.60 2 2022-07-05 33.57 82.39 270.05 24.77 17.43 19.33 155.85 39.82 3 2022-07-06 31.69 83.09 277.01 25.22 17.59 19.51 156.75 40.47 4 2022-07-07 32.68 84.06 277.85 25.22 17.72 19.86 157.67 41.04 5 2022-07-08 32.92 83.62 278.19 25.18 17.67 19.77 157.70 41.02 6 2022-07-11 31.90 83.58 278.81 24.87 17.67 19.67 155.08 40.73 7 2022-07-12 31.44 84.56 283.36 25.20 17.81 19.77 154.91 41.04 8 2022-07-13 30.99 85.46 284.44 25.48 17.86 19.53 158.36 41.53 9 2022-07-14 31.39 84.19 286.76 25.35 17.67 19.10 157.99 41.71 | | Date | BHP | CBA | CSL | NAB | WBC | ANZ | MQG | WES $\quad$ \ | | | :--- | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | | 0 | $2022-07-01$ | 33.62 | 81.91 | 260.65 | 24.64 | 17.21 | 19.16 | 151.74 | 38.63 | | | 1 | $2022-07-04$ | 33.49 | 82.59 | 266.04 | 24.85 | 17.43 | 19.40 | 154.43 | 39.60 | | | 2 | $2022-07-05$ | 33.57 | 82.39 | 270.05 | 24.77 | 17.43 | 19.33 | 155.85 | 39.82 | | | 3 | $2022-07-06$ | 31.69 | 83.09 | 277.01 | 25.22 | 17.59 | 19.51 | 156.75 | 40.47 | | | 4 | $2022-07-07$ | 32.68 | 84.06 | 277.85 | 25.22 | 17.72 | 19.86 | 157.67 | 41.04 | | | 5 | $2022-07-08$ | 32.92 | 83.62 | 278.19 | 25.18 | 17.67 | 19.77 | 157.70 | 41.02 | | | 6 | $2022-07-11$ | 31.90 | 83.58 | 278.81 | 24.87 | 17.67 | 19.67 | 155.08 | 40.73 | | | 7 | $2022-07-12$ | 31.44 | 84.56 | 283.36 | 25.20 | 17.81 | 19.77 | 154.91 | 41.04 | | | 8 | $2022-07-13$ | 30.99 | 85.46 | 284.44 | 25.48 | 17.86 | 19.53 | 158.36 | 41.53 | | | 9 | $2022-07-14$ | 31.39 | 84.19 | 286.76 | 25.35 | 17.67 | 19.10 | 157.99 | 41.71 | |
GMG FMG
0 17.75 13.25
1 18.25 13.31
2 18.08 13.50
3 18.77 12.85
4 18.69 13.41
5 18.48 13.49
6 18.17 13.13
7 18.11 13.17
8 18.53 13.24
9 18.35 13.57
( 505 , 11 ) ( 505 , 11 ) (505,11)(505,11)
GMG FMG 0 17.75 13.25 1 18.25 13.31 2 18.08 13.50 3 18.77 12.85 4 18.69 13.41 5 18.48 13.49 6 18.17 13.13 7 18.11 13.17 8 18.53 13.24 9 18.35 13.57 (505,11) | | GMG | FMG | | :--- | ---: | ---: | | 0 | 17.75 | 13.25 | | 1 | 18.25 | 13.31 | | 2 | 18.08 | 13.50 | | 3 | 18.77 | 12.85 | | 4 | 18.69 | 13.41 | | 5 | 18.48 | 13.49 | | 6 | 18.17 | 13.13 | | 7 | 18.11 | 13.17 | | 8 | 18.53 | 13.24 | | 9 | 18.35 | 13.57 | | $(505,11)$ | | |
In [4]: returns = data.iloc[:, 1:].pct_change().dropna()
在 [4] 中: returns = data.iloc[:, 1:].pct_change().dropna()

print(returns.head())
BHP CBA CSL NAB WBC ANZ MQG \
1 -0.003867 0.008302 0.020679 0.008523 0.012783 0.012526 0.017728
2 0.002389 -0.002422 0.015073 -0.003219 0.000000 -0.003608 0.009195
3 -0.056002 0.008496 0.025773 0.018167 0.009180 0.009312 0.005775
4 0.031240 0.011674 0.003032 0.000000 0.007391 0.017940 0.005869
5 0.007344 -0.005234 0.001224 -0.001586 -0.002822 -0.004532 0.000190
BHP CBA CSL NAB WBC ANZ MQG \ 1 -0.003867 0.008302 0.020679 0.008523 0.012783 0.012526 0.017728 2 0.002389 -0.002422 0.015073 -0.003219 0.000000 -0.003608 0.009195 3 -0.056002 0.008496 0.025773 0.018167 0.009180 0.009312 0.005775 4 0.031240 0.011674 0.003032 0.000000 0.007391 0.017940 0.005869 5 0.007344 -0.005234 0.001224 -0.001586 -0.002822 -0.004532 0.000190 | | BHP | CBA | CSL | NAB | WBC | ANZ | MQG | \ | | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | | 1 | -0.003867 | 0.008302 | 0.020679 | 0.008523 | 0.012783 | 0.012526 | 0.017728 | | | 2 | 0.002389 | -0.002422 | 0.015073 | -0.003219 | 0.000000 | -0.003608 | 0.009195 | | | 3 | -0.056002 | 0.008496 | 0.025773 | 0.018167 | 0.009180 | 0.009312 | 0.005775 | | | 4 | 0.031240 | 0.011674 | 0.003032 | 0.000000 | 0.007391 | 0.017940 | 0.005869 | | | 5 | 0.007344 | -0.005234 | 0.001224 | -0.001586 | -0.002822 | -0.004532 | 0.000190 | |
WES GMG FMG
1 0.025110 0.028169 0.004528
2 0.005556 -0.009315 0.014275
3 0.016323 0.038164 -0.048148
4 0.014085 -0.004262 0.043580
5 -0.000487 -0.011236 0.005966
WES GMG FMG 1 0.025110 0.028169 0.004528 2 0.005556 -0.009315 0.014275 3 0.016323 0.038164 -0.048148 4 0.014085 -0.004262 0.043580 5 -0.000487 -0.011236 0.005966| | WES | GMG | FMG | | :--- | ---: | ---: | ---: | | 1 | 0.025110 | 0.028169 | 0.004528 | | 2 | 0.005556 | -0.009315 | 0.014275 | | 3 | 0.016323 | 0.038164 | -0.048148 | | 4 | 0.014085 | -0.004262 | 0.043580 | | 5 | -0.000487 | -0.011236 | 0.005966 |
The returns for each stock have been calculated. Proceed to compute the mean and covariance matrix. As per the requirement, the results will be rounded to six decimal places.
已计算出每只股票的收益。继续计算均值和协方差矩阵。根据要求,计算结果将四舍五入到小数点后六位。
In [6]: 在 [6] 中:
r = returns.mean().round(6)
print(r)
BHP 0.000529 必和必拓 0.000529
CBA 0.000894
CSL 0.000294
NAB 0.000826
WBC 0.000974 白细胞 0.000974
ANZ 0.000828
MQG 0.000686
WES 0.001077
GMG 0.001472
FMG 0.001064
dtype: float64
In [7]: C = cov_matrix = returns.cov().round(6)
在 [7] 中:C = cov_matrix = returns.cov().round(6)

print© 打印
BHP CBA CSL NAB WBC ANZ MQG }
BHP 0.000224 0.000038 0.000004 0.000035 0.000036 0.000034 0.000074
CBA 0.000038 0.000106 0.000041 0.000091 0.000090 0.000080 0.000077
CSL 0.000004 0.000041 0.000123 0.000031 0.000029 0.000029 0.000045
NAB 0.000035 0.000091 0.000031 0.000120 0.000099 0.000089 0.000081
WBC 0.000036 0.000090 0.000029 0.000099 0.000126 0.000095 0.000079
ANZ 0.000034 0.000080 0.000029 0.000089 0.000095 0.000115 0.000078
MQG 0.000074 0.000077 0.000045 0.000081 0.000079 0.000078 0.000185
WES 0.000046 0.000063 0.000051 0.000059 0.000061 0.000058 0.000086
GMG 0.000052 0.000075 0.000064 0.000066 0.000066 0.000068 0.000113
FMG 0.000230 0.000040 0.000005 0.000040 0.000044 0.000043 0.000096
BHP CBA CSL NAB WBC ANZ MQG } BHP 0.000224 0.000038 0.000004 0.000035 0.000036 0.000034 0.000074 CBA 0.000038 0.000106 0.000041 0.000091 0.000090 0.000080 0.000077 CSL 0.000004 0.000041 0.000123 0.000031 0.000029 0.000029 0.000045 NAB 0.000035 0.000091 0.000031 0.000120 0.000099 0.000089 0.000081 WBC 0.000036 0.000090 0.000029 0.000099 0.000126 0.000095 0.000079 ANZ 0.000034 0.000080 0.000029 0.000089 0.000095 0.000115 0.000078 MQG 0.000074 0.000077 0.000045 0.000081 0.000079 0.000078 0.000185 WES 0.000046 0.000063 0.000051 0.000059 0.000061 0.000058 0.000086 GMG 0.000052 0.000075 0.000064 0.000066 0.000066 0.000068 0.000113 FMG 0.000230 0.000040 0.000005 0.000040 0.000044 0.000043 0.000096 | | BHP | CBA | CSL | NAB | WBC | ANZ | MQG | } | | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | | BHP | 0.000224 | 0.000038 | 0.000004 | 0.000035 | 0.000036 | 0.000034 | 0.000074 | | | CBA | 0.000038 | 0.000106 | 0.000041 | 0.000091 | 0.000090 | 0.000080 | 0.000077 | | | CSL | 0.000004 | 0.000041 | 0.000123 | 0.000031 | 0.000029 | 0.000029 | 0.000045 | | | NAB | 0.000035 | 0.000091 | 0.000031 | 0.000120 | 0.000099 | 0.000089 | 0.000081 | | | WBC | 0.000036 | 0.000090 | 0.000029 | 0.000099 | 0.000126 | 0.000095 | 0.000079 | | | ANZ | 0.000034 | 0.000080 | 0.000029 | 0.000089 | 0.000095 | 0.000115 | 0.000078 | | | MQG | 0.000074 | 0.000077 | 0.000045 | 0.000081 | 0.000079 | 0.000078 | 0.000185 | | | WES | 0.000046 | 0.000063 | 0.000051 | 0.000059 | 0.000061 | 0.000058 | 0.000086 | | | GMG | 0.000052 | 0.000075 | 0.000064 | 0.000066 | 0.000066 | 0.000068 | 0.000113 | | | FMG | 0.000230 | 0.000040 | 0.000005 | 0.000040 | 0.000044 | 0.000043 | 0.000096 | |
WES GMG FMG
BHP 0.000046 0.000052 0.000230
CBA 0.000063 0.000075 0.000040
CSL 0.000051 0.000064 0.000005
NAB 0.000059 0.000066 0.000040
WBC 0.000061 0.000066 0.000044
ANZ 0.000058 0.000068 0.000043
MQG 0.000086 0.000113 0.000096
WES 0.000135 0.000113 0.000048
GMG 0.000113 0.000279 0.000075
FMG 0.000048 0.000075 0.000430
WES GMG FMG BHP 0.000046 0.000052 0.000230 CBA 0.000063 0.000075 0.000040 CSL 0.000051 0.000064 0.000005 NAB 0.000059 0.000066 0.000040 WBC 0.000061 0.000066 0.000044 ANZ 0.000058 0.000068 0.000043 MQG 0.000086 0.000113 0.000096 WES 0.000135 0.000113 0.000048 GMG 0.000113 0.000279 0.000075 FMG 0.000048 0.000075 0.000430| | WES | GMG | FMG | | :--- | ---: | ---: | ---: | | BHP | 0.000046 | 0.000052 | 0.000230 | | CBA | 0.000063 | 0.000075 | 0.000040 | | CSL | 0.000051 | 0.000064 | 0.000005 | | NAB | 0.000059 | 0.000066 | 0.000040 | | WBC | 0.000061 | 0.000066 | 0.000044 | | ANZ | 0.000058 | 0.000068 | 0.000043 | | MQG | 0.000086 | 0.000113 | 0.000096 | | WES | 0.000135 | 0.000113 | 0.000048 | | GMG | 0.000113 | 0.000279 | 0.000075 | | FMG | 0.000048 | 0.000075 | 0.000430 |
This match the result provided from the document which means the calculation is correct.
这与文件中提供的结果一致,说明计算是正确的。
Question 2 问题 2
In [10]: e = np.ones((10, 1))
在 [10] 中: e = np.ones((10, 1))

a = np.matmul(np.matmul(e.T, np.linalg.inv©), e).item()
b = np.matmul(np.matmul(e.T, np.linalg.inv©), r).item()
c = np.matmul(np.matmul(r.T, np.linalg.inv©), r).item()
d = a c b 2 d = a c b 2 d=a**c-b^(****2)\mathrm{d}=\mathrm{a} * \mathrm{c}-\mathrm{b}{ }^{* * 2}
In [11]: alpha = np.matmul(np.linalg.inv©, e) / a
在 [11] 中: alpha = np.matmul(np.linalg.inv©, e) / a

np.shape(alpha)
alpha.round(2)
[ 0.06],
[ 0.36],
[ 0.11],
[ 0.05],
[ 0.2 ],
[-0.06],
[ 0.12],
[-0.03],
[-0.01]])
In [12]: new_shape_r = r.values.reshape(10, 1)
在 [12] 中: new_shape_r = r.values.reshape(10, 1)

beta = np.matmul(np.linalg.inv ( C ) ( C ) (C)(C), (new_shape_r - b / a * e))
beta.round(2)
Out[12]: array([[-4.05], Out[12]: array([[-4.05]、
[ 2.8 ],
[-5.6 ],
[-1.81],
[ 3.41],
[-1.71],
[-2.84],
[ 3.77],
[ 3.37],
[ 2.67]])
Hence, unrestricted critical line is:
因此,不受限制的临界线是
x 1 ( t ) = 0.21 + 4.05 t x 2 ( t ) = 0.06 + 2.80 t x 3 ( t ) = 0.36 + 5.60 t x 4 ( t ) = 0.11 + 1.81 t x 5 ( t ) = 0.05 + 3.41 t x 6 ( t ) = 0.20 + 1.71 t x 7 ( t ) = 0.06 + 2.84 t x 8 ( t ) = 0.12 + 3.77 t x 9 ( t ) = 0.03 + 3.37 t x 10 ( t ) = 0.01 + 2.67 t x 1 ( t ) = 0.21 + 4.05 t x 2 ( t ) = 0.06 + 2.80 t x 3 ( t ) = 0.36 + 5.60 t x 4 ( t ) = 0.11 + 1.81 t x 5 ( t ) = 0.05 + 3.41 t x 6 ( t ) = 0.20 + 1.71 t x 7 ( t ) = 0.06 + 2.84 t x 8 ( t ) = 0.12 + 3.77 t x 9 ( t ) = 0.03 + 3.37 t x 10 ( t ) = 0.01 + 2.67 t {:[x_(1)(t)=0.21+4.05 t],[x_(2)(t)=0.06+2.80 t],[x_(3)(t)=0.36+5.60 t],[x_(4)(t)=0.11+1.81 t],[x_(5)(t)=0.05+3.41 t],[x_(6)(t)=0.20+1.71 t],[x_(7)(t)=-0.06+2.84 t],[x_(8)(t)=0.12+3.77 t],[x_(9)(t)=-0.03+3.37 t],[x_(10)(t)=-0.01+2.67 t]:}\begin{aligned} x_{1}(t) & =0.21+4.05 t \\ x_{2}(t) & =0.06+2.80 t \\ x_{3}(t) & =0.36+5.60 t \\ x_{4}(t) & =0.11+1.81 t \\ x_{5}(t) & =0.05+3.41 t \\ x_{6}(t) & =0.20+1.71 t \\ x_{7}(t) & =-0.06+2.84 t \\ x_{8}(t) & =0.12+3.77 t \\ x_{9}(t) & =-0.03+3.37 t \\ x_{10}(t) & =-0.01+2.67 t \end{aligned}
For optimal portfolio, there is no short-selling for any t 0 t 0 t >= 0t \geq 0, which is:
在最优投资组合中,任何 t 0 t 0 t >= 0t \geq 0 都不会卖空,即
Asset 2: CBA 资产 2:成本效益分析
Asset 5: WBC 资产 5:周转基金
Asset 8: WES 资产 8:WES

Question 3A: 问题 3A:

In [16]: t = 0.06 t = 0.06 t=0.06t=0.06 在 [16] 中: t = 0.06 t = 0.06 t=0.06t=0.06
x = alpha + beta * t
print(x)
[[-0.03355909]
[ 0.2235898 ]
[ 0.02305524]
[ 0.00112341]
[ 0.25561903]
[ 0.09742369]
[-0.22592595]
[ 0.3417103 ]
[ 0.17063291]
[ 0.14633065]]
In [17]: dollars_sum = 100000
在 [17] 中: dollars_sum = 100000

dollars_investment = x * dollars_sum
投资额 = x * 投资总额

dollars_investment.round(2)
Out[17]: array([ [ -3355.91],
Out[17]: array([ -3355.91]、

[ 22358.98],
[ 2305.52],
[ 112.34],
[ 25561.9 ],
[ 9742.37],
[-22592.59],
[ 34171.03],
[ 17063.29],
[ 14633.07]])
For an investor with a risk aversion parameter t = 0.06 t = 0.06 t=0.06t=0.06, the optimal investment proportions are as follows:
对于风险规避参数为 t = 0.06 t = 0.06 t=0.06t=0.06 的投资者来说,最优投资比例如下:
Asset 1 (BHP): -3.36% (indicating a short position)
资产 1 (BHP):-3.36%(表示空头头寸)

Asset 2 (CBA): 22.36% 资产 2(CBA):22.36%
Asset 3 (CSL): 2.31% 资产 3(CSL):2.31
Asset 4 (NAB): 0.11% 资产 4(NAB):0.11
Asset 5 (WBC): 25.56% 资产 5(WBC):25.56
Asset 6 (ANZ): 9.74% 资产 6(澳新银行):9.74%
Asset 7 (MQG): -22.59% (indicating a short position)
资产 7 (MQG):-22.59%(显示为空头头寸)

Asset 8 (WES): 34.17% 资产 8 (WES):34.17%
Asset 9 (GMG): 17.06% 资产 9(GMG):17.06
Asset 10 (FMG): 14.63% 资产 10(FMG):14.63
This portfolio includes both long and short positions, with short positions taken on BHP and MQG. BHP and MQG.
该投资组合包括多头和空头头寸,空头头寸为 BHP 和 MQG。BHP 和 MQG。
If this investor allocates $100,000, the dollar amounts invested in each asset would be:
如果该投资者分配了 100 000 美元,那么投资于每种资产的美元金额将是
Asset 1 (BHP): -$3,355.91 (indicating a short position)
资产 1 (BHP):-3,355.91 美元(表示空头头寸)
Asset 2 (CBA): $22,358.98
资产 2(CBA):22 358.98 美元

Asset 3 (CSL): $2,305.52 资产 3(CSL):2 305.52 美元
Asset 4 (NAB): $112.34 资产 4(NAB):112.34 美元
Asset 5 (WBC): $25,561.90
资产 5(世界广播公司):25,561.90 美元

Asset 6 (ANZ): $9,742.37 资产 6(澳新银行):9 742.37 美元
Asset 7 (MQG): - $ 22 , 592.59 $ 22 , 592.59 $22,592.59\$ 22,592.59 (indicating a short position)
资产 7 (MQG):- $ 22 , 592.59 $ 22 , 592.59 $22,592.59\$ 22,592.59 (表示空头头寸)

Asset 8 (WES): $34,171.03
资产 8(WES):34,171.03 美元

Asset 9 (GMG): $17,063.29
资产 9(GMG):17 063.29 美元

Asset 10 (FMG): $14,633.07
资产 10(财务管理小组):14,633.07 美元

Since Asset 1 (BHP) and Asset 7 (MQG) show negative allocations, the investor intends to take short positions in these assets, expecting their values to decline and aiming to profit from the decrease.
由于资产 1(BHP)和资产 7(MQG)的分配为负值,投资者打算在这些资产上建立空头头寸,预期其价值会下降,并希望从下降中获利。
In [20]: 在 [20] 中:
Expected_return = np.dot(x.T, new_shape_r).round(5).item()
print("Expected return " + str(Expected_return))
C = C.to_numpy() if isinstance(C, pd.DataFrame) else C
Risk = np.sqrt(np.matmul(np.matmul(x.T, C), x).item()).round(5)
print("Risk " + str(Risk))
Expected return 0.00114 预期收益率 0.00114
Risk 0.00958 风险 0.00958
Based on the given portfolio, the expected return is 0.00114 (or 0.114 % 0.114 % 0.114%0.114 \% ). The associated risk, measured by the portfolio’s standard deviation (volatility), is 0.00958 (or 0.958%).
根据给定的投资组合,预期收益为 0.00114(或 0.114 % 0.114 % 0.114%0.114 \% )。用投资组合的标准差(波动率)来衡量,相关风险为 0.00958(或 0.958%)。
In other words, with the current asset allocation, investors can anticipate an average return of 0.114 % 0.114 % 0.114%0.114 \% accompanied by a potential price fluctuation or risk level of 0.958 % 0.958 % 0.958%0.958 \%.
换句话说,在目前的资产配置下,投资者可以预期平均回报率为 0.114 % 0.114 % 0.114%0.114 \% ,而潜在的价格波动或风险水平为 0.958 % 0.958 % 0.958%0.958 \%

Question 3B: 问题 3B:

In [23]: from scipy.optimize import minimize
在 [23] 中: from scipy.optimize import minimize
def f(x):
return x @ (C @ x)
def c(x):
return sum(x) - 1
cons = [{‘type’: ‘eq’, ‘fun’: c}]
cons = [{'类型':'等式','函数':c}]

print(“minimize solution”)
print("minimize solution")

soln = minimize(
f,
        np.array([0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1]),
        constraints=cons,
        tol=1e-15,
        bounds=[(0, None)] * 10
)
x_MVP = soln.x.reshape(10, 1)
print(x_MVP)
minimize solution 最小化解决方案
[[1.85059987e-01]
[4.48396402e-02]
[3.51890774e-01]
[1.01056725e-01]
[5.24931498e-02]
[1.84793567e-01]
[4.80542967e-18]
[7.98661568e-02]
[0.00000000e+00]
[0.00000000e+00]]
In [24] 在 [24] 中
dollars_sum = 100000
dollars_inversment = x_MVP * dollars_sum
dollars_inversment.round(2)
Out[24]: array([[18506. ],
Out[24]: array([[18506. ]、

[ 4483.96],
[35189.08],
[10105.67],
[ 5249.31],
[18479.36],
[ 0. ],
[ 7986.62],
[ 0. ],
[ 0. ]])
In [25] 在 [25] 中
expected_return = np.dot(soln.x, r).round(5)
print("Expected return " + str(float(expected_return)))
Expected return 0.00062 预期收益率 0.00062
In [26]: risk = np.sqrt(soln.x @ C @ soln.x).round(5)
在 [26] 中: risk = np.sqrt(soln.x @ C @ soln.x).round(5)

print("Risk " + str(float(risk)))

Risk 0.00774 风险 0.00774

In [27] 在 [27] 中
grad = 2 * C @ soln.x
print("Gradient:", grad)
print("Is Gradient Close to 0:", np.allclose(grad, 0, atol=1e-8))
print("Sum of Weights is 1:", np.isclose(np.sum(soln.x), 1, atol=1e-8))
print("Are All Weights Non-Negative:", np.all(soln.x >= 0))
Gradient: [0.0001199 0.0001199 0.0001199 0.0001199 0.0001199
                                    0.0001199
    0.00013319 0.0001199 0.00013446 0.0001285 ]
Is Gradient Close to 0: False
梯度是否接近 0:假

Sum of Weights is 1: True
权重之和为 1:真

Are All Weights Non-Negative: True
所有砝码都是非负数吗?真
  1. For a specific investor with a risk aversion parameter of t = 0.06 t = 0.06 t=0.06t=0.06, without shortselling for any asset, their optimal investment proportions are as follows:
    对于风险规避参数为 t = 0.06 t = 0.06 t=0.06t=0.06 的特定投资者来说,在不卖空任何资产的情况下,其最优投资比例如下:
Asset 1 BHP: 18.51% 资产 1 必和必拓:18.51
Asset 2 CBA: 4.48% 资产 2 CBA:4.48%
Asset 3 CSL: 35.19% 资产 3 CSL:35.19
Asset 4 NAB: 10.11% 资产 4 NAB:10.11
Asset 5 WBC: 5.25% 资产 5 周转基金:5.25
Asset 6 ANZ: 18.48% 资产 6 澳新银行:18.48
Asset 7 MQG: 0.00% 资产 7 MQG: 0.00
Asset 8 WES: 7.99% 资产 8 WES:7.99
Asset 9 GMG: 0.00% 资产 9 GMG: 0.00
Asset 10 FMG: 0.00% 资产 10 FMG: 0.00
2. If this investor plans to invest $ 100 , 000 $ 100 , 000 $100,000\$ 100,000 dollars, their dollar allocations in each asset would be:
2.如果该投资者计划投资 $ 100 , 000 $ 100 , 000 $100,000\$ 100,000 美元,那么他们在每种资产中的美元分配情况将是:
Asset 1 BHP: $18,506.00 资产 1 BHP:18 506.00 美元
Asset 2 CBA: $4,483.96 资产 2 CBA:4,483.96 美元
Asset 3 CSL: $35,189.08 资产 3 CSL:35,189.08 美元
Asset 4 NAB: $10,105.67 资产 4 NAB:10 105.67 美元
Asset 5 WBC: $5,249.32 资产 5 周转基金:5 249.32 美元
Asset 6 ANZ: $18,479.35 资产 6 澳新银行:18 479.35 美元
Asset 7 MQG: $0.00 资产 7 MQG: 0.00 美元
Asset 8 WES: $7,986.62 资产 8 WES:7 986.62 美元
Asset 9 GMG: $0.00 资产 9 GMG: $0.00
Asset 10 FMG: $0.00 资产 10 FMG: $0.00
For the given portfolio, the expected return is 0.00062 ( 0.062 % 0.062 % 0.062%0.062 \% ). Meanwhile, the risk (standard deviation or volatility) of the portfolio is 0.00774 (0.774%).
对于给定的投资组合,预期收益率为 0.00062 ( 0.062 % 0.062 % 0.062%0.062 \% )。同时,投资组合的风险(标准差或波动率)为 0.00774(0.774%)。
This means that, based on the current asset allocation, investors can expect an average return of 0.062 % 0.062 % 0.062%0.062 \% with an accompanying risk or price fluctuation of 0.774%.
这意味着,根据目前的资产配置,投资者可以预期平均收益为 0.062 % 0.062 % 0.062%0.062 \% ,伴随的风险或价格波动为 0.774%。

Question 4: 问题 4:

In [30]: t = 0.06 t = 0.06 t=0.06t=0.06 在 [30] 中: t = 0.06 t = 0.06 t=0.06t=0.06
    mu_opt = (b + d * t) / a
    sig_opt = np.sqrt((1 + d * t ** 2) / a)
print(round(mu_opt, 6), round(sig_opt, 6))
0.0011390 .00958
In [31]: Minimum_risk_sig = np.sqrt(1 / a)
在 [31] 中:Minimum_risk_sig = np.sqrt(1 / a)

Minimum_risk_mu = b / a
最小风险值 = b / a
print(round(Minimum_risk_mu, 6), round(Minimum_risk_sig, 6))

0.0005980 .0077

In [32]: t_range = np.linspace(-0.25, 0.25, 5000)
在 [32] 中: t_range = np.linspace(-0.25, 0.25, 5000)
ret = []
sig = []
ret1 = []
sig1 = []
vertex_mu = b / a
for i in t_range:
    if (b + d * i) / a >= vertex_mu:
        ret.append((b + d * i) / a)
        sig.append(np.sqrt((1 + d * i**2) / a))
    else:
        ret1.append((b + d * i) / a)
        sig1.append(np.sqrt((1 + d * i**2) / a))
Utility_opt = t * mu_opt - 0.5 * sig_opt**2
sigma_range = np.linspace(0.005, 0.025, 5000)
mu_index = []
for i in sigma_range:
    mu_index.append((0.5 * i**2 + Utility_opt) / t)
In [33]: plt.figure(figsize=(60, 30))
在 [33] 中: plt.figure(figsize=(60, 30))
plt.plot(sig, ret, label="Efficient Frontier")
plt.plot(sig1, ret1, label=“Inefficient Frontier”, linestyle="-.")
plt.plot(sig1, ret1, label="Inefficient Frontier", linestyle="-.")

plt.plot(sigma_range, mu_index, label=“Indifference Curve”)
plt.plot(sigma_range, mu_index, label="Indifference Curve")

plt.plot(returns.std(), r, “o”, label=“10 Investment Funds”, markersize=20)
plt.plot(returns.std(), r, "o", label="10 Investment Funds", markersize=20)

plt.plot(sig_opt, mu_opt, “o”, label=“Optimal Portfolio”, markersize=22)
plt.plot(sig_opt, mu_opt, "o", label="最佳投资组合", markersize=22)

plt.plot(Minimum_risk_sig, Minimum_risk_mu, “o”, label=“Minimum Risk Portfolio”,
plt.plot(Minimum_risk_sig, Minimum_risk_mu, "o", label="最低风险组合"、

plt.xlabel(r"$\sigma$", fontsize=40)
plt.ylabel(r"$\mu$", fontsize=40)
plt.title(
"Graph of MVF, EF, IEF, Optimal Portfolio, Minimum Risk Portfolio & Indiffer
"MVF、EF、IEF、最佳投资组合、最低风险投资组合和无差异投资组合图表

fontsize=40
)
plt.legend(fontsize=36)
plt.show()
  • Optimal Portfolio 最佳投资组合
  • Minimum Risk Portfolio 最低风险组合
In the μ σ μ σ mu-sigma\mu-\sigma plane:
μ σ μ σ mu-sigma\mu-\sigma 平面上:
  1. The Minimum Variance Frontier (MVF) is represented as a hyperbola, given by the equation:
    最小方差边界(MVF)用双曲线表示,其方程为
σ 2 = 1 a + a d ( μ b a ) 2 σ 2 = 1 a + a d μ b a 2 sigma^(2)=(1)/(a)+(a)/(d)(mu-(b)/(a))^(2)\sigma^{2}=\frac{1}{a}+\frac{a}{d}\left(\mu-\frac{b}{a}\right)^{2}
This curve forms the critical line and is depicted by the blue solid curve and the yellow dashed curve.
这条曲线构成临界线,用蓝色实线和黄色虚线表示。

2. The Efficient Frontier (EF) corresponds to the upper branch of the hyperbola, where:
2.高效边界(EF)对应于双曲线的上分支,其中:
μ > b a = 0.000598 μ > b a = 0.000598 mu > (b)/(a)=0.000598\mu>\frac{b}{a}=0.000598
This section is parameterized by the critical line with ( t > 0 t > 0 t > 0t>0 ) and is represented by the blue solid curve.
该部分以 ( t > 0 t > 0 t > 0t>0 ) 临界线为参数,用蓝色实心曲线表示。

3. The minimum risk portfolio, represented by the purple dot on the plane, is the vertex of the hyperbola. It corresponds to:
3.平面上的紫色圆点所代表的最小风险组合是双曲线的顶点。它对应于
t = 0 , μ 0 = b a = 0.000598 , σ 0 = 1 a = 0.0077 t = 0 , μ 0 = b a = 0.000598 , σ 0 = 1 a = 0.0077 t=0,quadmu_(0)=(b)/(a)=0.000598,quadsigma_(0)=sqrt((1)/(a))=0.0077t=0, \quad \mu_{0}=\frac{b}{a}=0.000598, \quad \sigma_{0}=\sqrt{\frac{1}{a}}=0.0077
  1. The lower branch of the hyperbola (( m u < f r a c { b } { a } ) ) m u < f r a c { b } { a } ) ) \\mu < \\frac{b}{a}))\backslash m u<\backslash f r a c\{b\}\{a\})) forms the inefficient frontier, which corresponds to the critical line with ( t < 0 t < 0 t < 0t<0 ). This is depicted by the yellow dashed curve.
    双曲线 (( m u < f r a c { b } { a } ) ) m u < f r a c { b } { a } ) ) \\mu < \\frac{b}{a}))\backslash m u<\backslash f r a c\{b\}\{a\})) 的下分支构成无效率边界,与临界线 ( t < 0 t < 0 t < 0t<0 ) 相对应。黄色虚线表示这条曲线。
  2. The purple dot on the plane represents the optimal portfolio when the risk aversion parameter ( t ) equals ( 0.06 ).
    平面上的紫色圆点代表风险规避参数 ( t ) 等于 ( 0.06 ) 时的最优投资组合。
  3. The ten red dots on the plane denote the average returns and risk volatility of the ten individual stocks.
    平面上的十个红点表示十只个股的平均收益和风险波动。
  4. For ( n = 10 ( n = 10 (n=10(\mathrm{n}=10 ), the feasible set ( F F FF ) is the interior of the hyperbola, also known as the bullet.
    对于 ( n = 10 ( n = 10 (n=10(\mathrm{n}=10 ),可行集 ( F F FF ) 是双曲线的内部,也称为子弹。

Question 5A: 问题 5A:

Let x ^ = ( x 0 , x ) x ^ = x 0 , x hat(x)=(x_(0),x)\hat{\boldsymbol{x}}=\left(x_{0}, \boldsymbol{x}\right) be the portfolio vector for the 1 + n 1 + n 1+n1+n assets, where x 0 x 0 x_(0)x_{0} is the allocation to the risk-free asset, and x x x\boldsymbol{x} is the portfolio vector for the n n nn risky assets.
x ^ = ( x 0 , x ) x ^ = x 0 , x hat(x)=(x_(0),x)\hat{\boldsymbol{x}}=\left(x_{0}, \boldsymbol{x}\right) 1 + n 1 + n 1+n1+n 资产的投资组合向量,其中 x 0 x 0 x_(0)x_{0} 为无风险资产的配置, x x x\boldsymbol{x} n n nn 风险资产的投资组合向量。
We will use μ ^ , σ ^ μ ^ , σ ^ hat(mu), hat(sigma)\hat{\mu}, \hat{\sigma}, etc., to represent quantities that include both the risk-free asset and the n n nn risky assets. Similarly, we will write μ , σ μ , σ mu,sigma\mu, \sigma, etc., when only the n n nn risky assets are involved.
我们将使用 μ ^ , σ ^ μ ^ , σ ^ hat(mu), hat(sigma)\hat{\mu}, \hat{\sigma} 等表示包括无风险资产和 n n nn 风险资产的数量。同样,当只涉及 n n nn 风险资产时,我们将使用 μ , σ μ , σ mu,sigma\mu, \sigma 等表示。
Budget Constraint 预算限制
The budget constraint takes the following form:
预算约束的形式如下
x 0 + i = 1 n x i = 1 x 0 + i = 1 n x i = 1 x_(0)+sum_(i=1)^(n)x_(i)=1x_{0}+\sum_{i=1}^{n} x_{i}=1

Expected Return Rate 预期回报率

The expected return rate of the 1 + n 1 + n 1+n1+n-asset portfolio is given by:
1 + n 1 + n 1+n1+n 资产组合的预期收益率为
μ ^ = x ^ T r ^ = x 0 r 0 + x T r μ ^ = x ^ T r ^ = x 0 r 0 + x T r hat(mu)= hat(x)^(T) hat(r)=x_(0)r_(0)+x^(T)r\hat{\mu}=\hat{\boldsymbol{x}}^{T} \hat{\boldsymbol{r}}=x_{0} r_{0}+\boldsymbol{x}^{T} \boldsymbol{r}
Since x 0 = 1 x T 1 x 0 = 1 x T 1 x_(0)=1-x^(T)1x_{0}=1-\boldsymbol{x}^{T} \mathbf{1}, the above can be rewritten as:
由于 x 0 = 1 x T 1 x 0 = 1 x T 1 x_(0)=1-x^(T)1x_{0}=1-\boldsymbol{x}^{T} \mathbf{1} ,上述公式可改写为
μ ^ = r 0 + x T ( r r 0 1 ) = r 0 + x T r μ ^ = r 0 + x T r r 0 1 = r 0 + x T r ¯ hat(mu)=r_(0)+x^(T)(r-r_(0)1)=r_(0)+x^(T) bar(r)\hat{\mu}=r_{0}+\boldsymbol{x}^{T}\left(\boldsymbol{r}-r_{0} \mathbf{1}\right)=r_{0}+\boldsymbol{x}^{T} \overline{\boldsymbol{r}}
where r = r r 0 1 r ¯ = r r 0 1 bar(r)=r-r_(0)1\overline{\boldsymbol{r}}=\boldsymbol{r}-r_{0} \mathbf{1} represents the excess return rate over the risk-free rate r 0 r 0 r_(0)r_{0}.
其中, r = r r 0 1 r ¯ = r r 0 1 bar(r)=r-r_(0)1\overline{\boldsymbol{r}}=\boldsymbol{r}-r_{0} \mathbf{1} 表示相对于无风险利率 r 0 r 0 r_(0)r_{0} 的超额收益率。

Portfolio Variance 投资组合差异
The portfolio variance is given by:
投资组合方差的计算公式为
σ ^ 2 = x T C x σ ^ 2 = x T C x hat(sigma)^(2)=x^(T)Cx\hat{\sigma}^{2}=\boldsymbol{x}^{T} \boldsymbol{C} \boldsymbol{x}
where C C C\boldsymbol{C} is the covariance matrix of the risky assets.
其中, C C C\boldsymbol{C} 是风险资产的协方差矩阵。

Optimal Solution 最佳解决方案

Assuming that C C C\boldsymbol{C} is invertible, the optimal solution is expressed as:
假设 C C C\boldsymbol{C} 是可逆的,则最优解表示为
x ^ ( t ) = [ 1 t e T C 1 r t C 1 r ] x ^ ( t ) = 1 t e T C 1 r ¯ t C 1 r ¯ hat(x)(t)=[[1-te^(T)C^(-1) bar(r)],[tC^(-1) bar(r)]]\hat{\boldsymbol{x}}(t)=\left[\begin{array}{c} 1-t e^{T} \boldsymbol{C}^{-1} \overline{\boldsymbol{r}} \\ t \boldsymbol{C}^{-1} \overline{\boldsymbol{r}} \end{array}\right]
for t 0 t 0 t >= 0t \geq 0.  t 0 t 0 t >= 0t \geq 0
In [37]: r 0 = 0.00015 r 0 = 0.00015 r0=0.00015r 0=0.00015 在 [37] 中: r 0 = 0.00015 r 0 = 0.00015 r0=0.00015r 0=0.00015
r_bar = new_shape_r - e * r0
new_optimal_portfolio = t * np.matmul(np.linalg.inv(C), r_bar)
print(new_optimal_portfolio)
[[-0.14790681]
    [ 0.19327912]
    [-0.17317226]
    [-0.05897882]
    [ 0.22757084]
    [-0.01199638]
    [-0.19561854]
    [ 0.27845899]
    [ 0.18774781]
    [ 0.1539242 ]]
    if determine_Value > 0:
        print("Lending portfolio")
    else:
        print("Borrowing portfolio")
In [38]: determine_Value = float(1 - t * np.matmul(np.matmul(e.T, np.linalg.inv©), r_ba
在 [38] 中: determine_Value = float(1 - t * np.matmul(np.matmul(e.T, np.linalg.inv©), r_ba
Lending portfolio 贷款组合
In [39]: print(round(determine_Value,6))
在 [39] 中: print(round(determine_Value,6))

0.546692

This portfolio strikes a balance between risk-free and risky assets, reflecting a blend of stability and growth. With 54.67 % 54.67 % 54.67%54.67 \% allocated to risk-free assets, the focus is on capital preservation and minimizing market volatility. Simultaneously, the use of both long and short positions in risky assets aims to capture upside potential while mitigating downside risks.
该投资组合在无风险资产和风险资产之间取得平衡,体现了稳定与增长的融合。 54.67 % 54.67 % 54.67%54.67 \% 分配给无风险资产,重点是保本和尽量减少市场波动。同时,利用风险资产的多头和空头头寸,旨在捕捉上涨潜力,同时降低下跌风险。

1. Allocation to Risk-Free Asset
1.无风险资产配置

54.67% of the portfolio is allocated to risk-free assets, reflecting a conservative approach focused on wealth preservation. This strategy indicates a low to moderate risk appetite, prioritizing stability and minimizing volatility.
投资组合的 54.67% 分配给了无风险资产,反映了以财富保值为重点的保守策略。这一策略表明,投资组合的风险偏好处于中低水平,优先考虑稳定性,尽量减少波动性。

3. Allocation to Risky Assets
3.风险资产分配

The remaining 45.33% of the portfolio is spread across various risky assets, balancing long and short positions for strategic market exposure:
其余 45.33% 的投资组合分布在各种风险资产上,平衡多头和空头头寸,以获得战略性的市场风险:
BHP: -14.79% (Short) - Anticipates declining value to profit from downturn.
BHP: -14.79% (空头) - 预期价值下降,从经济下滑中获利。

CBA: 19.33% (Long) - Reflects bullish outlook and expectations of strong gains.
CBA:19.33%(多头)--反映了看涨前景和对强劲涨势的预期。

CSL: -17.32% (Short) - Signals expectation of underperformance.
CSL: -17.32% (空头) - 预期表现不佳的信号。

NAB: -5.90% (Moderate Short) - Mild bearish sentiment or hedge.
NAB: -5.90% (适度看空) - 轻度看跌情绪或对冲。

WBC: 22.76% (Long) - Significant confidence in positive returns.
WBC: 22.76% (多头) - 对积极回报充满信心。

ANZ: -1.20% (Minimal Short) - Serves as a hedge for other positions.
澳新银行:-1.20%(最小空头)--作为其他仓位的对冲。

MQG: -19.56% (Aggressive Short) - Expects decline in value.
MQG: -19.56% (激进空头) - 预期价值下降。
WES: 27.85% (Largest Long) - Strong conviction in substantial gains.
WES:27.85%(最大多头)--坚信会有可观收益。

GMG: 18.77% (Long) - Optimism about future performance.
GMG: 18.77% (多头) - 对未来表现持乐观态度。

FMG: 15.39% (Long) - Expects favorable performance.
FMG:15.39%(多头)--预期表现良好。

This diversified approach reflects a mix of growth optimism and hedging against potential downturns.
这种多样化的方法既反映了对增长的乐观态度,也反映了对潜在衰退的对冲。

3. Strategic Insights and Risk Management
3.战略洞察和风险管理

Significant Allocation to Risk-Free Assets:
大量配置无风险资产:

54.67% allocation minimizes market volatility, reflecting a cautious approach in uncertain conditions.
54.67% 的分配最大限度地减少了市场波动,体现了在不确定条件下的谨慎态度。
Balanced Use of Long and Short Positions:
平衡使用多头和空头头寸:

A mix of long and short positions creates a flexible strategy, leveraging market opportunities while managing risks.
多头和空头头寸的组合创造了一种灵活的策略,既能利用市场机会,又能控制风险。
Key Focus on Selective Assets: Strong long positions in WES, WBC, and CBA signal optimism, while short positions in MQG, CSL, and BHP reflect bearish expectations.
重点关注选择性资产:WES、WBC 和 CBA 的强势多头头寸预示着乐观情绪,而 MQG、CSL 和 BHP 的空头头寸则反映了看跌预期。
Risk Mitigation through Hedging: Short positions hedge against potential losses in long positions, enhancing portfolio stability.
通过套期保值降低风险:空头头寸对冲多头头寸的潜在损失,增强投资组合的稳定性。

4. Conclusion 4.结论

This portfolio achieves a balanced strategy, combining capital preservation through significant risk-free asset allocation with growth opportunities via long and short positions. It reflects a prudent yet calculated approach, targeting upside potential while managing risks through strategic short positions.
该投资组合采用平衡策略,通过大量无风险资产配置实现资本保值,同时通过多头和空头头寸把握增长机会。它反映了一种审慎而又精打细算的方法,在通过战略性空头头寸管理风险的同时,瞄准上行潜力。
With a moderate risk appetite, the portfolio prioritizes stability while remaining actively engaged in the market to enhance returns. The blend of conservative and aggressive tactics demonstrates a sophisticated understanding of market dynamics and proactive risk management.
投资组合的风险偏好适中,以稳定为主,同时积极参与市场以提高回报。保守与激进策略的融合,体现了对市场动态的深刻理解和积极的风险管理。
Question 5B: 问题 5B:
The optimal portfolio x ^ ( t ) x ^ ( t ) hat(x)(t)\hat{x}(t) has:
最佳投资组合 x ^ ( t ) x ^ ( t ) hat(x)(t)\hat{x}(t) 有:
μ ^ ( t ) = r 0 + c ¯ t , and σ ^ 2 ( t ) = c ¯ t 2 μ ^ ( t ) = r 0 + c ¯ t ,  and  σ ^ 2 ( t ) = c ¯ t 2 hat(mu)(t)=r_(0)+ bar(c)t,quad" and "quad hat(sigma)^(2)(t)= bar(c)t^(2)\hat{\mu}(t)=r_{0}+\bar{c} t, \quad \text { and } \quad \hat{\sigma}^{2}(t)=\bar{c} t^{2}
where c ¯ = r T C 1 r c ¯ = r T C 1 r bar(c)=r^(T)C^(-1)r\bar{c}=\mathbf{r}^{T} C^{-1} \mathbf{r}. 其中 c ¯ = r T C 1 r c ¯ = r T C 1 r bar(c)=r^(T)C^(-1)r\bar{c}=\mathbf{r}^{T} C^{-1} \mathbf{r}
Moreover, the efficient frontier, known as the Capital Market Line (CML), is expressed as:
此外,被称为资本市场线(CML)的有效边界表示为
μ ^ = r 0 + c ¯ σ ^ or μ ^ = r 0 + σ 0 d σ ^ μ ^ = r 0 + c ¯ σ ^  or  μ ^ = r 0 + σ 0 d σ ^ hat(mu)=r_(0)+sqrt bar(c) hat(sigma)quad" or "quad hat(mu)=r_(0)+sigma_(0)sqrt(d hat(sigma))\hat{\mu}=r_{0}+\sqrt{\bar{c}} \hat{\sigma} \quad \text { or } \quad \hat{\mu}=r_{0}+\sigma_{0} \sqrt{d \hat{\sigma}}
where: 在哪里?
σ 0 2 = a d ( r 0 b a ) 2 + 1 a σ 0 2 = a d r 0 b a 2 + 1 a sigma_(0)^(2)=(a)/(d)(r_(0)-(b)/(a))^(2)+(1)/(a)\sigma_{0}^{2}=\frac{a}{d}\left(r_{0}-\frac{b}{a}\right)^{2}+\frac{1}{a}
In [43]: 在 [43] 中:
c_bar = np.matmul(np.matmul(r_bar.T, np.linalg.inv©), r_bar).item() print(c_bar)

0.012408176479107264

In [44]: mu_new = r0 + c_bar * t
在 [44] 中:mu_new = r0 + c_bar * t

sig_new = = == np.sqrt (c_bar * t 2 ) t 2 ) t****2)t * * 2)
sig_new = = == np.sqrt (c_bar * t 2 ) t 2 ) t****2)t * * 2) )

print(round(mu_new, 6), round(sig_new, 6))

0.0008940 .006684

In [45]: sigma = np.linspace(0, 0.025)
在 [45] 中: sigma = np.linspace(0, 0.025)

sigma0 = np.sqrt(a / d * (r0 - b / a) ** 2 + 1 / a)
mu_m = (c_bar - b * r0) / (b - a * rө)
sigma_m = sigma0 * np.sqrt(d) / (b - a * r0)
round(mu_m, 6), round(sigma_m,6)
Out [45]: (0.001442, 0.014744)
输出[45]:(0.001442,0.014744)

μ M = c b r 0 b a r 0 μ M = c b r 0 b a r 0 mu_(M)=(c-br_(0))/(b-ar_(0))quad\mu_{M}=\frac{c-b r_{0}}{b-a r_{0}} \quad and I M = σ 0 d b a r 0 I M = σ 0 d b a r 0 quadI_(M)=(sigma_(0)sqrtd)/(b-ar_(0))\quad \mathfrak{I}_{M}=\frac{\sigma_{0} \sqrt{d}}{b-a r_{0}}  μ M = c b r 0 b a r 0 μ M = c b r 0 b a r 0 mu_(M)=(c-br_(0))/(b-ar_(0))quad\mu_{M}=\frac{c-b r_{0}}{b-a r_{0}} \quad I M = σ 0 d b a r 0 I M = σ 0 d b a r 0 quadI_(M)=(sigma_(0)sqrtd)/(b-ar_(0))\quad \mathfrak{I}_{M}=\frac{\sigma_{0} \sqrt{d}}{b-a r_{0}}
In [46]: plt.figure(figsize=(60, 30))
在 [46] 中: plt.figure(figsize=(60, 30))

plt.plot(returns.std(), r, “o”, label=“10 Investment Stocks”, markersize=18)
plt.plot(returns.std(), r, "o", label="10 Investment Stocks", markersize=18)

plt.plot(sig_opt, mu_opt, “o”, label=“Optimal Portfolio with only risky asset fo
plt.plot(sig_opt, mu_opt, "o", label="仅有风险资产的最优投资组合")

plt.plot(sig_new, mu_new, “o”, label=“Optimal Portfolio with risk-free asset for
plt.plot(sig_new, mu_new, "o", label="Optimal Portfolio with risk-free asset for

plt.plot(sig, ret, label=“Efficient Frontier”)
plt.plot(sig, ret, label="Efficient Frontier")

plt.plot(sig1, ret1, label=“Inefficient Frontier”, linestyle=”-.”)
plt.plot(sig1, ret1, label="Inefficient Frontier", linestyle="-.")

plt.plot(sigma, r0 + sigma0 * np.sqrt(d) * sigma, label=“Capital Market Line”)
plt.plot(sigma, r0 + sigma0 * np.sqrt(d) * sigma, label="资本市场线")

plt.plot(0, r0, “o”, label=“Risk-free Asset”, markersize=18)
plt.plot(0, r0, "o", label="无风险资产", markersize=18)

plt.plot(sigma_m, mu_m, “*”, label=“Market Portfolio”, markersize=25)
plt.plot(sigma_m, mu_m, "*", label="市场投资组合", markersize=25)

plt.xlabel(r"$\sigma$", fontsize=30)
plt.ylabel(r"$\mu$", fontsize=30)
plt.title("Graph of Risk-free Asset, Market Portfolio, and the Capital Market Li
plt.title("Graph of Risk-free Asset, Market Portfolio, and the Capital Market Li")。

plt.legend(fontsize=30)
plt.show()
This graph visualizes the relationship between risky assets, the market portfolio, the capital market line, and the risk-free asset. Below is a detailed explanation of the elements represented:
该图直观地展示了风险资产、市场投资组合、资本市场线和无风险资产之间的关系。下面是对所代表要素的详细解释:
10 Investment Stocks: The 10 blue dots on the graph represent individual investment stocks, each reflecting an expected rate of return ( μ μ mu\mu ) and the associated risk ( σ σ sigma\sigma ).
10 种投资股票:图中的 10 个蓝点代表单个投资股票,每个蓝点都反映了预期收益率 ( μ μ mu\mu ) 和相关风险 ( σ σ sigma\sigma )。
Risk-Free Asset: The pink dot symbolizes a risk-free asset with no risk ( σ = 0 σ = 0 sigma=0\sigma=0 ) and a return of 0.00015 ( μ = 0.00015 ) 0.00015 ( μ = 0.00015 ) 0.00015(mu=0.00015)0.00015(~ \mu=0.00015). At this point, the portfolio is 100 % 100 % 100%100 \% allocated to the risk-free asset, indicating a completely risk-free investment.
无风险资产:粉色圆点表示无风险资产,无风险( σ = 0 σ = 0 sigma=0\sigma=0 ),回报率为 0.00015 ( μ = 0.00015 ) 0.00015 ( μ = 0.00015 ) 0.00015(mu=0.00015)0.00015(~ \mu=0.00015) 。此时,投资组合的 100 % 100 % 100%100 \% 分配给无风险资产,表明投资完全无风险。
Portfolio (Combining Risky and Risk-Free Assets): The green dot shows a portfolio with both risky and risk-free assets at a specific risk coefficient of t = 0.06 t = 0.06 t=0.06t=0.06. This portfolio yields a return of μ = 0.000894 μ = 0.000894 mu=0.000894\mu=0.000894 and a risk level of σ = 0.006684 σ = 0.006684 sigma=0.006684\sigma=0.006684.
投资组合(风险资产与无风险资产的组合):绿点显示的是一个包含风险资产和无风险资产的投资组合,具体风险系数为 t = 0.06 t = 0.06 t=0.06t=0.06 。该投资组合的收益率为 μ = 0.000894 μ = 0.000894 mu=0.000894\mu=0.000894 ,风险水平为 σ = 0.006684 σ = 0.006684 sigma=0.006684\sigma=0.006684
Risky-Asset-Only Portfolio: The orange dot reflects a portfolio consisting entirely of risky assets, also at t = 0.06 t = 0.06 t=0.06t=0.06. This portfolio offers an expected return of μ = 0.001139 μ = 0.001139 mu=0.001139\mu=0.001139 with a risk level of σ = 0.00958 σ = 0.00958 sigma=0.00958\sigma=0.00958.
纯风险资产投资组合:橙色圆点反映的是一个完全由风险资产组成的投资组合,风险水平也是 t = 0.06 t = 0.06 t=0.06t=0.06 。该投资组合的预期收益为 μ = 0.001139 μ = 0.001139 mu=0.001139\mu=0.001139 ,风险水平为 σ = 0.00958 σ = 0.00958 sigma=0.00958\sigma=0.00958
Capital Market Line and Efficient Frontier: The brown line is the Capital Market Line (CML), which is tangent to the red Efficient Frontier at a key point (marked by a star). This point represents the optimal balance between risk and return under current market conditions.
资本市场线和有效边界:棕色线是资本市场线(CML),它与红色的有效前沿相切于一个关键点(用星号标出)。该点代表当前市场条件下风险与收益之间的最佳平衡。
Market Portfolio: The star symbol indicates the market portfolio, with an expected return of μ = 0.001179 μ = 0.001179 mu=0.001179\mu=0.001179 and risk of σ = 0.014744 σ = 0.014744 sigma=0.014744\sigma=0.014744. At this point, the portfolio consists only of risky assets, with no allocation to the risk-free asset.
市场组合:星号表示市场投资组合,预期收益为 μ = 0.001179 μ = 0.001179 mu=0.001179\mu=0.001179 ,风险为 σ = 0.014744 σ = 0.014744 sigma=0.014744\sigma=0.014744 。此时,投资组合中只有风险资产,没有无风险资产。
Risk-Free Asset: σ = 0 , μ = 0.00015 σ = 0 , μ = 0.00015 quad sigma=0,quad mu=0.00015\quad \sigma=0, \quad \mu=0.00015
无风险资产: σ = 0 , μ = 0.00015 σ = 0 , μ = 0.00015 quad sigma=0,quad mu=0.00015\quad \sigma=0, \quad \mu=0.00015

Portfolio: μ = 0.000894 , σ = 0.006684 μ = 0.000894 , σ = 0.006684 quad mu=0.000894,quad sigma=0.006684\quad \mu=0.000894, \quad \sigma=0.006684 投资组合: μ = 0.000894 , σ = 0.006684 μ = 0.000894 , σ = 0.006684 quad mu=0.000894,quad sigma=0.006684\quad \mu=0.000894, \quad \sigma=0.006684
Risky-Asset-Only Portfolio: μ = 0.001139 , σ = 0.00958 μ = 0.001139 , σ = 0.00958 quad mu=0.001139,quad sigma=0.00958\quad \mu=0.001139, \quad \sigma=0.00958
只有风险资产的投资组合: μ = 0.001139 , σ = 0.00958 μ = 0.001139 , σ = 0.00958 quad mu=0.001139,quad sigma=0.00958\quad \mu=0.001139, \quad \sigma=0.00958

Market Portfolio: μ = 0.001179 , σ = 0.014744 μ = 0.001179 , σ = 0.014744 quad mu=0.001179,quad sigma=0.014744\quad \mu=0.001179, \quad \sigma=0.014744
市场组合: μ = 0.001179 , σ = 0.014744 μ = 0.001179 , σ = 0.014744 quad mu=0.001179,quad sigma=0.014744\quad \mu=0.001179, \quad \sigma=0.014744
In summary, this graph helps investors determine optimal portfolio strategies by balancing risk-free and risky assets or focusing solely on risky investments.
总之,该图表可帮助投资者通过平衡无风险资产和风险资产或只关注风险投资来确定最佳投资组合策略。

Additionally, the relationship between the CML and the Efficient Frontier offers insights into maximizing returns for a given level of risk.
此外,CML 与有效前沿之间的关系还有助于深入了解在一定风险水平下如何实现收益最大化。

Question 6A: 问题 6A:

In [49]: x_M = np.array([0.191, 0.187, 0.116, 0.095, 0.088, 0.075, 0.072, 0.065, 0.06, 0. r _ M = n p . dot ( x _ M , r ) r _ M = n p . dot x _ M , r r_M=np.dot(x_M,r)r \_M=n p . \operatorname{dot}\left(x \_M, r\right)
在 [49] 中: x_M = np.array([0.191, 0.187, 0.116, 0.095, 0.088, 0.075, 0.072, 0.065, 0.06, 0. r _ M = n p . dot ( x _ M , r ) r _ M = n p . dot x _ M , r r_M=np.dot(x_M,r)r \_M=n p . \operatorname{dot}\left(x \_M, r\right) )

sigma_M = np.sqrt(np.matmul(np.matmul(x_M.T, C), x_M))
round(r_M, 6), round(sigma_M, 6)
Out[49]: (0.000791, 0.008488)
In [50]: sigma_m2 = np.dot(x_M, np.dot(C, x_M))
在 [50] 中: sigma_m2 = np.dot(x_M, np.dot(C, x_M))

beta_list = []
for i i ii in range(10):
for i i ii in range(10):

cov = np.dot(C[i], x_M)
beta = cov / sigma_m2
beta_list.append(beta)
print(returns.columns[i], “beta =”, str(beta_list[i]))
print(returns.columns[i], "beta =", str(beta_list[i]))

BHP beta = 1.1459985019086742
必和必拓贝塔 = 1.1459985019086742

CBA beta = 0.9796472387175467 = 0.9796472387175467 =0.9796472387175467=0.9796472387175467 CBA 测试版 = 0.9796472387175467 = 0.9796472387175467 =0.9796472387175467=0.9796472387175467
CSL beta = 0.5693696426669379 = 0.5693696426669379 =0.5693696426669379=0.5693696426669379
NAB beta = 0.9681546358037165
NAB β = 0.9681546358037165

WBC beta = 0.9791614402851987 = 0.9791614402851987 =0.9791614402851987=0.9791614402851987 白细胞 beta = 0.9791614402851987 = 0.9791614402851987 =0.9791614402851987=0.9791614402851987
ANZ beta = 0.9149250075735976 = 0.9149250075735976 =0.9149250075735976=0.9149250075735976 澳新银行测试版 = 0.9149250075735976 = 0.9149250075735976 =0.9149250075735976=0.9149250075735976
MQG beta = 1.1775198801904474
WES beta = 0.9160909238112325
WES β = 0.9160909238112325

GMG beta = 1.1743136105369514
GMG β = 1.1743136105369514

FMG beta = 1.3789596701523026
FMG β = 1.3789596701523026

Beta ( β β beta\beta ) is a measure of the risk associated with a stock or portfolio relative to the broader market:
Beta ( β β beta\beta ) 是衡量股票或投资组合相对于大盘的相关风险的指标:

β = 0 β = 0 beta=0\beta=0 : A beta value of 0 indicates a risk-free asset, meaning its returns are not influenced by market fluctuations. Such assets provide a fixed return, unaffected by market changes.
β = 0 β = 0 beta=0\beta=0 :贝塔值为 0 表示无风险资产,即其收益不受市场波动的影响。这类资产提供固定回报,不受市场变化的影响。

β = 1 β = 1 beta=1\beta=1 : Assets or portfolios with a beta of 1 carry the same level of risk as the market. Their performance aligns with the overall market, known as the “market portfolio,” reflecting average risk and return.
β = 1 β = 1 beta=1\beta=1 :贝塔系数为 1 的资产或投资组合与市场具有相同的风险水平。它们的表现与整体市场一致,被称为 "市场组合",反映了平均风险和回报。

β > 1 β > 1 beta > 1\beta>1 : When the beta value is greater than 1 , the asset’s price fluctuations are more volatile than the market. These assets carry higher risk but may also provide higher expected returns. Companies like BHP, MQG, GMG, and FMG exemplify this behavior.
β > 1 β > 1 beta > 1\beta>1 :当贝塔值大于 1 时,资产的价格波动比市场波动更大。这些资产的风险较高,但也可能提供较高的预期回报。BHP、MQG、GMG 和 FMG 等公司就是这种行为的典型代表。

β < 1 β < 1 beta < 1\beta<1 : Assets or portfolios with a beta below 1 are less volatile than the market, suggesting they offer lower risk. While their expected returns might be lower, they tend to be more stable. For example, CSL has a beta value under 1, demonstrating lower price fluctuations compared to the market.
β < 1 β < 1 beta < 1\beta<1 :贝塔系数低于 1 的资产或投资组合的波动性低于市场,表明它们的风险较低。虽然它们的预期回报可能较低,但往往更加稳定。例如,CSL 的贝塔值低于 1,表明其价格波动低于市场。
Question 6B: 问题 6B:
CSL and MQG display distinct beta values due to the fundamental differences in their business models. CSL, with a beta of 0.569, operates in the pharmaceutical and biotechnology sector, where the demand for healthcare products and services remains relatively stable, regardless of economic conditions. This defensive nature of the industry results in lower market sensitivity and reduced volatility, which is reflected in CSL’s lower beta.
CSL 和 MQG 的贝塔值截然不同,这是因为它们的业务模式存在根本差异。CSL 的贝塔值为 0.569,在制药和生物技术行业开展业务,无论经济状况如何,该行业对医疗保健产品和服务的需求相对稳定。该行业的防御性质导致市场敏感性较低,波动性较小,这也反映在 CSL 较低的贝塔值上。
On the other hand, MQG, with a beta of 1.178, operates within the financial services and investment banking sector. This industry is highly responsive to market cycles, with its performance closely tied to fluctuations in capital markets, investment activities, and economic trends. Consequently, MQG’s business model faces higher volatility and greater sensitivity to market movements, contributing to its higher beta value.
另一方面,MQG 的贝塔系数为 1.178,属于金融服务和投资银行业。该行业对市场周期反应灵敏,其业绩与资本市场、投资活动和经济趋势的波动密切相关。因此,MQG 的业务模式面临较高的波动性,对市场动向更加敏感,从而导致其贝塔值较高。
These beta values align with market expectations: CSL’s lower beta reflects the stability characteristic of defensive industries, while MQG’s higher beta captures the inherent volatility of financial services. This contrast in beta values aligns with financial theory, as it highlights the differing risk profiles across industries and demonstrates how sector-specific factors shape the market behavior of individual companies.
这些贝塔值符合市场预期:CSL 的贝塔值较低,反映了防御性行业的稳定性,而 MQG 的贝塔值较高,反映了金融服务的内在波动性。贝塔值的这种对比符合金融理论,因为它突出了不同行业的不同风险特征,并展示了特定行业的因素是如何影响单个公司的市场行为的。