Question

Study the stationarity of stock from Apple Inc. Using a random forest from Scikit-learn to predict...

Study the stationarity of stock from Apple Inc. Using a random forest from Scikit-learn to predict stock prices for your chosen stock, and see how far into the future you can go.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Random forest algorithm is based on decision tree algorithm. It considers many decision trees at a time and then learn from the given dataset to build a model. This model is used to predict the values for unknown data.

Say, we have following data available for the stock prices over 10 years:

You may add more data in this.

Then for the above data, the python code will be:

Note: You may look the screenshot of the code to have better understanding of the indentation.

Source Code:

# Random Forest Regression

# Importing the libraries
import numpy as np
import matplotlib.pyplot as plt
%matplotlib qt
import pandas as pd

# Importing the dataset
dataset = pd.read_csv('Position_Salaries.csv')
X = dataset.iloc[:, 0:1].values
y = dataset.iloc[:, 1].values


# Fitting Random Forest Regression to the dataset
from sklearn.ensemble import RandomForestRegressor
regressor = RandomForestRegressor(n_estimators = 100, random_state = 0)
regressor.fit(X, y)

# Predicting a new result
samp = [[6.5]]
y_pred = regressor.predict(samp)

# Visualising the Random Forest Regression results (higher resolution)
X_grid = np.arange(min(X), max(X), 0.01)
X_grid = X_grid.reshape((len(X_grid), 1))
plt.scatter(X, y, color = 'red')
plt.plot(X_grid, regressor.predict(X_grid), color = 'blue')
plt.title('Truth or Bluff (Random Forest Regression)')
plt.xlabel('Position level')
plt.ylabel('Salary')
plt.show()

Output:

For year 6.5, the following prediction is done:

Plot:

Screenshot of code:

Add a comment
Know the answer?
Add Answer to:
Study the stationarity of stock from Apple Inc. Using a random forest from Scikit-learn to predict...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Look up and report the closing stock price of Apple, Inc., from the previous day. Do...

    Look up and report the closing stock price of Apple, Inc., from the previous day. Do you consider the stock to be overvalued? Justify your answer.

  • Prices as shown on 20 Dec 2018 Apple Inc :  Current spot price: $ 150    CALLS PUTS...

    Prices as shown on 20 Dec 2018 Apple Inc :  Current spot price: $ 150    CALLS PUTS Dec Jan Feb Strike Price Dec Jan Feb 5 8.85 - 149 2.67 6.6 7.93 4.25 8.35 9.65 150 3.15 7 8.38 2.97 7 7.95 152 4.2 8.1 9.5 1.88 5.83 7.36 155 5.85 9.3 10.64 Construct a  Bull Spread diagram using data from the above table. If  price of Apple Inc moves to 175 sometime in the near future how much profit will you make...

  • . On January 1, you tell your broker to sell short 500 shares of Apple Inc....

    . On January 1, you tell your broker to sell short 500 shares of Apple Inc. stock at a price of $100 per share. You use $30,000 cash to serve as a margin. (a) (5 points) How high can the stock price go before you get a margin call if the maintenance margin is 50%? (b) Assume that on April 1, a dividend of $4 per share was paid. On May 1, you covered the short sale by buying the...

  • Identify a healthcare-related topic that you would study using qualitative methods, and explain specifically how would y...

    Identify a healthcare-related topic that you would study using qualitative methods, and explain specifically how would you go about collecting the data to research your topic. Be specific as to what you would expect to learn from your study.

  • Question 11 4 pts Stratified samples are widely used to study large areas of forest. Based on sat...

    Question 11 4 pts Stratified samples are widely used to study large areas of forest. Based on satellite images, a forest area in the Amazon basin is divided into 14 types. Foresters studied the four most commercially valuable types: alluvial climax forests of quality levels 1, 2, and 3, and mature secondary forest. They divided the area of each type into large parcels, chose parcels of each type at random, and counted tree species in a 20- by 25-meter rectangle...

  • APPLE INC-CASE STUDY ON AGENCY THEORY Apple Inc started operations in early 1970. The company produces...

    APPLE INC-CASE STUDY ON AGENCY THEORY Apple Inc started operations in early 1970. The company produces specialized items for manufacturing cars. Most of the raw materials used are imported from Brazil because the cost is low and the labor is very cheap. The CEO for Apple Inc, Mr Rodriguez, makes every attempt to keep the cost at the lowest. From 1970 to 2000 net income has increased at a rate of at least 25% per year. There are around 20,000...

  • Your parents are considering investing in Apple Inc. common stock. They ask you, as an accounting...

    Your parents are considering investing in Apple Inc. common stock. They ask you, as an accounting expert, to make an analysis of the company for them. Financial statements of Apple are presented in Appendix A. The complete annual report, including the notes to its financial statements, is available at the company's website. Answer the following questions. Make a 5-year trend analysis, using 2013 as the base year, of (1) net sales and (2) net income. (Round percentages to O decimal places, e.g....

  • a.Why is it important to learn about statistics? At the beginning of the course, predict how...

    a.Why is it important to learn about statistics? At the beginning of the course, predict how you might see statistics applied in the medical sciences? b. Examine the four types of measurement scales. Give an example of where you might encounter each type. 2. Hi, I attached file here to answer the question. Please first one is just a sample answer. You need to answer the question on second assignment below the red line. Cite the source on APA professional...

  • Apple announces Mac transition to Apple silicon Recently, Apple announced their decision to move from Intel...

    Apple announces Mac transition to Apple silicon Recently, Apple announced their decision to move from Intel ISA to Arm ISA [1] for their future chips which they will design on their own. Prior to that, Apple made a similar transition moving to Intel ISA from Power PC ISA (a RISC-based ISA developed by AIM, which is a Apple-IBM-Motorola joint venture). The announcement was made in June 2005 and the first Intel-based Macs were available by January 2006. Even before that,...

  • Refer back to Apple Inc. as a technology company and assess the financial statements using the...

    Refer back to Apple Inc. as a technology company and assess the financial statements using the ratio tools Select at least one profitability, liquidity, solvency, and market valuation ratio and evaluate the results. Based on your findings, post an initial response to the following: What do the metrics tell you about the company’s performance? Support your answer by explaining the results from your assessment. If you were considering investing in the company, what other questions would you ask to gain...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT