Milestone III: Your Own Designed Trading Algorithm

Building on the momentum from the Moving Average algorithm, you’ll now try to outdo that algorithm with a snazzy one of your own!

Algorithm 2: Your Own Design

The next task will be to come up with your own algorithm to analyze the data. An important part of being a computer scientist is to be able to bring your ideas from the drawing board to a working program.

You should try to be as creative as possible. You can use outside data to augment your decision making as well! If you think stock trading performance is dependent on the phase of the moon, or the season, weather of that particular day, or some other weird thing - give it a go! There are many different possible options.

How does the algorithm you created compare to your moving average algorithm?

This algorithm has to be significantly different from a moving average, and sufficiently thoughtful for full credit (i.e. it needs to have some interesting complexity to it)!

I will dictate very little here, except the function prototype specified below. Follow the basic requirements of the function (name, args, return values), and the rest is up to you. Also, like in Milestone II, you are to sell all your stock when it finishes.

Because this algorithm is entirely of your own design, you need to provide sufficient docstring and comments to explain what you did, and why!

def alg_mine(filename):
    """This function implements the student's custom trading algorithm.

    Using the CSV stock data that should be loaded into your program, use
    that data to make decisions using your own custome trading algorithm.

    Also, any bookkeeping setup in Milestone I should be called/used here.

    Args:
        A filename, as a string.

    Returns:
        Two values, stocks and balance OF THE APPROPRIATE DATA TYPE.

    Prints:
        Nothing.
    """

    # Last thing to do, return two values: one for the number of stocks you end up
    # owning after the simulation, and the amount of money you have after
    # the simulation.
    # Remember, all your stocks should be sold at the end!
    return stocks_owned, cash_balance

Now your main() function.

# Don't forget the required "__main__" check!
def main():
    # My testing will use AAPL.csv or MSFT.csv
    filename = input("Enter a filename for stock data (CSV format): ")

    # Call your moving average algorithm, with the filename to open.
    alg1_stocks, alg1_balance = alg_moving_average(filename)

    # Print results of the moving average algorithm, returned above:
    print("The results are...")

    # Now, call your custom algorithm!
    alg2_stocks, alg2_balance = alg_mine(filename)

    # Print results of your algorithm, returned above:
    print("The results are...")

Output

I don’t care what gets printed to the screen, so long as alg_mine(filename) returns the correct data.