Updated: Mar 8
The winter holiday season, whatever you celebrate, contains magic. From solar cults celebrating that the sun is no longer dropping from the sky (this is still 2020, expect anything regarding the sun) to consumerist cults celebrating the materialism of modernity, or the new year Calendarists and their holy 00:00, and having Christmas (as a religious celebration) in between, everyone can find an excuse to be happy for a while, or at least has a chance to entertain that illusion at the end of this 2020 that, history to confirm, will be marked as a generally bad year (history makes do without stronger words).
Today Ostirion joins the ranks of the best sagas, joins into the magic along the Star Wars Holiday Special, the Teenage Mutant Hero Turtles and Bill Murray. We have no good specials to comment on from Spain, La Casa de Papel seems not to have one yet. We join into the magic and we are going to make do without capable artificial intelligences, advanced machine learning models or complex stuff in general to engage with the best possible magical thinking... citing Forbes. In this article, now old, multiple holiday season hopefuls are quoted saying that monkeys, random agents, are capable of beating anything related to the market, making everything else utter nonsense.
The magic is strong this time, this is Mochi:
We found him in the streets five years ago, did not run away, was hungry and thirsty and had no identification chip. None in the area claimed him but he clearly was not a street cat. Mochi thinks he can beat any arrogant quantitative trader or automated robot using the powers that the holiday season confers on him just by walking over the keyboard. This is what Mochi, or the Forbes monkeys do. We will try to simulate this random walking over the keyboard on Wall Street using Quantconnect backtest tool.
We will let Mochi decide our investment decisions, not totally sure of his capabilities are going to limit him to SP500 companies, or similar stock, and we are importing the library that will power Mochi: "random", he is a cat after all:
from Selection.QC500UniverseSelectionModel import QC500UniverseSelectionModel import random
The algorithm for Mochi to work on is initialized, the start date is, of course, the date in which we found Mochi and put him to work in the financial industry. Mochi is a brave cat and will invest 1 million dollars of his own money. He cannot bother with accessories to his trading model so that it will just include an immediate execution model and insight weighted portfolio construction, insights that he himself will decide!
class HolidaySpecial(QCAlgorithm): def Initialize(self): self.SetStartDate(2015, 9, 25) # Set Start Date self.SetEndDate(2020, 12, 25) # Set Start Date starting_mochi_cash = 1000000 self.SetCash(starting_mochi_cash) # Set Strategy Cash self.SetBrokerageModel(AlphaStreamsBrokerageModel()) self.SetUniverseSelection(QC500UniverseSelectionModel()) self.UniverseSettings.Resolution = Resolution.Daily self.AddAlpha(MochiAlphaModel(self, starting_mochi_cash)) self.SetExecution(ImmediateExecutionModel()) self.SetPortfolioConstruction(InsightWeightingPortfolioConstructionModel(lambda time: None))
The starting wealth (the mochicash) is fed into the alpha model that Mochi makes:
class MochiAlphaModel(AlphaModel): def __init__(self, algorithm, starting_mochi_cash): self.Name = 'MochiPAlphaModel' self.mochi_wealth = [starting_mochi_cash] self.CreateMochi()
We create Mochi, Mochi the stock agent, that behaves like this:
def CreateMochi(self): self.mochi_diligence = random.random() self.mochi_patience = random.randrange(253) self.mochi_grumpyness = random.random() self.mochi_directions = [InsightDirection.Down, InsightDirection.Up] self.mochi_hoardiness = random.randrange(500)
Mochi will be either diligent or lazy, have patience or be a passionate short-term trader, be grumpy to a certain degree and will like to hoard stock from a lot of different companies, or just a few. He also knows that stock price can go up or down, so he will act accordingly.
The Update method contains what Mochi will do when receiving each new and shiny stock data package:
def Update(self, algorithm, data): # Clear counters and insights, return if data slice is empty. mochi_insights =  if not data.HasData: return 
If there is none, he will not do work, will go back to sleep. Even if there is work to be done, Mochi cannot feel like doing it, and may just decide not to trade that day, he goes back to research environment:
if random.random() > self.mochi_diligence: return 
When Mochi works, he makes a list of the stocks he likes, using his deep analytical capabilities to select them:
things_mochi_likes_now =  # What companies does Mochi like? for symbol in data.keys(): if random.random() > self.mochi_grumpyness: things_mochi_likes_now.append(symbol)
Maybe Mochi has decided that there are too many companies he likes! No problem, his hoardiness can kick in and decide to drop some of them, or keep them all:
maximum_things_mochi_likes = len(things_mochi_likes_now) picks_a_few = min(self.mochi_hoardiness, maximum_things_mochi_likes) if picks_a_few == 0: mochi_is_tired = True return 
For each company he likes Mochi decides if that company is going up or down, as a smart cat he knows shorting is sometimes good. He determines the weight of that stock in the portfolio and even for how long to hold the position, depending on how patient he feels.
for symbol in random.choices(things_mochi_likes_now, k=random.randrange(picks_a_few)): is_this_going_up = random.getrandbits(1) how_much = random.random() mochi_direction = self.mochi_directions[is_this_going_up] and_when = timedelta(days=self.mochi_patience) how_much_does_mochi_invest = random.random() one_mochi_insight = Insight(symbol, and_when, InsightType.Price, mochi_direction, how_much, 1, self.Name, how_much_does_mochi_invest) mochi_insights.append(one_mochi_insight)
Mochi is worried about his performance, so after a working day he will evaluate the state of his portfolio and, if needed, he will reevaluate his methods (will not learn much, being a cat and all that), and finally, emit his deep insights on the market:
self.mochi_wealth.append(algorithm.Portfolio.TotalPortfolioValue) is_mochi_winning = self.mochi_wealth[-1] > self.mochi_wealth is_mochi_doing_good = self.mochi_wealth[-1] > self.mochi_wealth[-2] and is_mochi_winning if not is_mochi_doing_good: self.CreateMochi() return mochi_insights
How did Mochi do in the past? How will he do in the future? Will they return? Who? The ancient aliens, of course, as they can become the best topic of conversation in seasonal family gatherings, avoiding many other controversial and less interesting topics. Mochi does, well..., he seems no to be the correct monkey:
He fell asleep somewhere in 2017 after making 500$ out of a million!
He lost a lot of money!
And finally even Mochi makes money! It is for sure a choppy and capricious trading result, but hey, a 5% in 5 years is not bad for a cat behaving at random. He also made the results charts look like mid-90s web pages, the magic is indeed back!
At this point we could run as many Mochi simulations as we wanted, and try to average the results. A future (or, released just as this is published) Quantconnect feature will apparently provide the capability to run automated batches of models and obtain aggregate performance results, we could run infinite Mochi models in the future!
This Mochi model has been designed to minimize as much as possible bias. The Forbes monkeys were, in their form, biased towards long, long-term strategies that yes, could in some sample cases outperform the market. Generally speaking, no, it is not beneficial to let a cat or a monkey pick stocks in a random fashion, really random behaviour, not just random behaviour inside a constraint set that fits the past very gell. We hope to have presented an "on-par" Holiday Special, the intention is to enjoy the festivities... and to justify our work!
We wish you a happy holiday season and a merry Christmas.
Remember that information in ostirion.net does not constitute financial advice, we do not hold positions in any of the companies or assets that we mention in our posts at the time of posting. If you are in need of algorithmic model development, deployment, verification or validation do not hesitate and contact us. We will be also glad to help you with your predictive machine learning or artificial intelligence challenges.
The code for the Mochi model, if you wish to try your holiday luck, is here: