*Numpy Strategies 0.0.8*

Entropy is a measure of uncertainty and therefore risk. So I attempted to replace the variance of stock returns in the CAPM with entropy. I also tried to save some pennies by “shooting” below the open price on entry. This makes the strategy more selective, because of the possibility that we shoot too low.

## Numpy 2 portfolio closed

After six weeks the Numpy 2 portfolio was closed. The expectation was that it would do better than the Numpy 1 portfolio, but it seems that the performance is similar.

## Stops update

It was a good week for the Numpy 4 portfolio. Still a few positions had to be closed.

The Numpy 5 portfolio had some startup issues, and this week was also pretty bad.

## CAPM and entropy

Entropy is a measure of uncertainty and therefore risk. So I attempted to replace the variance of stock returns in the CAPM with entropy. On the “y” axis I put sequentially the volume weighted average return, skewness of returns and Jarque-Bera pval.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | ... ev = average(returns, weights=v[:len(returns) ]) p,bins = histogram(returns,sqrt(len(returns)),range=(min(returns), max(returns)), normed=True) entropy = 0 for pi in p: if pi > 0: entropy += pi * log(pi) evs.append( ev ) entropies.append( entropy ) S = stats.skew( returns ) skews.append( S ) jb = jb_pval( returns ) jbs.append(jb) t = file.replace('.csv', ''), ev, entropy, S, jb records.append( t ) ( a,b,residuals ) = fitline( entropies, evs ) ( aSkew, bSkew, residuals ) = fitline( entropies, skews ) ( aJb, bJb, residuals ) = fitline( entropies, jbs ) for t in records: symbol, evC, entropy, S, jb = t if evC > a * entropy + b: if S > aSkew * entropy + bSkew: if jb > aJb * entropy +bJb: ... |

## Target practice

In order to save some pennies I try shooting below the open price on entry. It’s not much, but it adds up in the long run. It might even be enough to compensate for the transaction costs. This makes the strategy more selective, because of the possibility that we shoot too low. The algorithm requires knowing the open price on the trading day. From this a “low” price is extrapolated using statistical analysis of historical data. The target that we try to hit is the range open to low not including the open price itself. For each security I build up a list of “open low returns”. Then I calculate for each percentile of the returns, what the probability is, to hit the target.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | ... r = (o[:-3] - l[:-3])/l[:-3] ... for i in range(1,100): score = stats.scoreatpercentile(r, float(i) ) p = o[-2]/(1 + score) if not isnan(score): means[i] += score if p >= l[-2] and p < o[-2]: ratios[i] += 1 ... |

Below you can see plots for my historical data.

And here are the entries with the CAPM entropy strategy and the shooting method.

## A Cardassian portfolio

Gul Voldemordor was the commander of the largest Bajoran workcamp. Before that he was in the Obsidian Order, in charge of gathering information about subversive elements. The Order was one of the best intelligence organizations in the known universe. Some observers said that the average Cardassian could not have a meal without the Order knowing the contents of it.

Obsidians were famous for having a plan within a plan within a plan leading to a trap. The Gul was no exception. He was a very good Kotra player. Another thing he liked was checklists. Voldemordor had a checklist for every occasion.

One day, the camp commander drank a mug of hot fish juice with his breakfast of hardboiled tasper eggs and read his morning checklist:

- Punish the Bajorans who underperformed.
- Supervise the workers who were building barracks for new arrivals.
- Invest the camp funds.

Item 1 appeared regularly on his checklist. It was as if the filthy, lazy Bajorans were trying to sabotage the mining operation. Voldemordor had tried beatings, different forms of torture and cutting off body parts, but nothing seemed to help. As last resort he considered executing some Bajorans to set an example, although he found that a very counterproductive measure.

Item 2 was a recurring theme as well. That was not a problem at all. As a matter of fact the commander welcomed any additions to the workforce. There were concerns raised by some potential Bajoran lovers, but that was all rubbish. The Bajorans were breeding like there was no tomorrow. For every Bajoran sent to the mining planets, ten new Bajorans were born.

Item 3 was his very private thing, that he tried to keep secret. The matter was that business was going rather well. Despite the constant Bajoran sabotage, the sheer number of laborers assured a steady and ever increasing income for the camp. Voldemordor preferred that Central Command did not know this. He cooked the books and reported severe production problems and high operational costs. Of course, he was being watched – primarily by Mineher, the officer in charge of the financial administration department. The Gul had this officer poisoned and then blamed it afterwards on the Bajorans. Three of the Bajoran cooks were shot on the spot.

The Cardassian decided to invest the excess camp income. If the profit was substantial, he would keep it for himself, otherwise he would report it to Central Command. In the latter case it was bound to be interpreted as a sign of his brilliant leadership. The long anticipated promotion would then become a reality. However in the event that there was not enough profit to report – he would just spend the money on a crate of the finest Kanar in the district.

The Gul heard from his finance officer about a dissident on ancient Earth, who had some interesting investment strategies. One of the strategies involved shooting. This appealed to Voldemordor as a military man. Before ordering Mineher to be killed, the commander asked Mineher to help him compose the Numpy 8 portfolio. A purely hypothetical portfolio, of course.

Gul Voldemordor made a new checklist and filed it to be read six weeks into the future:

- Sell the stocks on the Numpy 8 portfolio.
- Decide what to do with the profit.
- Appoint a new, more cooperative financial administration officer.

THE END

## Random links of interest

If you liked this post and are interested in NumPy check out NumPy Beginner’s Guide by yours truly.