Saturday, September 16, 2017

Predictions and Suggestions from a machine learning based Algorithmic trading

#MachineLearning #AlgortihmicTrading #StockMarketAutomatedTrading  #LogisticRegression #Boosting

Predictions and Suggestions from a machine learning based Algorithmic trading

An algorithm is a specific set of clearly defined instructions aimed to carry out a task or process.

Algorithmic trading (automated trading, black-box trading, or simply algo-trading) is the process of using computers programmed to follow a defined set of instructions for placing a trade in order to generate profits at a speed and frequency that is impossible for a human trader. The defined sets of rules are based on timing, price, quantity or any mathematical model. Apart from profit opportunities for the trader, algo-trading makes markets more liquid and makes trading more systematic by ruling out emotional human impacts on trading activities.

We can create a Regression formula like below :

The dependent variable is the Return on capital invested and can be run across all stocks.

Error term ei can be boosted using Boosting Algos and thus increasing the prediction accuracy.

Now how to choose your Variables and what can be the ideal STOCK Equation :

YOY Quarterly sales growth  > 15 and
YOY Quarterly profit growth  > 20 and
Net Profit latest quarter  > 1 and
G Factor >= 7 and
Net Profit latest quarter > .33 AND
Other income latest quarter < Net Profit latest quarter * .5 AND
Net Profit preceding year quarter <= 0 AND
Expected quarterly net profit > 0 AND
Sales latest quarter > Sales preceding year quarter   AND
Return on invested capital > 25 and
Earnings yield > 15 and
Book value > 0 AND
Market Capitalization > 15

Graham Number > Current price AND
PB X PE <=22.50 AND
PEG Ratio >0 AND
PEG Ratio <1 .5="" and="" o:p="">
Altman Z Score >=2.5 AND
Sales growth 5Years >25 AND
Profit growth 5Years >15 AND
Current ratio >2 AND
Market Capitalization >250 AND
Sales >100  AND
Piotroski score > 7
Dividend yield > 2 AND
Average 5years dividend > 0 AND
Dividend last year > Average 5years dividend AND
Profit after tax > Net Profit last year * .8 AND
Dividend last year > .35 AND
( Profit growth 3Years > 10 OR
Profit growth 5Years > 10 OR
Profit growth 7Years > 10 ) 
(Market Capitalization > 3000) AND
(Average return on equity 10Years Years > 20) AND
(Debt to equity < 1.5) AND
(Interest Coverage Ratio > 2) AND
( PEG Ratio <= 1) AND
(Profit growth 5Years > 20) 

YOY Quarterly sales growth  > 40 and
YOY Quarterly profit growth  > 40 and
Average return on capital employed 3Years >30 and
Price to Earning <6 o:p="">
Sales growth 10Years > 10 AND
Profit growth 10Years > 12 AND
OPM 10Year > 12 AND
Debt to equity < 0.5 AND
Current ratio > 1.5 AND
Altman Z Score > 3 AND
Average return on equity 10Years > 12 AND
Average return on capital employed 10Years >12 AND
Return on invested capital > 15 AND
Sales last year / Total Capital Employed > 2 AND
Average dividend payout 3years >15

PEG Ratio <1 and="" o:p="">
Sales > 500 AND
Price to Earning < 40 AND
Profit growth > 20 AND
Debt to equity < 0.2 AND
Price to Cash Flow > 5


EPS last year >20 AND
Debt to equity <.1 AND
Average return on capital employed 5Years >35 AND
Market Capitalization >500 AND
OPM 5Year >15

Net Profit latest quarter > Net Profit preceding quarter AND
Net Profit preceding quarter > Net profit 2quarters back AND
Net profit 2quarters back > Net profit 3quarters back


EPS latest quarter > 1.2 * EPS preceding year quarter AND
EPS latest quarter > 0 AND
YOY Quarterly sales growth > 25 AND
EPS last year > EPS preceding year AND
EPS > EPS last year AND
Profit growth 3Years > 25 AND
Return on equity > 17 AND
Down from 52w high < 15 AND
Market Capitalization > 100


Price to Earning >0 and Price to Earning <10 5years="" and="" equity="" growth="" on="" return="">10 and Dividend yield >1 and Return on capital employed >10

Profit growth 5Years > Sales growth 5Years AND
Sales growth 5Years > 3 AND
Return on equity > 15 AND
Working capital 5Years back < 0
Price to Earning >0 and Return on equity 5years growth > 5 and Dividend yield >0  

Note : DEBT reacts inversely to the equation . Term period will be a spread over last 15 to 20 Years. 

Now , applying boosting algorithm ( like XGBoost) you can reduce the error coefficients.

Based on the above equation and a little variation choosing a flattened NN( Neural Network ) below stocks can be looked upon for Indian stock market.






the story of the procession of ants


‘We are waiting for your orders, my Lord’ Vasuki asked looking at the approaching Asura army.
‘Let them come forward. Close...very close’ Shiva replied, looking at the river flowing below. Vasuki presumed looking at the tridents pointing skyward, must have reached the limits of their patience. Scattered stones spanning the river looked like dead soldiers.

