Friday, 17 November 2017

Machine Learning – A Simple Example for Stock Market Prediction

Machine Learning (ML) is an application or methodology to analyse input data and then predict an output value using statistical analysis.  It is getting popular in finance and the investing industry.  The basic idea of ML in investing is feeding all available data to a computer and let the algorithm learn the relationship between the data and stock price movement.

Traditionally, finance and economics data have been analysed statistically to find their relationships with KLCI.  Recently, all other variables which are indirectly or not related to KLCI such as weather, traffic conditions, concert ticket sales, celebrity news and others, have been included in the ML algorithm.

Let’s do a simple experiment, using Google Trend data to predict Kuala Lumpur Composite Index (KLCI).  Three search-terms – “Malaysia”, “1MDB”, and “KLCI” were selected.  The popularity of each search-term over time were plotted together with KLCI.  Chart 1 is search-term “Malaysia” and KLCI; Chart 2 is search-term “1MDB” and KLCI; while Chart 3 is search-term “KLCI” and KLCI.





Based on a cursory inspection, Charts 1 and 2 do not reveal any strong relationship between search-term and KLCI movement.  Although there was a sharp drop in KLCI when the popularity of “1MDB” surged in Aug 2015, the subsequent surge did not move KLCI drastically.  Chart 3, on the other hand, is more interesting as each time the popularity of search-term “KLCI” peaked, the KLCI tend to reverse its downtrend movement.

Next, these data were then analysed using basic machine learning algorithm.  Generally, there are two main types of machine learning used in quantitative finance – Regression, and Classification.  For simplicity purpose, Classification method is chosen for this analysis (Read more here).

The KLCI data was transformed into “Up”, “Down”, “Flat”, and “Dunno” by calculating the weekly closing price changes.  Example, if week 2 closing price is higher than week 1 closing price, week 2 will be classified as “Up”.  The “Down”, and “Flat” were calculated similarly.  Additionally, the “Dunno” category was introduced to eliminate noises for the region where no high search popularity occurred.

A time lag effect was also introduced into the model to “predict” whether KLCI will be “Up”, “Down”, “Flat”, or “Dunno” in the coming week.  As such, current week search-term results will affect following week’s KLCI behaviour.

Several algorithms were tested and k-nearest neighbours (KNN) algorithm was chosen as the accuracy is the highest amongst others.  See Pictures 1 and 2 for details.

Picture 1.

Picture 2.


Now, let’s run a hypothetical test case to predict KLCI movement.  In Test case 1, assuming the search-term popularity for “Malaysia”, “1MDB”, and “KLCI” are 2, 1, and 25 respectively.  This means “Malaysia” and “1MDB” search traffics are almost flat but “KLCI” search traffic increased by 25%.  The KNN algorithm predicted the KLCI will go down in the following week.  In Test case 5, both “Malaysia and “1MDB” are almost flat but “KLCI” retreated from a high peak.  The KNN algorithm predicated the KLCI will go up in the coming week.  The machine learning algorithm is giving similar results as eye-balling observation.  Table 1 shows KLCI movement predicted by KNN algorithm based on various test cases.



Above is just an illustrative example of how Google Trend and machine learning algorithm works.  Actual algorithm trading requires more intensive research and data processing effort! 

Friday, 10 November 2017

Cryptocurrency: 21st Century Bane or Boon?

Satoshi Nakamoto, inventor of Bitcoin, never intended to invent a currency. It was a “peer to peer electronic cash system”. The key part was that he found a way to build a decentralized cash system with every peer in the network having a list of all transactions.

A simple definition would be “limited entries in a database no one can change without fulfilling specific conditions”.

 Source: Blockgeeks

The transaction is known immediately by the whole network and gets confirmed after a specific amount of time. It can’t be reversed and is not forgeable. It is part of an immutable record of historical transactions – the so-called block chain.

Crytocurrencies are built on cryptography. They are not secured by people or by trust but by math. We could describe properties of crytocurrencies into transactional and monetary properties.

