From be3a837b38ec669bd071b8a00fa56210d31bd04a Mon Sep 17 00:00:00 2001 From: Pankaj Kumar Goyal <140732455+Pankaj4152@users.noreply.github.com> Date: Tue, 8 Oct 2024 00:46:59 +0530 Subject: [PATCH] indicator graph improved --- .../Stock_Price_Prediction_REMOTE_20502.ipynb | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/Python File/Stock_Price_Prediction_REMOTE_20502.ipynb b/Python File/Stock_Price_Prediction_REMOTE_20502.ipynb index c08a8c8..60d2fc6 100644 --- a/Python File/Stock_Price_Prediction_REMOTE_20502.ipynb +++ b/Python File/Stock_Price_Prediction_REMOTE_20502.ipynb @@ -324,10 +324,10 @@ ], "source": [ "fig, ax1 = plt.subplots(figsize=(10, 6))\n", - "\n", - "ax1.plot(df[\"SMA_10\"], label = \"SMA_10\", color='Red', linewidth=1, alpha=0.8)\n", - "ax1.plot(df[\"SMA_50\"], label = \"SMA_50\", color='Green', linewidth=1, alpha=0.8)\n", - "ax1.plot(df[\"Close\"], label = \"Close\", color='Blue', linewidth=2)\n", + "days = int(input(\"of how many past days you want to see graph: \"))\n", + "ax1.plot(df[\"SMA_10\"][-days:], label = \"SMA_10\", color='Red', linewidth=1, alpha=0.8)\n", + "ax1.plot(df[\"SMA_50\"][-days:], label = \"SMA_50\", color='Green', linewidth=1, alpha=0.8)\n", + "ax1.plot(df[\"Close\"][-days:], label = \"Close\", color='Blue', linewidth=2)\n", "\n", "plt.legend()\n", "plt.show()" @@ -397,14 +397,15 @@ "# Create subplots\n", "fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(10, 8), gridspec_kw={'height_ratios': [3, 1]})\n", "\n", + "days = int(input(\"of how many past days you want to see graph: \"))\n", "# price graph\n", - "ax1.plot(df['Close'], label='Close Price', color='blue')\n", + "ax1.plot(df['Close'][-days:], label='Close Price', color='blue')\n", "ax1.set_title('Stock Price')\n", "ax1.set_ylabel('Price')\n", "ax1.legend()\n", "\n", "# rsi graph\n", - "ax2.plot(df['RSI'], label='RSI', color='orange')\n", + "ax2.plot(df['RSI'][-days:], label='RSI', color='orange')\n", "ax2.axhline(70, color='red', linestyle='--') # Overbought line\n", "ax2.axhline(30, color='green', linestyle='--') # Oversold line\n", "ax2.set_title('Relative Strength Index (RSI)')\n", @@ -725,14 +726,15 @@ "fig, ax = plt.subplots(2, 1, figsize=(10, 8))\n", "\n", "\n", + "days = int(input(\"of how many past days you want to see graph: \"))\n", "# Plot stock price on first subplot (bold)\n", - "ax[0].plot( df['Close'], label='Close Price', color='blue', linewidth=3)\n", + "ax[0].plot( df['Close'][-days:], label='Close Price', color='blue', linewidth=3)\n", "ax[0].set_title('Stock Price')\n", "ax[0].set_ylabel('Price')\n", "\n", "# Plot MACD and Signal line on second subplot\n", - "ax[1].plot( df['MACD'], label='MACD', color='green', linewidth=2)\n", - "ax[1].plot( df['Signal_Line'], label='Signal Line', color='red', linestyle='--', alpha=0.7)\n", + "ax[1].plot( df['MACD'][-days:], label='MACD', color='green', linewidth=2)\n", + "ax[1].plot( df['Signal_Line'][-days:], label='Signal Line', color='red', linestyle='--', alpha=0.7)\n", "ax[1].set_title('MACD')\n", "ax[1].set_ylabel('MACD Value')\n", "\n",