Introduction

Unfortunately, the field of effective trading algorithms using the OHLCV data is gradually narrowing. This process is influenced by the fact that a lot of trading companies are constantly conducting market research and exploiting new inefficiencies. Over time, these inefficiencies disappear and the algorithms lose their statistical characteristics. In such a situation, external data comes to the rescue. With the help of external data sources, it is possible to significantly expand the field of effective algorithms and raise the bar for their ultimate efficiency.

There is a lot of external data in the cryptocurrency market right now, from off-chain metrics to sentiment, but large firms are already using this data in their analysis. Besides that, for a long period of time large financial companies have been trying to work with traders’ emotions and build additional layers of protection against emotional burnout. It is known that some large companies in a pilot mode tried to use neural interfaces to prevent traders from accessing the terminal in the event of a violation of brain activity indicators. Sometimes a trader is clearly not in the best shape, but either he cannot recognize it himself, or he does not admit it for one reason or another.

If the financial environment has already successfully implemented the experience of automating the task of “filtering burned out traders”, then I will go further and try to digitize the complex set of traders’ emotions. Simple ideas can be written on paper, then formalized and translated, but a complex system of incentives that induces a trader to make trades cannot be described that way. The purpose of this article is to try to discover a new class of synthetic external data - the brainwaves of real traders. If this approach works, then in the long term it can significantly expand the opportunities for creating profitable and stable algorithms. I do not know what will come of it, but I will try to take the first step in this direction, describe my understanding of the mechanics of the process, put the first experiment, and highlight possible problems.

Theoretical basis and concept

The brain is an extremely complex mechanism that cannot be programmed to work. The famous physicist and mathematician Roger Penrose believed that human consciousness does not lend itself to algorithmization and cannot be digitized by a computer. I completely agree with him, but it is not needed, because, as a rule, good trading ideas that work consistently and bring profit are quite simple.

I will try to decompose the task of scanning the trader's internal state and figure out only the most important information.

Conventionally, the tasks of neural interfaces can be divided into two large groups: decoding a response to an external influence and decoding an internal state. In the case of decoding the internal state, a scientist tries to decode imaginary representation (for instance, imaginary hand movements, which are often used in medicine - restorative therapy). Response to external stimuli is an approach that reads the responses of the subject through indicators of brain activity with some influence on his perceptual mechanisms.

Reaction to external potential is just the method that suits our research. I will try to present the subject with visual potentials in the form of price and volumes changes and try to track his reaction.

Brain waves are closely related to our emotional state, feelings, and thoughts. With the help of these waves, people can understand the state of a person and the state of the market observed by him. Thus, if I measure the brain activity of an experienced trader, I can extract the way new off-market data, that may have great predictive potential.

Brain waves are formed when neurons respond to environmental stimuli very quickly (the response rate is measured in microseconds). When millions of neurons continually respond to stimuli, they produce "swinging" electrical discharges. These discharges create a rhythm called "brain wave".

Let’s skip the comprehensive physics of waves generation. I will only mention that the signal source is formed in the depressions of the cerebral folds. The physics of the process is arranged in such a way that the cranium is a rather strong obstacle to the transmission of an accurate signal. However, I also note that, unlike acoustic signals, the physics of the brainwave process does not imply delays in the propagation of the signal. Since there is no delay in reading the signal, it is possible to digitize strategies at any timeframes.

Rhythms are generated from a raw signal, which is divided into clusters of different frequencies with a specific power using the Fast Fourier Transform. The types of waves differ in the frequency spectrum, and their value is essentially the average power in a certain frequency range.

