Frontiers in Business, Economics and Management ISSN: 2766-824X | Vol. 15, No. 3, 2024 427 Analysis of Apple Stock - Based on R Junjie Yu, Wenjia Sang, Yiqian Tang Anhui University of Finance and Economics, Bengbu, China Abstract: With the continuous development of China's economy, the stock market is becoming increasingly mature, and stocks play a crucial role in the economic life. The development and changes in stocks can measure the economic development of enterprises. Meanwhile, stock investment has become a means for people to obtain economic benefits. The development of stocks is closely related to economic development. The fluctuation of stock prices can reflect the implementation of national economic policies and also comprehensively reflect the living conditions of residents. With the continuous improvement of the stock market, accurately analyzing the trend of stock prices has become an important research topic. Accurate analysis of stock price changes is of great significance for the regulation of macroeconomic policies and making optimal choices for investors. The fluctuation of stock prices is a complex nonlinear dynamic process, and traditional linear models cannot accurately describe and analyze its development and changes. Time series models can effectively fit curve data, so they are of great importance in the analysis and description of stock price changes. In this study, we collected all trading days' stock data of Apple Inc. from January 1, 20 21, to June 29, 2021, and used a time series model to analyze the changes in stock prices. In this paper, we first conducted a simple descriptive statistical analysis of the changes in Apple's stock prices and found that the price fluctuations of Apple's stock did not revolve around a specific value. Secondly, through the observation and preprocessing of stock prices, it was found that the sequence was non-stationary. This paper used the first-order difference method to achieve stationarity and fitted the data using the ARIMA model. For different parameters of the ARIMA model, the optimal model was determined based on the AIC criterion and the modified AIC coefficient. Furthermore, the abnormal values of the stock prices were processed, enabling effective prediction of the future trend of Apple's stock prices. Through research analysis, the conclusion drawn in this pape r is that the price of Apple's stock is not only influenced by random factors but also significantly affected by the lagged 5-period stock prices. Overall, the trend of Apple's stock price changes is relatively stable. Keywords: Time series, ARIMA model, Stock prices, Outlier detection, Prediction. 1. Research Background and Significance (1) Overview of Stock Development Stocks are certificates issued by joint-stock companies to raise funds from investors. By purchasing the stocks of a company, investors can share in the profits generated by the company's development, but they also need to bear various risks that the company may encounter during its growth. The emergence of joint-stock companies is partly due to the continuous accumulation of capital by producers themselves and partly due to the limitations imposed by finite loan capital on enterprise expansion towards socialized large-scale production. Joint-stock companies arose from the combined influence of multiple factors. Overseas trading companies established by the Netherlands and England in the early 17th century are considered the earliest joint-stock companies [1]. The Dutch East India Company, established in 1602, is often regarded by experts and researchers studying joint-stock companies as the precursor of modern limited liability companies. Although joint-stock companies emerged relatively late, their development has been rapid. From the late 17th century to the early 19th century, joint-stock companies experienced significant growth in industries such as transportation and finance. Around the 1850s, most Western countries completed their industrial revolutions. The completion of the industrial revolution led to the rapid rise of manufacturing industries, which required financial support for their growth and expansion. This prompted many manufacturing companies to transition into joint-stock companies. Since then, joint-stock companies have become an important form of enterprise development, and stock-based economies have become a key feature of economic development. In the 1870s, the concept of joint-stock companies began to spread to China. China's first stock was issued by the China Merchants Steam Navigation Company, which was established in 1873. With the continuous development of China's economy, particularly since the reform and opening-up policy, the pace of economic growth has been remarkable. The development environment of China's stock market has also improved, making it an increasingly significant component of the financial system. The stock market plays an ever-important role in driving economic reforms and serves as a crucial conduit for monetary policy transmission. Moreover, the development of the stock market influences residents' investment, savings, and consumption behaviors. Due to its low entry barriers and operational convenience, stock investment has become increasingly popular, growing into a common method of investment and financial management. (2) Research Background of Apple Inc. Apple Inc. is a multinational technology company headquartered in California, USA, founded in 1976. The company primarily manufactures and sells consumer electronics, computer hardware and software, and provides digital distribution services. Apple's well-known products include the iPhone, iPad, Mac computers, Apple Watch, and more. In the context of stock research, investors typically focus on several aspects of Apple Inc.'s performance: Financial Status: This includes analyzing the company’s revenue, profits, cash flow, and balance sheet data to assess its profitability and financial stability. 428 Product Innovation and Market Performance: Attention is paid to the company’s ability to innovate, its market share, sales growth, and performance in different regions. Leadership Team and Strategy: Investors look at the company’s management team, leadership capabilities, and strategic planning and execution. Competitors and Industry Trends: Understanding the competitive landscape and trends within the industry helps gauge the company's position and future prospects. Legal and Policy Risks: Given Apple’s global business operations, investors need to consider the legal, policy, and geopolitical risks in the markets where the company operates. These factors are critical for investors when researching Apple Inc.'s stock. Investment decisions should be based on comprehensive considerations of various factors, and investors should be aware of the inherent risks. As a major player in the electronics industry, Apple Inc. consistently draws significant attention. Stocks, being a means to benefit the company, naturally attract interest. Predicting Apple Inc.'s stock performance has long been a hot topic among investors. In joint-stock enterprises, stocks represent the embodiment of investors' ownership in the company [2]. (3) Significance of Stock Research: Integral Part of Financial Markets: The stock market is a crucial component of the financial markets. With globalization and the advancement of internet technologies, the scale and influence of the stock market have grown, becoming a vital indicator of national economic development [3]. Protection of Investor Interests: Research on stocks helps investors understand market trends and patterns, evaluate the operational status and risk of joint-stock companies, thus reducing investment risks and protecting investor interests [4]. Reference for Corporate Decision-Making: Stock research provides companies with information on market demand, industry development trends, and more, aiding corporate decision-makers in formulating correct strategies, enhancing market competitiveness, and development potential [5]. 2. Data Source Data Source: The data is selected from Apple Inc.'s stock data for all trading days from January 1, 2021, to June 29, 2021. The data was scraped from Yahoo Finance using R. The code is as follows [6]: > stockData<- new.env() > startDate = as.Date("2010-06") > endDate = as.Date("2021-06") > tickers <- c("AAPL") > getSymbols(tickers,env = stockData,src = "yahoo",from= startDate,to = endDate) [1] "AAPL" > options(max.print = 10000) > print(stockData$AAPL) 3. Descriptive Statistical Analysis Load the obtained data into Excel, and use R to output various statistical values of Apple Inc.'s stock prices over a certain period, such as mean, variance, and so on. The code and the displayed results are as follows: > library(readxl) > APPL<- read_excel("C:/Users/junjie/OneDrive/desktop/APPL.xlsx") > describe(AAPL) vars n mean sd median trimmed Date 1 133 NaN NA NA NaN Open 2 133 3.951000e+01 3.162000e+01 2.818000e+01 3.29200e+01 High 3 133 4.239000e+01 3.433000e+01 2.994000e+01 3.52000e+01 Low 4 133 3.729000e+01 2.982000e+01 2.683000e+01 3.10500e+01 Close 5 133 4.024000e+01 3.228000e+01 2.839000e+01 3.35400e+01 Adj Close 6 133 3.850000e+01 3.284000e+01 2.660000e+01 3.16100e+01 Volume 7 133 5.415859e+09 3.717854e+09 3.816608e+09 4.90708e+09 mad min max range skew kurtosis Date NA Inf -Inf - Inf NA NA Open 1.838000e+01 8.84 1.34800e+02 1.259600e+02 1.75 2.29 High 1.972000e+01 9.44 1.45090e+02 1.356500e+02 1.71 2.04 Low 1.674000e+01 8.41 1.34360e+02 1.259500e+02 1.76 2.33 Close 1.864000e+01 8.68 1.36330e+02 1.276500e+02 1.70 2.03 Adj Close 1.897000e+01 7.47 1.36330e+02 1.288600e+02 1.70 2.00 Volume 2.408502e+09 64556081.00 1.61426e+10 1.607804e+10 1.07 0.18 se Date NA Open 2.74 High 2.98 Low 2.59 Close 2.80 Adj Close 2.85 Volume 322378867.96 4. Inferential Statistical Analysis 4.1. Sampling Distribution of Sample Statistics (1) Sampling Distribution of the Sample Arithmetic Mean - Large Sample: Standard Deviation of the Sample Mean (Estimated Standard Error): SE n  = , at this point, 2 ( , )x N n   "If σ is unknown, then it is:" S SE n = , at this point, 2 ( , ) S x N n  Note: Small Sample: That is, t-distribution with n-1 degrees of freedom. (2) Sampling Distribution of Sample Variance The sampling distribution of the sample variance follows a chi-square distribution. 2 2 2 ( 1) ( 1) n S n  − − = 429 4.2. Confidence Interval for the Mean of a Large Sample Figure 1. Confidence interval ( 1.96 1.96 ) 0.95 S S P x n n  −   + = From the descriptive statistical analysis, it is known that the standard deviation (SE) of Apple's stock closing price data is 2.8. Sampling margin of error: 488.58.296.1 === SEZ x  Confidence interval: 488.524.40 == xx That is: ( ) 95.0728.45752.34 = P 5. Construction and Empirical Analysis of Statistical Models The general modeling process is shown in the following flowchart: Figure 2. Candlestick chart of Apple Inc.'s stock prices Figure 3. Time series plot of Apple Inc.'s stock closing prices Figure 4. Autocorrelation coefficient plot of Apple Inc.'s stock closing prices Figure 5. Partial autocorrelation coefficient plot of Apple Inc.'s stock closing prices > adf.test(Close) Augmented Dickey-Fuller Test data: Close Dickey-Fuller = 0.43519, Lag order = 5, p-value = 0.99 Test for pure randomness > for(k in 1:2) print(Box.test(Close,lag=6*k) + ) Box-Pierce test data: Close X-squared = 572.11, df = 6, p-value < 2.2e-16 Box-Pierce test data: Close X-squared = 840.07, df = 12, p-value < 2.2e-16 The time series plot shows a clear trend, indicating that the series has significant non-stationary characteristics. The results of the ADF test show that the P-value is greater than the significance level, so the series is non-stationary. According to the results of the pure randomness test, the P- values of the 6th and 12th order lag LB statistics are both less than the significance level, thus the series is determined to be -9.92028 -7.98815 -6.05603 -4.12390 -2.19177 -0.25965 1.67248 3.60460 5.53673 7.46885 9.400981 0.0 0.1 0.2 0.3 120 125 130 135 140 145 stockData$AAPL [2021-01-04/2021-06-28] Last 134.779999 Volume (millions): 62,111,300 60 80 100 120 140 160 180 1月 04 2021 1月 25 2021 2月 16 2021 3月 08 2021 3月 29 2021 4月 19 2021 5月 10 2021 6月 01 2021 6月 21 2021 430 non-stationary and non-white noise. Taking the first difference of the series: Figure 6. First Difference Time Series Plot > adf.test(dif_Close) Augmented Dickey-Fuller Test data: dif_Close Dickey-Fuller = -4.9472, Lag order = 5, p-value = 0.01 alternative hypothesis: stationary The ADF test shows that the P-value is less than the significance level, indicating that the series is stationary after the first difference. Using the auto.arima function for automatic fitting, the code is as follows: > library(forecast) > auto.arima(Close) Series: Close ARIMA(2,2,1) Coefficients: ar1 ar2 ma1 0.1327 -0.2862 -0.9459 s.e. 0.0863 0.0861 0.0324 sigma^2 estimated as 18.67: log likelihood=-377.42 AIC=762.84 AICc=763.16 BIC=774.34 The fitted model obtained is: ( ) ( ) tt BxBB 9459.012862.01327.0-1 22 +=+ 6. Summary and Conclusion of the Empirical Analysis Stocks are a crucial component of financial markets. As the Chinese stock market continues to develop, it is gradually maturing. The issuance and trading of stocks, in turn, promote and drive faster and better national economic development. On one hand, stocks have become a label to measure the development status of enterprises, and on the other hand, they serve as a method for people to invest and manage their finances. Therefore, research on stocks is a topic of great interest and concern for both investors and corporate managers. Investors hope to predict stock prices to achieve higher returns, while managers aim to make informed decisions through accurate stock price predictions to facilitate better growth. However, accurately predicting stock prices is challenging due to the influence of numerous factors such as macroeconomic policies, local economic policies, and industry development conditions. By utilizing the ARIMA model and conducting analysis with R language, we can see that Apple's stock price, though not stable, maintains an upward trend overall. The automatically fitted ARIMA (2, 2, 1) model can roughly reflect the stock price, but more detailed insights require further in-depth research. This paper provides a detailed introduction to the related theories and modeling steps of time series models. Based on the characteristics of Apple's stock price, an appropriate ARIMA model was established. By continuously updating the data, the model is supplemented and refined. From the model we established, it can be observed that the daily closing price of Apple's stock is significantly influenced by its price changes from 1 to 5 lags. Short-term forecasts of Apple's daily closing price have relatively small errors and can effectively predict the trend of Apple's stock price. However, long-term forecast errors are larger, indicating that more accurate analysis and prediction require continuous data updates followed by short-term forecasting. From the prediction and analysis of Apple's stock price, we can conclude that, at this stage, Apple's stock price changes are relatively stable, with minimal fluctuations, indicating good development status. References [1] Lv Changjiang, Zheng Huilian, Yan Mingzhu, et al. Design of Equity Incentive System for Listed Companies: Incentive or Benefit? [J]. Management World, 2009, (09):133-147+188. [2] Wang Meijin, Sun Jianjun. Returns, return volatility and investor sentiment in the Chinese stock market [J]. Economic Research, 2004, (10):75-83. [3] Xu Xiaodong,Chen Xiaoyue. Analysis of the Impact of the First Major Shareholder on Corporate Governance and Firm Performance [J]. Economic Research, 2003, (02):64-74+93. [4] Huang Shao'an,Zhang Gang. Analysis of Equity Financing Preferences of Chinese Listed Companies [J]. Economic Research, 2001, (11):12-20+27. [5] Tan Ruyong. An empirical study on the relationship between financial development and economic growth in China [J]. Economic Research, 1999, (10):53-61. [6] YANG Haimin, PAN Zhisong, BAI Wei. A review of time series forecasting methods [J]. Computer Science, 2019, 46 (01): 21-28.