Shiva walked up to the edge of the mountain and stooped down. He first looked eastward then westward, and then the river beneath .The river looked beautiful. Shiva watched a column of dark red ants transport mud pebbles across the edge of the mountain. When He laid a clod of earth in their way, they strained to climb over it instead of skirting it. There’s so much to learn from this tiny creature, their fighting spirit, the greatest Lord thought.

Shiva looked back at Vasuki and smiled. ‘Have you heard of the story of the procession of ants?’
‘No my Lord’ Vasuki looked completely perplexed. In this time of great panic and tension, how can the Lord think of a story?
‘It is all in our deeds, my dear friend Vasuki. It is by deeds that one merits happiness or anguish, or becomes a master or a villain. It is by deeds that one attains to the rank of a king or brahmin, or of some god, or of an Indra or a Brahma. And through deeds again, one contracts disease, acquires beauty and deformity, or is reborn in the condition of a monster.
Let me tell you then’...and Lord Shiva started.

‘Once there was a great warrior. After a long and dreadful war he slew the giant Vrtra that had been couching on the mountains in the limbless shape of a cloud serpent, holding the waters of heaven captive in its belly. The warrior flung his weapon, the thunderbolt into the midst of the ungainly coils; the monster shattered like a stack of withered rushes. The waters burst free and streamed in ribbons across the land, to circulate once more through the body of the world.

This flood is the flood of life and belongs to all.
The warrior was Indra, the king of the Gods.

All the divinities of the heavens were acclaiming him their saviour. Greatly elated in his triumph and in the knowledge of his strength, he summoned Vishwakarma, the god of art and craft, and commanded him to erect such a palace as should befit the unequalled splendour of the king of the gods.

The miraculous genius, Vishwakarma, succeeded in constructing in a single year a shining residence, marvellous with palaces and gardens, lakes and towers. But as the work progressed, the demands of Indra became even more exacting and his unfolding visions vaster. He required additional terraces and pavilions, more ponds, groves, and pleasure grounds. Whenever Indra arrived to appraise the work, he developed vision beyond vision of marvels remaining to be contrived.

Finally Vishwakarma brought to despair, realized that he had to do something .When Vishwakarma secretly resorted to the higher throne and presented his case, Brahma comforted the petitioner. “You will soon be relieved of your burden,” he said. “Go home in peace.”
Early next morning a brahmin boy, carrying the staff of a pilgrim, made his appearance at the gate of Indra. The gate-man hurried to the master, and the master hastened to the entrance to welcome in person the auspicious guest. The boy was slender, some ten years old, radiant with the lustre of wisdom.
The boy greeted the host with a gentle glance of his dark and brilliant eyes. The king bowed to the holy child and the boy cheerfully gave his blessing. The two retired to the hall of Indra, where the god ceremoniously welcomed his guest with oblations of honey, milk, and fruits, and then asked about the purpose of the boy's visit.
The beautiful child replied with a voice that was as deep and soft as the slow thundering of auspicious rain clouds. “O King of Gods, I have heard of the mighty palace you are building, and have come to refer to you the questions in my mind. How many years will it require to complete this rich and extensive residence? What further feats of engineering will Vishwakarma be expected to accomplish? O Highest of the Gods,”-the boy's luminous features moved with a gentle, scarcely perceptible smile- “no Indra before you have ever succeeded in completing such a palace as yours is to be.”
Full of the wine of triumph, the king of the gods was entertained by this mere boy's pretension to have the knowledge of Indras earlier than himself. 

With a fatherly smile he put the question. “Tell me, Child! Are they then so very many, the Indras and Vishwakarmas whom you have seen-or at least, whom you have heard of?”
The wonderful guest calmly nodded. “Yes, indeed, many have I seen. I knew your father, Kashyapa, the Old Tortoise Man, lord and progenitor of all the creatures of the earth. And I knew your grandfather, Marichi, Beam of Celestial Light, who was the son of Brahma. Marichi was begotten God Brahma’s pure spirit; his only wealth and glory were his sanctity and devotion. Also, I know Brahma, brought forth by Vishnu from the lotus calyx growing from Vishnu's navel. And Vishnu himself-the Supreme Being, supporting Brahma in his creative endeavour-him too I know.
When Brahma closes his eyes, a world goes out of being. The life of a Brahma is four hundred and thirty-two thousand years. When he dies, the lotus goes back, and another lotus is formed, and another Brahma. Then think of the galaxies beyond galaxies in infinite space, each a lotus with a Brahma sitting on it opening his eyes, closing his eyes. And Indras? There may be wise men in your court who would volunteer to count the drops of water in the oceans of the world or the grains of sand on the beaches, but no one would count those Brahmas, let alone those Indras.”
While the boy was talking, an army of ants had emerged in the hall and paraded across the floor in military style. The boy laughed when he saw them, and Indra's hairs stood on end, “Why do you laugh?”, stammered Indra,
“who are you? why you know so much? What are these ants doing here?"
“The truth hurts.” answered the boy, “Don't ask unless you really want to know.”