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

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

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.

Milestone Submission Requirements¶

1. Simulation Code (18 points) Your custom trading simulation should be written according to the specification given. Most decisions are left to you, regardless Your algorithm will not at any point look ahead at ‘future’ stock data. You can only use data for the days gone for making decisions in your simulation’s ‘current day’
2. Data Handling (5 points) Is your algorithm appropriately using the data you loaded from the CSV file?
3. Bookkeeping (5 points) Your trading function should appropriately use the groundwork built in Milestone I (or, updated afterwards for this Milestone). That is, does your trading algorithm make the right decisions when buying and selling, and does it track this information appropriately. For example, you can’t sell if you own zero stocks! Things like this should be covered.
4. Testing (5 points) I will test your code by calling your alg_mine() function directly. It should run smoothly and return the two values specified of the correct data types (stocks: integer, cash: float).

Points may be generally deducted across all categories in cases of syntax, style or running issues.