Moving Average charts for ONGC Stock
收藏NIAID Data Ecosystem2026-05-01 收录
下载链接:
https://data.mendeley.com/datasets/mh7h4thwp9
下载链接
链接失效反馈官方服务:
资源简介:
The provided code performs analysis and visualization of daily returns and moving averages for the historical stock price data of Oil and Natural Gas Corporation (ONGC) from a CSV file. The analysis is conducted using the pandas library for data manipulation, numpy for numerical computations, and matplotlib.pyplot for generating plots.
Loading Data:
The code imports the pandas library as pd, numpy as np, and matplotlib.pyplot as plt.
It specifies the file path of the CSV file containing ONGC stock price data.
The data is loaded into a DataFrame named df using the read_csv() function from pandas.
Extracting Required Columns:
The code extracts the required columns from the DataFrame, including 'Open', 'High', 'Low', 'Close', and 'Adj Close' prices, and assigns them to separate variables.
Calculating Daily Returns:
Daily returns are calculated for each price metric ('Open', 'High', 'Low', 'Close', 'Adj Close') using the pct_change() function, which computes the percentage change between consecutive values.
Calculating Moving Averages:
Moving averages are computed for each daily return series using the rolling() function with a specified window size.
The window size for the moving averages is set to 20 days.
Plotting Daily Returns and Moving Averages:
Subplots are created for each price metric ('Open', 'High', 'Low', 'Close', 'Adj Close') along with their corresponding moving averages.
Each subplot displays the daily returns and the moving average curve.
Titles and legends are added to each subplot for clarity.
Displaying Plots:
The plt.tight_layout() function adjusts the spacing between subplots to prevent overlapping.
Finally, the plt.show() function is called to display the plots.
Overall, the code provides a comprehensive analysis of daily returns and moving averages for ONGC stock prices, allowing for insights into the trend and volatility of the stock over time.
创建时间:
2024-04-23



