/Time-travel-Project

Project for the course in Programming tools and technologies for Data science & Machine Learning @ NTUA

Primary LanguagePython

The Time - travel project

This repository was developed for the purposes of the course in programming tools and technologies for data science and machine learning during my first semester as a graduate student in the Master's programme in Data Science & Machine Learning @ NTUA.

The storyline is the following:

Imagine that you could travel back in 1970 with a huge list containing all the information about the stock prices of the companies participated in the American stockmarket from 1970 until 2017. Futhermore, suppose that you have only 1 dollar in your pocket. The task is find two sequences of buy - sell moves with maximum lengths 1.000 and 1.000.000, respectively, in order to maximize your profit. At a given point there are six possible moves:

  1. Buy - open: buy at the opening price of the day
  2. Sell - open: sell at the opening price of the day
  3. Buy - low: buy at the lowest price of the day
  4. Sell - high: sell at the highest price of the day
  5. Buy - close: buy at the closing price of the day
  6. Sell - close: sell at the closing price of the day

The above moves are chronologically ordered in the following manner:

{buy-open, sell-open} >> {buy-low, sell-high} >> {buy-close, sell-close},

where the notation "A >> B" indicates that action A must happen before B. Futhermore, each move is bound to the following restrictions:

  1. The total number of stocks "s" that we buy at a given day "d" it should not exceed the 10% of the volume of stocks "s" at day "d"
  2. Similarly, the total number of stocks "s" that we sell at day "d" it should not exceed the 10% of the volume of stocks "s" at day "d"
  3. Suppose that at the beginning of day "d" we possess "n" stocks from "s", then during the day "d" we are not allowed to buy more than "n+1" stocks from "s".

Under these restrictions the goal is to find two sequences of moves with at most 1.000 and 1.000.000 moves, respectively, that maximize the profit. By the term profit we mean the total money after the execution of all moves. Futhermore, for a given sequence of moves we define the evaluation at a given day to be the sum of the money on the bank account and the value of all of our stocks in the closing price.

More details about the algorithm that was developed in order to provide a solution to this problem can be found on the report-pdf. The dataset can be found on Kaggle in the following link. Since it is infisible to examine every combination of companies the algorithm takes as input a list of companies and tries to find the best transactions between these companies. Below you can see the results obtained for the sequence with at most 1.000 and 1.000.000 moves respectively.

1.000 Moves

- Default Companies: {'AMZN', 'GE', 'AAPL'}

- Total transactions: 936

- Money earned: 4670718.89886

Below you can see the graph of the profit (balance) and evaluation (portfolio) obtained for the above transactions.

1.000.000 Moves

- Default Companies: {'MSFT', 'BAC', 'SIRI', 'FB', 'ORCL', 'EBAY', 'CSCO', 'AAPL', 'MO', 'GE', 'INTC', 'HD'}

- Total transactions: 52481

- Money earned: 22912967542.46073

Try your own combination of companies!

You can download the .py scripts and execute the mainscript.py with your own list of companies and become billionaire! Suppose you want to set a maximum number of 1500 moves and choose Amazon, Apple, Facebook and General Electric as companies, then you type the following command in the command line.

>python ./mainscript.py 1500 COMPANIES 4 AMZN FB AAPL GE

The identified word COMPANIES tells the program that the user will choose his/her own combination of companies, the number following the identifier word corresponds to the number of companies that the user will provide. If you want to print the results on screen you can type the following command.

>python ./mainscript.py 1500 COMPANIES 4 AMZN FB AAPL GE PRINT TRUE

and if you want to save the transactions into a txt file you can type

>python ./mainscript.py 1500 COMPANIES 4 AMZN FB AAPL GE SAVEFILE TRUE

Have fun!