Skip to content

Commit ad6da15

Browse files
authored
Add files via upload
1 parent 5872c05 commit ad6da15

File tree

32 files changed

+2777
-669
lines changed

32 files changed

+2777
-669
lines changed

Book7_Ch02_Python_Codes/Bk7_Ch02_01.ipynb

+60-42
Original file line numberDiff line numberDiff line change
@@ -18,36 +18,9 @@
1818
"metadata": {
1919
"tags": []
2020
},
21-
"outputs": [
22-
{
23-
"name": "stdout",
24-
"output_type": "stream",
25-
"text": [
26-
"Requirement already satisfied: yfinance in c:\\users\\james\\anaconda3\\lib\\site-packages (0.2.31)\n",
27-
"Requirement already satisfied: pandas>=1.3.0 in c:\\users\\james\\anaconda3\\lib\\site-packages (from yfinance) (1.5.3)\n",
28-
"Requirement already satisfied: frozendict>=2.3.4 in c:\\users\\james\\anaconda3\\lib\\site-packages (from yfinance) (2.3.8)\n",
29-
"Requirement already satisfied: peewee>=3.16.2 in c:\\users\\james\\anaconda3\\lib\\site-packages (from yfinance) (3.17.0)\n",
30-
"Requirement already satisfied: html5lib>=1.1 in c:\\users\\james\\anaconda3\\lib\\site-packages (from yfinance) (1.1)\n",
31-
"Requirement already satisfied: numpy>=1.16.5 in c:\\users\\james\\anaconda3\\lib\\site-packages (from yfinance) (1.23.5)\n",
32-
"Requirement already satisfied: multitasking>=0.0.7 in c:\\users\\james\\anaconda3\\lib\\site-packages (from yfinance) (0.0.11)\n",
33-
"Requirement already satisfied: beautifulsoup4>=4.11.1 in c:\\users\\james\\anaconda3\\lib\\site-packages (from yfinance) (4.11.1)\n",
34-
"Requirement already satisfied: lxml>=4.9.1 in c:\\users\\james\\anaconda3\\lib\\site-packages (from yfinance) (4.9.1)\n",
35-
"Requirement already satisfied: pytz>=2022.5 in c:\\users\\james\\anaconda3\\lib\\site-packages (from yfinance) (2022.7)\n",
36-
"Requirement already satisfied: appdirs>=1.4.4 in c:\\users\\james\\anaconda3\\lib\\site-packages (from yfinance) (1.4.4)\n",
37-
"Requirement already satisfied: requests>=2.31 in c:\\users\\james\\anaconda3\\lib\\site-packages (from yfinance) (2.31.0)\n",
38-
"Requirement already satisfied: soupsieve>1.2 in c:\\users\\james\\anaconda3\\lib\\site-packages (from beautifulsoup4>=4.11.1->yfinance) (2.3.2.post1)\n",
39-
"Requirement already satisfied: six>=1.9 in c:\\users\\james\\anaconda3\\lib\\site-packages (from html5lib>=1.1->yfinance) (1.16.0)\n",
40-
"Requirement already satisfied: webencodings in c:\\users\\james\\anaconda3\\lib\\site-packages (from html5lib>=1.1->yfinance) (0.5.1)\n",
41-
"Requirement already satisfied: python-dateutil>=2.8.1 in c:\\users\\james\\anaconda3\\lib\\site-packages (from pandas>=1.3.0->yfinance) (2.8.2)\n",
42-
"Requirement already satisfied: idna<4,>=2.5 in c:\\users\\james\\anaconda3\\lib\\site-packages (from requests>=2.31->yfinance) (3.4)\n",
43-
"Requirement already satisfied: certifi>=2017.4.17 in c:\\users\\james\\anaconda3\\lib\\site-packages (from requests>=2.31->yfinance) (2023.5.7)\n",
44-
"Requirement already satisfied: charset-normalizer<4,>=2 in c:\\users\\james\\anaconda3\\lib\\site-packages (from requests>=2.31->yfinance) (2.0.4)\n",
45-
"Requirement already satisfied: urllib3<3,>=1.21.1 in c:\\users\\james\\anaconda3\\lib\\site-packages (from requests>=2.31->yfinance) (1.26.14)\n"
46-
]
47-
}
48-
],
21+
"outputs": [],
4922
"source": [
50-
"!pip install yfinance\n",
23+
"# !pip install yfinance\n",
5124
"# 需要安装库,下载金融数据"
5225
]
5326
},
@@ -179,7 +152,7 @@
179152
" <tbody>\n",
180153
" <tr>\n",
181154
" <th>2020-01-02</th>\n",
182-
" <td>73.152641</td>\n",
155+
" <td>73.152664</td>\n",
183156
" <td>3257.850098</td>\n",
184157
" <td>75.087502</td>\n",
185158
" <td>3257.850098</td>\n",
@@ -194,7 +167,7 @@
194167
" </tr>\n",
195168
" <tr>\n",
196169
" <th>2020-01-03</th>\n",
197-
" <td>72.441452</td>\n",
170+
" <td>72.441460</td>\n",
198171
" <td>3234.850098</td>\n",
199172
" <td>74.357498</td>\n",
200173
" <td>3234.850098</td>\n",
@@ -209,7 +182,7 @@
209182
" </tr>\n",
210183
" <tr>\n",
211184
" <th>2020-01-06</th>\n",
212-
" <td>73.018692</td>\n",
185+
" <td>73.018684</td>\n",
213186
" <td>3246.280029</td>\n",
214187
" <td>74.949997</td>\n",
215188
" <td>3246.280029</td>\n",
@@ -239,7 +212,7 @@
239212
" </tr>\n",
240213
" <tr>\n",
241214
" <th>2020-01-08</th>\n",
242-
" <td>73.844345</td>\n",
215+
" <td>73.844353</td>\n",
243216
" <td>3253.050049</td>\n",
244217
" <td>75.797501</td>\n",
245218
" <td>3253.050049</td>\n",
@@ -260,11 +233,11 @@
260233
" Adj Close Close High \\\n",
261234
" AAPL ^GSPC AAPL ^GSPC AAPL \n",
262235
"Date \n",
263-
"2020-01-02 73.152641 3257.850098 75.087502 3257.850098 75.150002 \n",
264-
"2020-01-03 72.441452 3234.850098 74.357498 3234.850098 75.144997 \n",
265-
"2020-01-06 73.018692 3246.280029 74.949997 3246.280029 74.989998 \n",
236+
"2020-01-02 73.152664 3257.850098 75.087502 3257.850098 75.150002 \n",
237+
"2020-01-03 72.441460 3234.850098 74.357498 3234.850098 75.144997 \n",
238+
"2020-01-06 73.018684 3246.280029 74.949997 3246.280029 74.989998 \n",
266239
"2020-01-07 72.675262 3237.179932 74.597504 3237.179932 75.224998 \n",
267-
"2020-01-08 73.844345 3253.050049 75.797501 3253.050049 76.110001 \n",
240+
"2020-01-08 73.844353 3253.050049 75.797501 3253.050049 76.110001 \n",
268241
"\n",
269242
" Low Open \\\n",
270243
" ^GSPC AAPL ^GSPC AAPL ^GSPC \n",
@@ -693,7 +666,7 @@
693666
},
694667
{
695668
"cell_type": "code",
696-
"execution_count": 17,
669+
"execution_count": 10,
697670
"id": "80805657-6e0b-4288-97de-357cb51add66",
698671
"metadata": {},
699672
"outputs": [
@@ -706,8 +679,8 @@
706679
"Dep. Variable: AAPL R-squared: 0.689\n",
707680
"Model: OLS Adj. R-squared: 0.687\n",
708681
"Method: Least Squares F-statistic: 550.5\n",
709-
"Date: Thu, 16 Nov 2023 Prob (F-statistic): 5.16e-65\n",
710-
"Time: 16:38:00 Log-Likelihood: 675.37\n",
682+
"Date: Thu, 23 Nov 2023 Prob (F-statistic): 5.16e-65\n",
683+
"Time: 11:09:43 Log-Likelihood: 675.37\n",
711684
"No. Observations: 251 AIC: -1347.\n",
712685
"Df Residuals: 249 BIC: -1340.\n",
713686
"Df Model: 1 \n",
@@ -719,8 +692,8 @@
719692
"SP500 1.1234 0.048 23.462 0.000 1.029 1.218\n",
720693
"==============================================================================\n",
721694
"Omnibus: 52.109 Durbin-Watson: 1.871\n",
722-
"Prob(Omnibus): 0.000 Jarque-Bera (JB): 210.795\n",
723-
"Skew: 0.772 Prob(JB): 1.68e-46\n",
695+
"Prob(Omnibus): 0.000 Jarque-Bera (JB): 210.791\n",
696+
"Skew: 0.772 Prob(JB): 1.69e-46\n",
724697
"Kurtosis: 7.216 Cond. No. 46.0\n",
725698
"==============================================================================\n",
726699
"\n",
@@ -738,6 +711,51 @@
738711
"print(results.summary())"
739712
]
740713
},
714+
{
715+
"cell_type": "code",
716+
"execution_count": 11,
717+
"id": "bdf197d2-9683-4698-b63e-0478abf04b87",
718+
"metadata": {},
719+
"outputs": [
720+
{
721+
"name": "stdout",
722+
"output_type": "stream",
723+
"text": [
724+
" OLS Regression Results \n",
725+
"=======================================================================================\n",
726+
"Dep. Variable: AAPL R-squared (uncentered): 0.687\n",
727+
"Model: OLS Adj. R-squared (uncentered): 0.686\n",
728+
"Method: Least Squares F-statistic: 549.2\n",
729+
"Date: Thu, 23 Nov 2023 Prob (F-statistic): 4.97e-65\n",
730+
"Time: 11:10:26 Log-Likelihood: 673.71\n",
731+
"No. Observations: 251 AIC: -1345.\n",
732+
"Df Residuals: 250 BIC: -1342.\n",
733+
"Df Model: 1 \n",
734+
"Covariance Type: nonrobust \n",
735+
"==============================================================================\n",
736+
" coef std err t P>|t| [0.025 0.975]\n",
737+
"------------------------------------------------------------------------------\n",
738+
"SP500 1.1265 0.048 23.434 0.000 1.032 1.221\n",
739+
"==============================================================================\n",
740+
"Omnibus: 52.047 Durbin-Watson: 1.846\n",
741+
"Prob(Omnibus): 0.000 Jarque-Bera (JB): 210.241\n",
742+
"Skew: 0.771 Prob(JB): 2.22e-46\n",
743+
"Kurtosis: 7.210 Cond. No. 1.00\n",
744+
"==============================================================================\n",
745+
"\n",
746+
"Notes:\n",
747+
"[1] R² is computed without centering (uncentered) since the model does not contain a constant.\n",
748+
"[2] Standard Errors assume that the covariance matrix of the errors is correctly specified.\n"
749+
]
750+
}
751+
],
752+
"source": [
753+
"# 无截距一元线性回归\n",
754+
"model_no_intercept = sm.OLS(y_df, x_df)\n",
755+
"results_no_intercept = model_no_intercept.fit()\n",
756+
"print(results_no_intercept.summary())"
757+
]
758+
},
741759
{
742760
"cell_type": "markdown",
743761
"id": "e1a8a7a6-594b-4630-8360-45b529a37f2a",

0 commit comments

Comments
 (0)