Concept explainers
Index (RSI) Algorithm
Building on the momentum from the Moving Average algorithm, you’ll now try to develop a more sophisticated algorithm to outdo it! With this algorithm you will make trading decisions with Relative Strength Index, or RSI.
How does this algorithm compare to your moving average algorithm?
Algorithm Description
The relative strength index (RSI) is defined as a momentum indicator that measures the magnitude of recent price changes to evaluate overbought or oversold conditions in the price of a stock. The index is calculated by the average gain and average loss over a rolling time window.
-
???????????=?????????/????????AverageGain=TotalGain/Lookback
-
?????Gains: When there was a price increase compared to the previous day, the gain is equal to that price gain value, otherwise set to zero.
-
?????????TotalGain: The sum of the gains over the lookback period.
-
????????Lookback: The number of days of previous data to look back.
-
-
???????????=?????????/????????AverageLoss=TotalLoss/Lookback
-
??????Losses: When there was a price decrease compared to the previous day, the loss is equal to that price loss value, otherwise set to zero.
-
?????????TotalLoss: The sum of the losses over the lookback period.
-
????????Lookback: The number of days of previous data to look back. The typically used value for the “lookback” is 14 or 21 days.
-
-
???=100−(100/(1+(???????????/???????????)))RSI=100−(100/(1+(AverageGain/AverageLoss)))
Your task is to develop a Python program to calculate the RSI and see if the market is trending towards a positive or a negative momentum associated with a stock. In your code, a trading decision needs to be made based on RSI.
-
Buying position: When the RSI for the stock is below 30, it indicates a good buying position. This signifies that the market is oversold.
-
Selling position: When the RSI for the stock is above 70, it indicates a good selling position. This signifies that the market is overbought.
On each day, you need to make trading decisions on two distinct data files based on the criteria above. You can test using AAPL.csv and MSFT.csv, but I may test with any two stock data files from random companies.
You can trust that any tested stock files will have the same date ranges for the data.
A starting balance of $10,000 is recommended.
Additional Requirements¶
-
For each company, you must buy, or sell 10 stocks, or less per transaction.
-
You are free to choose which column of stock data to use (open, close, low, high, etc).
-
When your algorithm reaches the last day of data, have it sell all remaining stock. Your function will return the number of stocks you own (should be zero, at this point), and your cash balance.
-
You are not allowed to “look into the future” in your data. Your simulation has the data for the current day, and the past.
-
You are not allowed to use test_data() directly in Milestone III, so be sure to write new functions that use what you learned from writing that function.
-
You must use the transact() function you wrote in Milestone I, as it will help you make some of the basic decisions for buying and selling you will undoubtedly make.
Date |
Open |
High |
Low |
Close |
Adj Close |
Volume |
2000-01-03 |
3.745536 |
4.017857 |
3.631696 |
3.997768 |
2.695920 |
133949200 |
2000-01-04 |
3.866071 |
3.950893 |
3.613839 |
3.660714 |
2.468626 |
128094400 |
2000-01-05 |
3.705357 |
3.948661 |
3.678571 |
3.714286 |
2.504751 |
194580400 |
2000-01-06 |
3.790179 |
3.821429 |
3.392857 |
3.392857 |
2.287994 |
191993200 |
2000-01-07 |
3.446429 |
3.607143 |
3.410714 |
3.553571 |
2.396373 |
115183600 |
2000-01-10 |
3.642857 |
3.651786 |
3.383929 |
3.491071 |
2.354226 |
126266000 |
2000-01-11 |
3.426339 |
3.549107 |
3.232143 |
3.312500 |
2.233805 |
110387200 |
Date |
Open |
High |
Low |
Close |
Adj Close |
Volume |
2000-01-03 |
58.687500 |
59.312500 |
56.000000 |
58.281250 |
42.641369 |
53228400 |
2000-01-04 |
56.781250 |
58.562500 |
56.125000 |
56.312500 |
41.200928 |
54119000 |
2000-01-05 |
55.562500 |
58.187500 |
54.687500 |
56.906250 |
41.635361 |
64059600 |
2000-01-06 |
56.093750 |
56.937500 |
54.187500 |
55.000000 |
40.240646 |
54976600 |
2000-01-07 |
54.312500 |
56.125000 |
53.656250 |
55.718750 |
40.766510 |
62013600 |
Trending nowThis is a popular solution!
Step by stepSolved in 4 steps
- What would a student's raw score be on a test if she earned a z-score = -0.43? (Given: mean = 63; s = 7) Group of answer choices 54 57 60 63arrow_forwardsimilar to this, but with 4 states Online chess game - state diagramarrow_forwardRobot is at position 0 and move the robot to a destination x(x>0). Robot moves in 1,2,3,4,5 steps.Find the minimum number of steps to reach the destination Ex:destination x=12 output: 3 stepsarrow_forward
- Overview In this assignment, you will gain more practice with designing a program. Specifically, you will create pseudocode for a higher/lower game. This will give you practice designing a more complex program and allow you to see more of the benefits that designing before coding can offer. The higher/lower game will combine different programming constructs that you have been learning about, such as input and output, decision branching, and a loop. Higher/Lower Game DescriptionYour friend Maria has come to you and said that she has been playing the higher/lower game with her three-year-old daughter Bella. Maria tells Bella that she is thinking of a number between 1 and 10, and then Bella tries to guess the number. When Bella guesses a number, Maria tells her whether the number she is thinking of is higher or lower or if Bella guessed it. The game continues until Bella guesses the right number. As much as Maria likes playing the game with Bella, Bella is very excited to play the game…arrow_forwardPlease I need graphic images in the solution required for drawing products and reach a wider range of customers by using the software product line (SPL) technology as described next All products in this SPL must be capable of providing a basic vacuum cleaning as follows: The user presses the power button located on top of the vacuum cleaner. The system starts vacuuming by activating the two spinning brush motors. The system starts moving the vacuum using a simple, random walk algorithm as follows. The system signals the wheel motors to move forward so that the vacuum moves forward. When the system detects an obstacle, the system rotates the wheels in a randomly selected degree and then moves signals the wheel motors to move forward. The system updates the battery level indicator every 1 minute (when the battery level reaches 15% or lower) The user presses the power button again. The system stops vacuuming by deactivating the brush and wheel motors. It should be noted that if the…arrow_forwardHorizontal sequence :RIVL Vertical sequence:FMK Scoring rules: g/o = -3, g/e = -1, match or mismatch - from PAM250 substitution matrix below. NW algorithm. 1. Complete the scoring matrix. Scoring matrix with PAM250 scores: R I V L F M K 2. Set up, initialize and complete the NW matrix. 3. Retrace, align and score alignment(s). Use the arrows and circles for the matrix and path(s). R I V L F M K Align and score all optimal alignments here. PLZ the arrows and circles for the matrix and path(s) AND SHOW ALL possible Alignmentarrow_forward
- 1 / 3 Exercises Exercise I: Consider the following rotation matrix R: The ratio between B and D is 2, and B > 0. (a) (b) Го A B R= C D -0.354 E 0.612 F 75% Exercise 2: Suppose that F is transformation matrix ▾ Find the values of A, B, C, D, E, F. Verify that the obtained R is a rotation matrix within some rounding errors. 0014 O Onearrow_forwardAlert dont submit AI generated answer.arrow_forward#2arrow_forward
- Se x + learn.edgenuity.com/player/ nciples Semester A This algorithm is using a heuristic Mark this and return brute force approach heuristic tractable problem superpolynomial time O to approximate the best route. ↑ A mapping application cannot consider every factor to calculate the fastest route in a reasonable amount of time. Instead, the application uses an algorithm that considers only the most important factors such as total distance and traffic congestion along popular routes. MD A Save and Exit Next G < English Sign out ☆ * TIME REMAINING 58:34 Submit Mar 27 19 0 Kinley Heath X ⠀ + 10:25 0 4arrow_forwardOut next step is Match. Recalling for similar problem solved in the past is also very helpful. It may even present you the solution directly. In fact this is why solving a lot of problems is beneficial. If you are a beginner, this may be bit challenging but as you solve more and more problems, you will improve. Imagine you have solved below problems and select the most suitable Match for the fizz buzz problem. O Given the APR of a bank savings account, calculate the compounding interest earned for given amount of years of a given initial investment amount. O Given the Fahrenheit temperature, return the respective Celsius temperature. O Given a positive integer number, return the factorial of the number. O Given the class average total marks of a student and the cutoff marks for the pass/no pass grade return the student's pass/no pass grade by returning either "Pass" or "No pass". O Given an integer number, extract the first digit numerically. Search barrow_forwardThe two pictures uploaded are explaining the taskarrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education