|
18 | 18 | "metadata": {
|
19 | 19 | "tags": []
|
20 | 20 | },
|
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": [], |
49 | 22 | "source": [
|
50 |
| - "!pip install yfinance\n", |
| 23 | + "# !pip install yfinance\n", |
51 | 24 | "# 需要安装库,下载金融数据"
|
52 | 25 | ]
|
53 | 26 | },
|
|
179 | 152 | " <tbody>\n",
|
180 | 153 | " <tr>\n",
|
181 | 154 | " <th>2020-01-02</th>\n",
|
182 |
| - " <td>73.152641</td>\n", |
| 155 | + " <td>73.152664</td>\n", |
183 | 156 | " <td>3257.850098</td>\n",
|
184 | 157 | " <td>75.087502</td>\n",
|
185 | 158 | " <td>3257.850098</td>\n",
|
|
194 | 167 | " </tr>\n",
|
195 | 168 | " <tr>\n",
|
196 | 169 | " <th>2020-01-03</th>\n",
|
197 |
| - " <td>72.441452</td>\n", |
| 170 | + " <td>72.441460</td>\n", |
198 | 171 | " <td>3234.850098</td>\n",
|
199 | 172 | " <td>74.357498</td>\n",
|
200 | 173 | " <td>3234.850098</td>\n",
|
|
209 | 182 | " </tr>\n",
|
210 | 183 | " <tr>\n",
|
211 | 184 | " <th>2020-01-06</th>\n",
|
212 |
| - " <td>73.018692</td>\n", |
| 185 | + " <td>73.018684</td>\n", |
213 | 186 | " <td>3246.280029</td>\n",
|
214 | 187 | " <td>74.949997</td>\n",
|
215 | 188 | " <td>3246.280029</td>\n",
|
|
239 | 212 | " </tr>\n",
|
240 | 213 | " <tr>\n",
|
241 | 214 | " <th>2020-01-08</th>\n",
|
242 |
| - " <td>73.844345</td>\n", |
| 215 | + " <td>73.844353</td>\n", |
243 | 216 | " <td>3253.050049</td>\n",
|
244 | 217 | " <td>75.797501</td>\n",
|
245 | 218 | " <td>3253.050049</td>\n",
|
|
260 | 233 | " Adj Close Close High \\\n",
|
261 | 234 | " AAPL ^GSPC AAPL ^GSPC AAPL \n",
|
262 | 235 | "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", |
266 | 239 | "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", |
268 | 241 | "\n",
|
269 | 242 | " Low Open \\\n",
|
270 | 243 | " ^GSPC AAPL ^GSPC AAPL ^GSPC \n",
|
|
693 | 666 | },
|
694 | 667 | {
|
695 | 668 | "cell_type": "code",
|
696 |
| - "execution_count": 17, |
| 669 | + "execution_count": 10, |
697 | 670 | "id": "80805657-6e0b-4288-97de-357cb51add66",
|
698 | 671 | "metadata": {},
|
699 | 672 | "outputs": [
|
|
706 | 679 | "Dep. Variable: AAPL R-squared: 0.689\n",
|
707 | 680 | "Model: OLS Adj. R-squared: 0.687\n",
|
708 | 681 | "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", |
711 | 684 | "No. Observations: 251 AIC: -1347.\n",
|
712 | 685 | "Df Residuals: 249 BIC: -1340.\n",
|
713 | 686 | "Df Model: 1 \n",
|
|
719 | 692 | "SP500 1.1234 0.048 23.462 0.000 1.029 1.218\n",
|
720 | 693 | "==============================================================================\n",
|
721 | 694 | "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", |
724 | 697 | "Kurtosis: 7.216 Cond. No. 46.0\n",
|
725 | 698 | "==============================================================================\n",
|
726 | 699 | "\n",
|
|
738 | 711 | "print(results.summary())"
|
739 | 712 | ]
|
740 | 713 | },
|
| 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 | + }, |
741 | 759 | {
|
742 | 760 | "cell_type": "markdown",
|
743 | 761 | "id": "e1a8a7a6-594b-4630-8360-45b529a37f2a",
|
|
0 commit comments