Let's look at the spectrum of frequencies that our neural interface reads and see which of them will be of interest to the research

  • Delta (0.5 – 2.75Hz): these brainwaves are usually active during the subject's rest and regeneration processes. Most often, during the activity of these waves, the subject is asleep or unconscious, so I will not use this spectrum in our model.
  • Theta (3.5 – 6.75Hz): These waves are active during bursts of creativity and active work of the subconscious. Rather, trading processes require concentration and formal analysis, so this brainwave will also not be used to build a model.
  • Low-Alpha (7.5 – 9.25Hz): these waves are associated with a calm, balanced and concentrated state, similar to meditation. I will use these waves in the model.
  • High-Alpha (10 – 11.75Hz): this spectrum is activated during a mental state of open awareness (the ability to adequately respond to changes in the environment.  I will use these waves in the model.
  • Low-Beta (13 – 16.75Hz): these waves are active during mental stress and mental stress, which, by the way, are closely related to the trading process. This data will definitely come in handy for us.
  • High-Beta (18 – 29.75Hz): this frequency range often rises during anxiety, worry, or reflection. Of course, the state in which a trader finds himself after a series of unsuccessful deals comes to mind.  I will use these waves in the model.
  • Low-Gamma (31 – 39.75Hz) These waves are active during times of stress, anxiety, and alertness. All these states are an integral part of trading, so the data will be useful to us.
  • Mid-Gamma (41 – 49.75Hz): these waves are manifested with increased concentration and energetic attention. These waves are associated with information processing when many brain units work together. It would be useful to input this spectrum into the model.

In fact, I could draw certain conclusions from all spectrums of brainwaves and their combinations, but it is important for us to strike a balance between the complexity of the model and the complexity of the trading process - there is always a risk of overfitting.

Methodology

To build a model, I will take data from brain waves, the quality of which can be improved not by software, but by physical methods. For example, breathing practices, meditation, and yoga have been shown to increase brain wave activity in general. So, regular meditation practice before trading provides us with better and “pure” results. On average, people who practice meditation have more alpha activity, and this is often associated with calming and other positive effects. Moreover, breathing practices and meditation help to improve concentration and calmness, which should also affect the quality of the trading signals generated by the trader and his well-being.

I will act as the first subject for this methodology of developing trading strategies. In addition to 6 years of experience in developing trading strategies for different markets, I have experience in trading on derivative markets,, where I have been trading for 2 years. During the entire time of developing a strategy and trading manually, I have accumulated quite extensive visual experience and visually identify market patterns well.

For this task, I will use EEG (electroencephalogram) methods, that is, to measure the total electrical activity of the brain. This approach has many drawbacks, but for our task, many of them can be leveled, for the rest, I will have to look for compromises.

EEG does a poor job of locating brain activity. Nevertheless, when I work in the paradigm of “decoding a response to an external influence”, the localization of brain activity is not so important to us. The most important parts are the speed of the response (specifically for our task) and the general description of brain activity, from which I can extract the necessary information. As I said earlier, the physiology of the signal is such that there is no delay in data transmission.

Signal noise also plays an important role in measurements. In an ideal world, I would conduct an experiment in a vacuum or use expensive signal amplifiers, which are now available only in special laboratories. In fact, signal noise is affected by many factors associated with electrical waves, right down to nearby power sockets. During the experiment, I will try to minimize external influences on the reader. Do not forget that in our case the influence of external signals cannot be avoided, because the trader will inevitably look at the monitor, this is the essence of the experiment.

For the measurement, I will use the Brainlink Lite device. It transmits data to the computer via Bluetooth. Its connection may contain interference due to external sources. For instance, it shares the same frequency spectrum as Wi-Fi. Therefore for a clear experiment, I need to minimize the influence of external sources.

Brainlink Lite contains three dry electrodes. Brainlink firmware uses sophisticated mathematics to process these signals and put them straight into our computers. Signal noise is processed at the lowest software level. In the future, during the preparation of the data, I will use special techniques to identify and isolate noisy areas.

The sample in this study is limited to one person who has experience trading on the stock exchange. Perhaps 1 person is not enough to draw full conclusions, so the next study should be carried out on a larger group of subjects with different trading skillsets. It is also worth taking into account the limitations of the measuring device, perhaps in the next study, it is worth replacing it with a more powerful one.

In order to collect data, I made a program that shows the candlestick chart and the trading volume of Bitcoin. The y-axis is logarithmic, y is numeric, and it does not contain a date. I tried to make the chart as abstract as possible to exclude the possibility of a learned reaction - I could remember some parts of the chart for certain dates and react to them, already knowing the correct answer. This approach excludes looking into the future on the part of the subject.

Every second a new candle is added to the chart and at the same time, the Brainlink Lite device reads the brain data. It happens synchronously. There is always a fixed number of candles on the chart - 150. In order to formalize the chart that I observe, I decided to collect several metrics that, it seems to me, fully describe what is visually happening on the chart.

  • High Momentum -amplitude  of  the momentum  from the minimum value on the chart to the maximum
  • Low Momentum - amplitude  of  the momentum  from the maximum value on the chart to the minimum
  • Fast Momentum - 14-period momentum
  • Volatility - volatility of the chart
  • Norm Close - normalized close price
  • Norm Volume - normalized trading volume

*HighMomentum and LowMomentum were calculated according to a special algorithm that takes into account which movement was the last - ascending or descending

I stockpiled the metrics to test their predictive power and test a larger pool of inputs. For brain waves, I also tried to collect as much information as possible so that later I could effectively clean up the data:

  • Delta, HighAlpha, HighBetta, LowAlpha, LowBetta, LowGamma, MidGamma, Theta
  • Meditation - a cumulative index that shows the concentration level. With this indicator, I will try to filter out invalid data.

For analysis, I used hourly candles from 2019/10/05 to 2022/01/15. A total of 19996 observations were obtained. In case you convert this into time spent, you get more than 5 hours spent in front of a computer screen. I collected data in iterations of 20-25 minutes, each time leaving a small margin of candles to prepare for the next iteration. This is done because the program synchronizes the data for the first few candles. I also left a supply of candles for each iteration so that the Brainlink had time to tune in and start receiving data without interference.

Building model

The target metric for predictions in our case can be:

  • A synthetic index is composed of the different types of brainwaves described above (LowAlpha, LowBetta, HighAlpha, HighBetta, MidGamma, LowGamma). This approach is good in theory, but in practice gives an absolutely unpredictable multipart index. The sum of indexes with different patterns and inefficiencies of the same dimension, when averaged, gives the target metric, which is practically very difficult to predict.
  • Two synthetic indexes, grouped by meaning:

Positive index - averaging (LowAlpha + HighAlpha + MidGamma)

Negative index = averaging(LowBetta+HighBetta+LowGamma)

This approach has the same problem as any multipart synthetic index.

  • Each individual index - this approach seems to be the most reasonable, because it kind of decomposesx the task of predicting the global emotion index, while greatly simplifying it and throwing out the excess. With this approach, I will simply remove the indices for which the model is built with the maximum error and will not use them at all.

To get a cleaner input, I will filter values by the Meditation index. It is likely that when I was more focused during my observations, the data was clearer. The output data will be used without a shift since I will try to bring our model as close as possible to the instantaneous reaction. For each target metric, I will build an LSTM (Long Short-Term Memory) model with a different threshold on MeditationIndex and a different number of inputs. The results of the model will be evaluated by standard metrics - RMSE (Root Mean Squared Error).

I have to note that I am trying to strike a balance between simplicity and efficiency, therefore I do not strive for our neural network to be too complex - the simpler the model, the easier it will be to use in the production.

Based on the results of model optimization, it turned out that models with 1 input perform best - this is the normalized closing price. There is nothing strange in this, but I hoped that my approach to the complex description of the chart using momentum would show itself better. This predictor approximates LowGamma and MidGamma well on different MeditationIndex thresholds. Since these two indices just reflect the opposite states of emotions (positive and negative), I will use them.

To make sure our data has statistical power, I built exactly the same models but used previous values as a predictor. According to the results, our models with LowGamma and MidGamma approximate the value of the target metric much better. Now let's try to make several strategies from the obtained models:

  • In the first variant, the trigger for entering the position will be the indexes obtained using the neural network, and it will exit after n bars (let's call it MidGammaNBarsStrategy). Such a primitive strategy will allow us to understand whether our data has at least some predictive potential and whether it is possible to work with them further.
  • The second strategy will use entry/exit signals of the strategy, which certainly shows good results both in backtests and in real trading. I will try to add a trade filter to this strategy, which will filter out entries by threshold: for the Midgamma algorithm trade if the index is greater than the threshold, for LowGamma if it is less.

I optimized strategies using a genetic optimizer on hourly bitcoin price data for the same period as I collected the data. The commission is 5 pips per trade, this amount includes slippage. All transactions are made on the market, with the execution of limit orders, the results will be better. The strategies use data with a threshold on the meditation index = 80.

I give an example of strategies using Midgamma, strategies on LowGamma show similar results and the conclusions on them will be the same.

In the picture below can be seen with the naked eye that although MidGammaNBarsStrategy has a positive slope of the equity curve, its p-value is quite high, which means that our strategy does not have any special advantages over the strategy that generates signals randomly. As a first approximation, it can be seen that indices are not suitable for generating trading signals head-on, if I add filters and additional conditions to this strategy, then I would probably get a satisfactory result, but the lifespan and stability of such a strategy would be unacceptable for launching into production.

Now let's look at the results of tests in which Midgamma was used as a filter. The dotted line shows the profitability curve of the strategy without a filter, the black line - with a MidGamma filter. It can be visually seen that the filter was actively working for only a couple of months, from May to July 2020. During this time, it filtered out some of the profitable and unprofitable trades, which in general slightly increased the Sharpe Ratio and did not change the profitability. I believe that in our case, the filter has a negligible effect on the profitability of the algorithm.

Discussions

An attempt to create an algorithm using brainwaves was not a failure. At the current stage, I described the methodology and successfully walked through the entire pipeline of creating a model. However, the model did not show good results on the first attempt. I attribute this to several reasons:

  • 1 subject in the sample was both researcher and subject. In such conditions, it is very difficult to maintain scientific sterility, so further studies will include more subjects with relevant experience.
  • Errors of the measuring device. Most likely, the data from Brainlink Lite came with some errors, which is typical for devices in a simple configuration.

If I expand the sample and pick up a more advanced measuring device, then the data will be purer, and the model will probably turn out better. Most likely, in such a configuration, the approach with the formalization of the chart using derivatives will work.

The curse of many researchers is that if they spend N days on their research and don't come up with conclusions that they are satisfied with, they begin to manipulate the data and add ad-hoc hypotheses that lead science to a dead end. This study could use more parameterization of the model and compress the testing window to generate beautiful conclusions, but this study is only the beginning of a long journey in understanding the brain's ability to trade on the stock exchange. In the following studies, I will try to take into account the current errors and build a model that will slightly open a new class of external data for any type of asset.

If you are interested in this topic, you can connect me via LinkedIn: https://www.linkedin.com/in/sergey-frolov-0a090a179/ .