{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Chap 2. Deciphering the Markets with Technical Analysis\n", "\n", "### 1.1 Support and Resistance Line" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "from pandas_datareader import data\n", "\n", "start_date = '2014-01-01'\n", "end_date = '2018-01-01'\n", "SRC_DATA_FILENAME = 'goog_data.pkl'\n", "\n", "try:\n", " goog_data2 = pd.read_pickle(SRC_DATA_FILENAME)\n", "except FileNotFoundError:\n", " goog_data2 = data.DataReader('GOOG', 'yahoo', start_date, end_date)\n", " goog_data2.to_pickle(SRC_DATA_FILENAME)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "把GOOGLE数据下载下来" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": " High Low Open Close Volume \\\nDate \n2015-07-17 674.468018 645.000000 649.000000 672.929993 11164900.0 \n2015-07-20 668.880005 653.010010 659.239990 663.020020 5860900.0 \n2015-07-21 673.000000 654.299988 655.210022 662.299988 3377200.0 \n2015-07-22 678.640015 659.000000 660.890015 662.099976 3929300.0 \n2015-07-23 663.630005 641.000000 661.270020 644.280029 3029100.0 \n... ... ... ... ... ... \n2017-12-22 1064.199951 1059.439941 1061.109985 1060.119995 755100.0 \n2017-12-26 1060.119995 1050.199951 1058.069946 1056.739990 760600.0 \n2017-12-27 1058.369995 1048.050049 1057.390015 1049.369995 1271900.0 \n2017-12-28 1054.750000 1044.770020 1051.599976 1048.140015 837100.0 \n2017-12-29 1049.699951 1044.900024 1046.719971 1046.400024 887500.0 \n\n Adj Close \nDate \n2015-07-17 672.929993 \n2015-07-20 663.020020 \n2015-07-21 662.299988 \n2015-07-22 662.099976 \n2015-07-23 644.280029 \n... ... \n2017-12-22 1060.119995 \n2017-12-26 1056.739990 \n2017-12-27 1049.369995 \n2017-12-28 1048.140015 \n2017-12-29 1046.400024 \n\n[620 rows x 6 columns]", "text/html": "
\n | High | \nLow | \nOpen | \nClose | \nVolume | \nAdj Close | \n
---|---|---|---|---|---|---|
Date | \n\n | \n | \n | \n | \n | \n |
2015-07-17 | \n674.468018 | \n645.000000 | \n649.000000 | \n672.929993 | \n11164900.0 | \n672.929993 | \n
2015-07-20 | \n668.880005 | \n653.010010 | \n659.239990 | \n663.020020 | \n5860900.0 | \n663.020020 | \n
2015-07-21 | \n673.000000 | \n654.299988 | \n655.210022 | \n662.299988 | \n3377200.0 | \n662.299988 | \n
2015-07-22 | \n678.640015 | \n659.000000 | \n660.890015 | \n662.099976 | \n3929300.0 | \n662.099976 | \n
2015-07-23 | \n663.630005 | \n641.000000 | \n661.270020 | \n644.280029 | \n3029100.0 | \n644.280029 | \n
... | \n... | \n... | \n... | \n... | \n... | \n... | \n
2017-12-22 | \n1064.199951 | \n1059.439941 | \n1061.109985 | \n1060.119995 | \n755100.0 | \n1060.119995 | \n
2017-12-26 | \n1060.119995 | \n1050.199951 | \n1058.069946 | \n1056.739990 | \n760600.0 | \n1056.739990 | \n
2017-12-27 | \n1058.369995 | \n1048.050049 | \n1057.390015 | \n1049.369995 | \n1271900.0 | \n1049.369995 | \n
2017-12-28 | \n1054.750000 | \n1044.770020 | \n1051.599976 | \n1048.140015 | \n837100.0 | \n1048.140015 | \n
2017-12-29 | \n1049.699951 | \n1044.900024 | \n1046.719971 | \n1046.400024 | \n887500.0 | \n1046.400024 | \n
620 rows × 6 columns
\n\n | price | \nsup_tolerance | \nres_tolerance | \nsup_count | \nres_count | \nsup | \nres | \nposition | \nsignal | \n
---|---|---|---|---|---|---|---|---|---|
Date | \n\n | \n | \n | \n | \n | \n | \n | \n | \n |
2013-12-31 | \n558.262512 | \nNaN | \nNaN | \nNaN | \nNaN | \nNaN | \nNaN | \nNaN | \nNaN | \n
2014-01-02 | \n554.481689 | \nNaN | \nNaN | \nNaN | \nNaN | \nNaN | \nNaN | \nNaN | \nNaN | \n
2014-01-03 | \n550.436829 | \nNaN | \nNaN | \nNaN | \nNaN | \nNaN | \nNaN | \nNaN | \nNaN | \n
2014-01-06 | \n556.573853 | \nNaN | \nNaN | \nNaN | \nNaN | \nNaN | \nNaN | \nNaN | \nNaN | \n
2014-01-07 | \n567.303589 | \nNaN | \nNaN | \nNaN | \nNaN | \nNaN | \nNaN | \nNaN | \nNaN | \n
... | \n... | \n... | \n... | \n... | \n... | \n... | \n... | \n... | \n... | \n
2017-12-22 | \n1060.119995 | \n1014.371997 | \n1061.44801 | \nNaN | \nNaN | \n998.679993 | \n1077.140015 | \n0.0 | \n1.0 | \n
2017-12-26 | \n1056.739990 | \n1014.371997 | \n1061.44801 | \nNaN | \nNaN | \n998.679993 | \n1077.140015 | \n0.0 | \n1.0 | \n
2017-12-27 | \n1049.369995 | \n1014.371997 | \n1061.44801 | \nNaN | \nNaN | \n998.679993 | \n1077.140015 | \n0.0 | \n1.0 | \n
2017-12-28 | \n1048.140015 | \n1014.371997 | \n1061.44801 | \nNaN | \nNaN | \n998.679993 | \n1077.140015 | \n0.0 | \n1.0 | \n
2017-12-29 | \n1046.400024 | \n1014.371997 | \n1061.44801 | \nNaN | \nNaN | \n998.679993 | \n1077.140015 | \n0.0 | \n1.0 | \n
1008 rows × 9 columns
\n\n | price | \nsup_tolerance | \nres_tolerance | \nsup_count | \nres_count | \nsup | \nres | \nposition | \nsignal | \n
---|---|---|---|---|---|---|---|---|---|
Date | \n\n | \n | \n | \n | \n | \n | \n | \n | \n |
2013-12-31 | \n558.262512 | \nNaN | \nNaN | \nNaN | \nNaN | \nNaN | \nNaN | \nNaN | \nNaN | \n
2014-01-02 | \n554.481689 | \nNaN | \nNaN | \nNaN | \nNaN | \nNaN | \nNaN | \nNaN | \nNaN | \n
2014-01-03 | \n550.436829 | \nNaN | \nNaN | \nNaN | \nNaN | \nNaN | \nNaN | \nNaN | \nNaN | \n
2014-01-06 | \n556.573853 | \nNaN | \nNaN | \nNaN | \nNaN | \nNaN | \nNaN | \nNaN | \nNaN | \n
2014-01-07 | \n567.303589 | \nNaN | \nNaN | \nNaN | \nNaN | \nNaN | \nNaN | \nNaN | \nNaN | \n
... | \n... | \n... | \n... | \n... | \n... | \n... | \n... | \n... | \n... | \n
2017-12-22 | \n1060.119995 | \n1014.371997 | \n1061.44801 | \nNaN | \nNaN | \n998.679993 | \n1077.140015 | \n0.0 | \n1.0 | \n
2017-12-26 | \n1056.739990 | \n1014.371997 | \n1061.44801 | \nNaN | \nNaN | \n998.679993 | \n1077.140015 | \n0.0 | \n1.0 | \n
2017-12-27 | \n1049.369995 | \n1014.371997 | \n1061.44801 | \nNaN | \nNaN | \n998.679993 | \n1077.140015 | \n0.0 | \n1.0 | \n
2017-12-28 | \n1048.140015 | \n1014.371997 | \n1061.44801 | \nNaN | \nNaN | \n998.679993 | \n1077.140015 | \n0.0 | \n1.0 | \n
2017-12-29 | \n1046.400024 | \n1014.371997 | \n1061.44801 | \nNaN | \nNaN | \n998.679993 | \n1077.140015 | \n0.0 | \n1.0 | \n
1008 rows × 9 columns
\n