HOME
Stock Analyzer

BACKGROUND

A.I. and money, I'm a fan of both and this project got them all.

For many hardworking families, the family home is the single largest investment they own. It is a good idea to diversify the investment and investing in stock market is a good way of doing this.

The aim of the project is to give a shot at stock market analysis using a combination of Kelly Criterion and NN. Hopefully it will be able to help me and others to formulate good stock investment strategies.

This project is still work in progress and I'm learning a lot from it. Like Benjamin Franklin once said, "An investment in knowledge pays the best interest."


IMPLEMENTATION

Kelly criterion is a math formula which calculates the optimal percentage to invest in order to maximize the return when given the probability of winning and the win-loss ratio. Below is the formula in its simplified form:

k = (p * b - (1 - p)) / b
k is the percentage to invest.
p is the probability to win.
b is the win-loss ratio

My current approach for calculating k or KI (Kelly Index) of a specific stock is to break up its historical data into multiple trading periods. The average gain and the overall chance of gaining money are then calculated for all trading periods.

For example, the KI used in the next section is calculated by taking the historical data from the first half of 2019 for NZX and ASX and break them up into 7-day trading periods. For each stock the average win-loss ratio after each 7-day period and the probability of winning are calculated. These values are then used to calculate the stock's KI using the formula above.

Stocks are sorted by their KI by default in the next section. Higher KI indicates better performance.

The next step is to let the users add their favourite stocks to watchlist, then formulate investment strategy for the watched stocks and run simulations for the investment strategy to see how it performs.


STOCKS ANALYZER

Disclaimer: all NZX and ASX stock data on this page are provided "as is".

Add your favourite stocks to watchlist by clicking on the eye icon on the top right corner of the stock chart. Click on the Investment Strategy & Simulation button to let the AI generates the recommended investment strategy for the watched stocks and run simulations to test out the strategy.

Market:       
Chart duration:       
Sort by:       
 Watchlist only



Investment Strategy & Simulation...(TODO)



TECHNICAL DETAILS

The stock data are stored in Microsoft Azure SQL. I was going to use the SQL Express on one of my existing cloud VMs but then decided to stop being so cheap. The Basic 5 DTUs configuration which I'm using for this only costs around $8 per month. A lot cheaper than starting another VM for database. Maybe its time to unsub my Netflix :)

The server side uses ASP.NET Core 3.1. Entity Framework Core was initially chosen as the ORM. I have been using FluentNhibernate at work and only used EF briefly when it just came out. The experience with EF has been good so far. I was able to get everything running quickly thanks to the reverse engineering tool which saved me hours of pain to work out the mappings.

Later on I swapped out EF entirely with Dapper, a light-weight ORM made and used by Stack Overflow. The main reason for this is to improvement query performance and significantly reduce the amount code on the server side. I was able to get rid of all my DB classes from EF and simply returns dynamic from the REST API. The trade off is to have to deal with SQL queries directly which shouldn't be an issue for most developers.

The main components used on the client side are jQuery and Google Chart. Google Chart is used simply because it is free and extremely easy to setup. IMO it is one of the best free client side chart library out there. My main complain is its poor performance on mobile devices. But this is probably the case with most other client side chart libraries as well.


YOUR FEEDBACK

As always, I'd love your feedback. Send me an email or leave me a message on LinkedIn or Blogger.