|
21 | 21 | "source": [
|
22 | 22 | "infile = 'data/t_data.csv'\n",
|
23 | 23 | "\n",
|
24 |
| - "df = pd.read_csv(infile, index_col=0, parse_dates=True)" |
| 24 | + "#Data Used In This Example\n", |
| 25 | + "df = pd.read_csv(infile, index_col=0, parse_dates=True)", |
| 26 | + "#Formula Used For Calculation\n", |
| 27 | + "# Get the 26-day EMA of the closing price\n", |
| 28 | + "#k = df['Close'].ewm(span=12, adjust=False, min_periods=12).mean()\n", |
| 29 | + "# Get the 12-day EMA of the closing price\n", |
| 30 | + "#d = df['Close'].ewm(span=26, adjust=False, min_periods=26).mean()\n", |
| 31 | + "# Subtract the 26-day EMA from the 12-Day EMA to get the MACD\n", |
| 32 | + "#macd = k - d\n", |
| 33 | + "# Get the 9-Day EMA of the MACD for the Trigger line\n", |
| 34 | + "#macd_s = macd.ewm(span=9, adjust=False, min_periods=9).mean()\n", |
| 35 | + "# Calculate the difference between the MACD - Trigger for the Convergence/Divergence value\n", |
| 36 | + "#macd_h = macd - macd_s\n", |
| 37 | + "# Add all of our new values for the MACD to the dataframe\n", |
| 38 | + "#df['MACD_12_26_9'] = df.index.map(macd)\n", |
| 39 | + "#df['MACDh_12_26_9'] = df.index.map(macd_h)\n", |
| 40 | + "#df['MACDs_12_26_9'] = df.index.map(macd_s)\n" |
| 41 | + |
25 | 42 | ]
|
26 | 43 | },
|
27 | 44 | {
|
|
0 commit comments