Transactional properties will include: irreversible; pseudonymous; fast and global; secure; permissionless.

Source: Blockgeeks

Monetary properties will be controlled by supply and no debt but bearer – it’s a system of IOUs.

It is revolutionary in impact. It is an attack on banks and governments over monetary transactions of their citizens. It is an attack on the scope of monetary policy – i.e. central banks control of inflation or deflation is now irrelevant. Cryptocurrencies are changing the world. Step by step. We can either standby on the sidelines and observe it or become part of history in the making.

Notes:  There is a follow up on previous article "India’s GST of 28%:  Is This A Valid Benchmark?".  Please go to this link (Read more here) for the update. 

Friday, 3 November 2017

War and Capital Markets!

We often read headlines relating stock market declines with regional military tensions.  On 28 Aug 2017, North Korea fired a missile that flew over Japan before falling into the Pacific Ocean, which triggered a regional market sell-off where Asian, European and American markets all opened sharply lower, shed 1% roughly.

Mark Ambruster, CFA, published an article in Enterprising Investor (Read more here), examining the capital market performance during times of war.  His data shows that war does not necessarily imply lacklustre returns for US stocks.  Quite the contrary, stocks have outperformed their long-term averages during wars.  Bonds, which are deemed safe harbour during tumultuous times perform below historical averages during periods of wars  See below table for details.



He is in the opinion that the future direction of capital market is dependent on economic growth, earnings, valuation, interest rates, inflation, and a host of other factors; history suggests that any market decline due to war should be short-lived.



Friday, 27 October 2017

India’s GST of 28%: Is This A Valid Benchmark?

The concept of goods and services tax (“GST”) is not new to the world. About 160 countries have opted to adopt GST as a tax mode. France was the first country to introduce this tax regime in 1954. Some others have dual-GST model, like Brazil and Canada – a structure where both Federal and State have powers to levy and collect taxes. India’s GST is essentially under five brackets: 0%, 5%, 12%, 18% and 28%. Its top bracket (of 28%) is the highest rate and exceeds that of Argentina (27%). On average, it is around 18%. More developed economies have rates set between 19-20%, which they use to support social services and benefits.


In India, majority of tax revenues is indirect. Less than 3% pay income tax. In 2016/17, direct taxes was Rs 8.47 trillion while indirect taxes constituted Rs 8.63 trillion.

The problem of GST worldwide is that it is regressive in nature – the lower income bears a higher tax burden than the higher income. The other problem is that it leads to a growing shadow economy and their structures:


