Spartan Trader - part 8 (H21)

The Recommender


Goal

By completing this homework you will implement an algorithm that hedges a portfolio of stocks and options using (for now) stocks. The algorithm analyzes the current market situation, makes decision on transactions that will hedge the portfolio, and executes those transactions.


Context

source:memegenerator.net

“My friend, it is time.”
“It is time for what, Ms. Tickertracker?”
“It is time to wave our magic wand and start infusing some smarts into our Spartan Trader.  I feel like Dr. Frankenstein the night before the experiment.  It will be WONDROUS!”
You feel that this time your Boss’ guidance is way too vague for you to get to work.   “Your analogy is thrilling, Ms. Tickertracker….  What do you have in mind?  What kind of ‘smarts’ would you like me to ‘infuse’ into the program?”
“We will endow the Spartan Trader with the ability to recommend transactions designed to hedge our portfolio.”
“How will we do that?”
“Think of our IP portfolio as composed of several families of related securities.”
“Sure, for example, the AAPL stock and all the options with AAPL as an underlier can be seen as a family of related securities.”
“PRECISELY.  I want you to write an algorithm that computes the family delta for each family.  Then, for each family, the algorithm recommends either buy, sell, sell short, or buyback a security so that when that transaction is executed, it will make the resulting family of securities delta neutral.”
“Got it.  First compute the family delta, then select one transaction that will make the family delta neutral.  How will the algorithm identify the right transaction?”
“So INSIGHTFUL! The algorithm will consider ALL possible transactions (buy/sell/sell short/buy back) and then select the one that works best.”
“How?”
“You see, certain transactions will not be feasible.  There are financial constraints: how much money we have in our Capital Account, the margins,  whether the markets are open, expiration dates… So, for example, certain transactions will be too expensive, and we will not be able to execute them for lack of funds. Other transactions will violate our margin limits…”
“Understood.  So the algorithm will consider all possible transactions, then eliminate the ones that are not feasible… but what if we are left with more than one feasible transaction?  Which one do we recommend?”
“MOST PERSPICACIOUS!  In that case, we will use a scoring system based on our preferences: the algorithm will select the transaction with the highest score and that will be the recommendation shown to the user.”
“And those preferences will express our hedging strategy.”
“You are catching up ASTOUNDINGLY fast! These preferences will be part of our secret sauce. I am glad I hired you.”
“I am on it, Boss.”


Requirements

This homework adds to the Spartan Trader the capability to recommend transactions that hedge the IP portfolio. For now, the system only recommends buying/selling stocks. The homework

  • is cumulative, which means that it needs to do everything that the previous homework did
  • generates recommended transactions designed to hedge each of your twelve family portfolios,  At this point the only recommendations it can generate are about buying and selling stocks.
  • Visualizes the recommended transactions, but does not automatically execute them

The vLab contains a demo and instructions, and this file contains a lot of code, so that you do not have to type as much (you are welcome!).  As before, feel free to change the look and feel of the app.