Tuesday, September 22, 2015

Simple automated investing advisor

/*
This code will be my step by step figuring out of an algorithm to suggest best investing practices, given the valuations and times of the valuations.  For example, if stock 1 does well on the first day, while stock 2 does poorly, and stock 2 does well the next day and stock one does poorly.  The algorithm will suggest buying shares in the first stock the first day, selling them to buy stock 2 the second day.

Essentially it will follow the logic: calculate which stock has the highest rate of growth between given moments.  Since there is no cost to sell and no cost to buy (in this early step), All shares should be sold to purchase the stock which will have the highest rate of growth. The program should accept the following inputs: the value of stock 1 on day one, day two, day three, and the value of stock 2 on day one, day two, and day three.  The program will set a variable to represent how much money is owned.

A later update of this algorithm will return a prioritized list of what I should do next.  It will prompt me to gather information about the activities, such as what I can gain in return for doing them, when I will get the return, the amount of time which will be spent (it will multiply this by the current hourly work worth

*/

var s1d1 = prompt("what is the value of stock one on day one? ");
var s1d2 = prompt("what is the value of stock one on day two? ");
var s1d3 = prompt("what is the value of stock one on day three?");
var s2d1 =prompt("what is the value of stock two on day one?");
var s2d2 =prompt("what is the value of stock two on day two?");
var s2d3 =prompt("what is the value of stock two on day three?");

if (s1d2/s1d1 >= s2d1/s2d2)
 var answer = "Buy stock 1 for day one. "
else if (s1d2/s1d1 <= s2d1/s2d2)
var answer = "Buy stock 2 for day one. "

if (s1d2/s1d1 >= s2d1/s2d2)
 answer +=  "Buy stock 1 for day two. "
else if (s1d2/s1d1 <= s2d1/s2d2)
 answer += "Buy stock 2 for day two. "

if (s1d2/s1d1 >= s2d1/s2d2)
 answer += "Buy stock 1 for day three. "
else if (s1d2/s1d1 <= s2d1/s2d2)
 answer += "Buy stock 2 for day three. "

console.log(answer);

No comments:

Post a Comment