(Source: https://www.valueresearchonline.com)

Germany has a shadow economy of about 15% per cent of the real economy for decades.

To evaluate GST’s performance, we should examine five indicators (implications):

·       Consumption (whether consumption is reduced which impacts GDP);
·       Production (should be neutral);
·       Inflationary pressures (could increase cost of living);
·       Compliances (creating a “Big Brother” society?  Oversight/ surveillance which impacts business sentiment); and
·       Tax buoyancy (whether tax revenues increase in the medium to long-term)


The performance of a Government has to be measured by the above indicators and not just whether it is 28% or 6%.

Update (8-Nov-2017):

Recently a friend had the following questions on impact of GST in Malaysia (27 Oct 2017).

“How does Malaysia measure up on the five criteria – consumption, production, inflation, compliances and tax buoyancy?”

Positive effects
Neutral
Perceived Negative Impact
1. Compliances
-Strong effort on enforcement

1. Production
-A slight drop perceived due to consumption decline
1. Inflation
-higher at 4% or more
2. Tax buoyancy
-collected over RM42b in 2016 compared to RM18b under SST

2. Consumption
-dropped significantly with increase in prices – effect of which include closure of
Giant outlets and others


From a Government perspective therefore, the tax is useful and increased Government revenue substantially in the immediate term. From a consumer and retail perspective it has negatively impacted disposable income and turnover of retailers respectively. From the producers’ point of view, it is somewhat neutral to negative as lower consumption impacts production but hopefully this remains a short-term phenomenon.

Friday, 20 October 2017

Detecting Potential Financial Manipulation

In fundamental analysis, besides looking for the potential earnings growth of a company, one has to ensure that the company’s financial position is healthy.  However, analysing a company’s financial statement is not an easy task; one has to go through many annual reports, read the notes and understand the details of each entry in the financial statement.  Often, the process is time consuming.

In 1999, Dr. Messod Beneish, an accounting professor at Indiana University’s Kelly School of Business published a research paper called “The Detection of Earning Manipulation”.     He introduced a simple analysis method, the Beneish M Score, to detect potential financial manipulation by using information that is readily available in the financial statement.

The Beneish M Score is calculated using eight financial ratios with different weightage.

M-Score= -4.840 + 0.920DSRI + 0.528GMI + 0.404AQI + 0.892SGI + 0.115 DEPI - 0.172SGAI + 4.697TATA - 0.327LVGI

where,

       DSRI            =          Days Sales Receivables Index
       GMI             =          Gross Margin Index
       AQI              =          Asset Quality Index
       SGI              =          Sales Growth Index
       DEPI            =          Depreciation Index
       SGAI            =          Sales, General, Administrative Expenses Index
       TATA           =          Total Accruals to Total Assets
       LVGI            =          Leverage Index

For M-Score that is smaller than -1.78 (more negative) is classified as non-manipulator.  Whereas for M-Score that is larger than -1.78 (moving towards zero or positive) is classified as a possible manipulation.

The table below, shows the M-Score for various companies in Malaysia.

Company
Beneish M-Score
2016
2015
Benchmark
PETRONAS
-2.713
-2.791
Normal < -1.78 < Cautious
TNB
-2.814
-2.587
Normal < -1.78 < Cautious
SIME DARBY
-2.649
-2.364
Normal < -1.78 < Cautious
FGV
-2.624
-1.778
Normal < -1.78 < Cautious


All the companies in the table showed to be normal under the M-Score test except for FGV in 2015.  But in 2016, FGV reverted to normal.  Perhaps, a more detailed analysis of FGV’s financial statement may be required.

Friday, 13 October 2017

What’s My Budget for 2018?

At a pre-Halloween party, I was appointed the shadow Minister of Finance for a “virtual” nation. My job entails how to address the following:

·       Exchange rate depreciation;
·       Rising inflation for daily goods/services;
·       High fiscal debt;
·       High household debt;
·       Greater transparency and accountability;
·       Income inequality @ 0.40% Gini coefficient;
·       Enforcement of policies/laws;
·       Reducing corruption and enhancing integrity;
·       Providing unemployed graduates with jobs;
·       Reduce cost of doing business;
·       Getting value for investments in education;
·       Mounting health cost and surplus of medical professionals; and
·       Increasing productivity of civil service and private sector

These are some of the main concerns, amongst others.

As a technocrat, my new appointment makes life difficult because of competing forces in the political maelstrom! Be that as it may, I am determined to lay down my best for the “virtual” nation.

Many are troubled by exchange rate fluctuations. As an immediate step, the Overnight Policy Rate is raised by 1.0% to improve the exchange rate.  We need to reward savers as much as investors. There will be an outcry by those in business who see this as a cost increase which may impact GDP growth. We will take that challenge. Imported inflation is reduced, currency is better reflective of our standing, and people have confidence going forward. Creeping deprecation is like being in a haunted house with “creepy” ghosts.

For 2018 and 2019, we are reducing GST to 3%. Thereafter, we will re-examine consumption, inflation and tax buoyancy. This will stimulate growth, increase consumption and reduce inflationary pressures.

Our fiscal debt which is high, will first rise to 60% of GDP before reducing to a manageable 40% by 2020 and beyond. Legislative exemption will be sought for the increase. An additional 5% or $50 billion will be injected into the economy as a stimulus to build new district hospitals, TVETs (in education) and social services. Graduates in medical, education, social sciences are to be engaged for better services to the rakyat.

Our students in public universities will have their tuition fees waived for their respective courses. This is an investment in the country’s long-term future.

Household debts and the broad property sector have been a “drag” on the economy. I propose that both these areas are centralised under a new agency with the Central Bank as the custodian. Commercial banks have to “sell” to this agency their portfolios in the broad property sector to generate liquidity and lend fresh money for affordable housing. Each state will establish new housing development agencies for the middle and lower income strata. Affordable house cost will not exceed six times the average earnings of a household.

Private sector remuneration at the top end will not exceed 20 times that of the lowest employee in an organisation. The “excess” wage will be taxed at a higher rate of 30%. Inequalities have to be addressed if societies are not destabilised. With many large corporations having pre-tax profits in excess of $1 billion, it may be timely for wages of the lower level employees be raised. Tax rate will be reduced to 20% for those companies improving salary scales in excess of 10% but below 15% for 2018.

A new Corruption and Reconciliation Commission is proposed to provide an avenue for those involved in such practices. This Commission is to function for a period of three years, after which it will focus on integrity in private and public sectors.

Graduate unemployment has to be tackled at source. In the short term, a period of internship with companies is proposed. These companies will receive double tax relief for every graduate employed from the registered pool of unemployed graduates. Job centres/placement centres are to be established in every major city. In the longer term, graduate intake at university level must reflect demand conditions in the economy. A major review of courses will be implemented at university and college levels. Schools will be permitted to use English as a medium of instruction from Form 3. This is an option and will improve marketability of graduates.

To enhance productivity and provide innovation, an R&D Fund of $10 billion for application research is to be established.


To drive down health costs, generic drugs and production of the same will be encouraged. In the short-term, import of these drugs will be tax free (including GST). This will hopefully bring down costs. For the ageing population (above 65), all medical costs are borne by the Government. Purchase of medical devices such as walkers, wheelchairs, beds for assisted living are reimbursed on a one-time basis for each senior citizen.

To help reduce global greenhouse effect, we will refocus our energy sources to renewables. A special renewable fund scheme will be announced shortly to increase usage of solar and other sources of renewable energy. All gasoline driven cars will be banned in 2035 to reduce pollution in cities. Subsidies will be introduced for electric and hybrid vehicles.

Growth is driven by the private sector, and to enhance their ability to move forward, a structure similar to that at Central level is to be instituted at each state. The Government’s job is to facilitate. And this has to be in an efficient manner.

Our focus for 2018 and beyond is GDP growth of 6% and above. This together with an enhanced quality of life for the ordinary person. It is a right for everyone to own a home, a car and a business or have a stable income stream. We want this “virtual” nation to live up to its name, and truly reflect unity in diversity.

Finally, this is not a trick or treat event!

(The above is a figment of unbridled imagination (or the lack of it) of the writer. It does not represent any nation in the past, present or future).



Friday, 6 October 2017

Stock Market Crash Indicator



From Tulip Mania (1637) to the Subprime Crisis (2008), each market crash has cost investors a huge fortune.  Inevitably, it also has led to a period of economic recession/ depression.  There are many theories that attempt to explain the causes of the crash but not many could predict the crash ex-ante timely.

Didier Sornette, Professor of the Chair of Entrepreneurial Risks, also a Physicist and an Earth Scientist at the Swiss Federal Institute of Technology Zurich (ETH Zurich), has combined economic theory, behavioural finance and earth science physics, to create a model in predicting financial bubbles, namely log-periodic power law singularity (LPPLS).

The LPPLS model successfully predicted the 2008 Oil Bubble (Read more here), 2015 Shanghai Stock Market Crash (Read more here) and 2016 minor Bond Market Crash.  According to his September 2017 report (Read more here), there is a growing risk of fixed income bubble whereas the chances of an equity market crash is easing somewhat(See below chart).  However, the September report only covered up to August data, thus it did not factor in the September rally where S&P 500 surpassed 2500 level.





We love to wait for his October report to see where the equity market is heading!