Synaptic The Peltarion Blog

1Jun/065

Hebbian novelty filters for financial analysis

I have been asked to post a few words about novelty filtering stock market data. This can also of course be applied to any other system, including, but not limited to forex data and other financial time series.

What anti-Hebbian novelty filters can do for you:

  • Detect previously unseen trading patterns
  • Give a quantitative measure of how much this new pattern differs from old trading patterns

What anti-Hebbian novelty filters can't do for you:

  • Predict what consequence (if any) the new trading pattern will have on for instance the stock price
  • Give you the direction of or type of change

So why would you want to use novelty filters if they can't tell you the consequence of the change?

It's simple: You use neural networks and other technology to try to model the market. You don't throw a dice or flip a coin.

When the market exhibits behaviour it hasn't shown earlier and you choose to trade, then you are just picking random actions. All predictive models are based on the assumption that there is an analyzable pattern. You find this pattern by looking at historical data.

If the market is behaving in a way no represented by the historical data, then your model is invalid.

Let's look at a practical example, and I'll then show you how to do it in Synapse.

What we have here is the output of an anti-Hebbian filter (top graph) and the closing price of the Microsoft shares. As you can see, around sample 209-210, the novelty filter detected something was up - three days before the stock went down significantly (on April 27). This would have been a very good signal to get out of the market.

Let's take a closer look on how this is done in Synapse and what it means:

First of all, if you are running 1.0.3.3 you'll need the 1.0.3.4 update. If you haven't updated your Synapse, do so before proceeding. Just starting Synapse with an active internet connection should be enough, the update engine will do the update automatically.

If you wish to download the Synapse solution that produces the result presented above, you can do it here:

msft.xml (Downloads data from finance.yahoo.com and therefore requires an active internet connection)

or

mstf_e.xml (The data is embedded in the solution so you can run it offline).

To see the results, go to training and press "Step Epoch" in the training bar (Play followed by a "pause" will do as well). Don't press the stop button as you will reset the system.

The four plots that you see are (from the top) novelty filter output, MSFT close, SUNW close, AAPL close.

Basic concept

The basic idea is that we take a number of stocks in a related field and take their Open, Close, Volume etc parameters as inputs. This will allow us not only to detect changes in trading behaviour of one particular stock, but changes in trading behaviour relative other similar stocks.

So, for our example we'll use Sun Microsystems (SUNW), Microsoft (MSFT) and Apple (AAPL).

Using stock quotes in Synapse

Getting stock market data into Synapse is simple, you just have to keep a few things in mind.

  1. Use the CSV format to import data.
  2. As the source, enter the URL to the data, for instance of SUNW:http://ichart.finance.yahoo.com/table.csv?
    s=JAVA&a=02&b=20&c=2000&d=04&e=23&f=
    2006&g=d&ignore=.csv

    You can find the syntax on the Yahoo Finance homepage. Or alternatively you can go to the "Historical Prices" page (http://finance.yahoo.com/q/hp?s=SUNW) for the stock you wish and set the date range. On the bottom of the page you can find a link saying "Download to Spreadsheet". Copy that link and paste it into the CSV format wizard.

  3. Set the string variable handling to "Enumerate". This will enumerate dates:

  4. When you select delimieters, make sure that only comma is selected:

When you finish the wizard, there is only one more thing to keep in mind: the data is in reversed order (soonest data first). To fix this, do the following:

  1. Add a Mixer filter and set "Percent" to 0. This will move all the data from the validation channel to the training channel, so that we have the whole time series in one place.
  2. Add a Selector filter. Set the "Sort" field to "Row DESC" (without the quotation marks). This will sort the data by descending row number and thus reversing it.

  3. Add another Mixer filter and set the "Percent" to 15 to move 15% of the data to the validation channel. (This is the data range where it will detect new patterns)

Creating the adaptive system

There are a number of ways to create the novelty filter, but perhaps the most simple is to use one Data Source per stock and connect them through a Merger component. Then just connect the merger to a Hebbian Layer:

The "Step" property on the Hebbian update rule should be set to a small negative value (i.e -0.01 or something similar) to produce the novelty filtering effect. You can play around with that, as the system may converge to different solutions depending on the step.

If you want to visualize the whole thing, you can add plots.

Interpreting the results

All adaptive systems require careful interpretation of the results, but it is especially true for novelty filters, because they only tell you that something has changed - not how or what or what the consequences will be. In many cases complex systems such as stock markets are capable of absorbing large changes.

What the novelty filter does tell you however is that you can't predict what is coming as nothing similar has happened before. If the price goes up or down depends on how sustained the new trading pattern is and of course the nature of any macroeconomic development that might have triggered it. And remember - the price of a stock may change significantly without the novelty filter showing anything - if that type of trading has occured before.

The important thing you get to know that the trade has become unpredictable. How you choose to act upon the information entirely depends on the context.

Finally, let's take a look at the results shown in the plot:

I have marked the five largest spikes from the novelty filter on the plots.

  1. We have a spike at MSFT and approaching a spike at SUNW. Since the novelty filter response is in sync with MSFT, it is likely the cause of that.
  2. No significant consequences. A slight drop in price at SUNW, but hardly dramatic. An excellent example of how a new trading pattern doesn't necessarily mandate a radical cange in closing price.
  3. Also nothing ospiciously correlated to the closing price. Remember that other inputs are used such as volume, open price, high, low.. Any previously unseen combination of those can trigger a novelty filter response.
  4. A very strong spike before the MSFT free-fall. An example of a dramatic consequence of a change in trading patterns.
  5. At any radical change in stock price there is a high probability of new trading patterns emerging. This spike was during the free-fall of MSFT.

As you can see, a change in trading pattern can have a significant impact on the closing price - and in some cases no or little impact. It also varies by stock - MSFT is for instance more sensitive to new trading patterns than AAPL.

Final words

Novelty filters do not predict the closing price. Nor are they entry or exit signals. The thing they do - and they do it well- is to detect new trading patterns which will cause any predictive model to perform no better than random guessing. How you choose to handle the information is entirely dependant upon the context of your trading. If you wish to be on the safe side, you'll exit (or wait to enter) until the market returns to a predictable pattern. In some cases however, it may be worth taking the risk. With an anti-Hebbian novelty filter in your toolbox, you'll at least be aware that you are taking a risk.

Good luck with your trading!

--Pete / Peltarion

Comments (5) Trackbacks (0)
  1. Thx. Just what the doctor ordered.

  2. Could this be used in some way with time-dynamic nets?

    I reckon that considering how the trading unfolds in time could be useful.

  3. Sure, instead of connecting the input directly, pipe it through a Gamma Memory component and you’ll get the temporal information as well.

    Alternatively, you can create a recurrent link from the output to a merger where it joins with the signal from a data source.

    I’d recommend the former though as gamma memories are more flexible in terms of memory depth and resolution than plain feedback loops.

    Including the temporal dynamics can indeed be useful – the only reason why it wasn’t included in the tutorial is because I wanted to keep things simple.

    Pete

  4. Guys,
    You shoudl check out this site… http://ww.stunnets.com... This site claims to predict stock prices using neural network technology!

    cheers!

  5. Hey

    Thanks for this great read, i have bookmarked your site so i can revisted it

    Keep up the good work

    Dirk


Leave a comment


No trackbacks yet.