Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
collab/help request - learning portfolio investment strategy

Hi guys,
Im new here. I am a complete python newbie, being raised on matlab in academia (originally a fluid dynamics orientated engineer).

Im looking to implement the algo in this technical paper:

http://papers.ssrn.com/sol3/papers.cfm?abstract_id=1509811

I've got someway in matlab, but found this and realised it would probably by much more robust to test with this platform, plus iv wanted to learn another language for a while, and I learn v. quickly by immersing myself in a complex problem.

Being matlab and (to some extent) c++ literate, I'm picking this up semi quickly, although what i have so far is based on modifying some other code that seemed to hold the bare bones of what i wanted. I havent got the algo down 100% yet, although its all in my head (at least i think so).

No idea how people collab on here, but I have implemented up to the max eigenvalue function in python (although this probably needs checking by a more experienced eye.)

5 responses

Hello Chris,

Unless you need to keep your algorithm private (since you are basing it on a published paper, perhaps not), just post to the forum. Have you been able to get the max eigenvalue function to execute in the backtester?

Grant

Obviously its not finished yet, but it calculates the maximum eigenvalue for the xcor matrix.
Im not very far, I only started on it this afternoon, the final stage of the eigenvalue evaluation is to determine percentiles of the past values and compare the recent one with the 35% and 77% values.

Credit to the principal component analysis file which had a good few of the components already implemented.

The only step i am not sure about is the f), which im fairly sure means the weighted av portfolio return given by kv, but not 100%.Im happy to flesh out the steps to the algo if it would be simpler for people (it defo took me a few hours to fully understand this method).

Good! Got it up and running at least. No time now, but looks interesting. --Grant

Fluid dynamics background eh? I'm curious what you think about this master's thesis work:
http://personal.lut.fi/wiki/lib/exe/fetch.php/en/technomathematics/time_series_research/applying_fluid_mechanics_and_kalman_filtering_to_forecasting_electricity_spot_prices.pdf
Ms.Shcherbacheva uses EnKF framework and concepts in fluid dynamics to model (and predict) electricity spot prices in the Nord Pool spot market.

Stanley, Ill have a more thorough read of that when I have a minute, but in general I think the analogy is a good one. I have never really investigated it but sat here now i can think of at least two equations we could take and directly apply.
The continuity equation states (in broad terms, for an incompressible fluid) the rate of flow into a control volume must be equal to the rate of flow out of it. If we take the flow as cash, its still valid - the amount of money into a security (assuming its not an ipo) must be equal to the flow out - if one person sells, they can be seen as removing their cash from the pool of that security, whilst the matching buyer will input the same amount.

equally, im sure we could define something in terms of the energy equation (bernoullis). This just states the total energy of a system is constant, barring losses which are normally negligable, energy simply changes between kinetic, pressure and gpe. If we consider the flow of cash as kinetic, we can say the total 'cash-energy' of a share would be the sum of the amount of cash flow, the pressure may be considered as something like those who are not physically transferring cash, but who affect the market, so maybe those with limit orders, and the gpe could be seen as sentiment. So if there exists a large number of limit orders to buy (signed negative to make the maths work), and no change in consumer sentiment, one would expect an increase in cash flow to compensate, with the price of the security being a function of the flow rate. This also gives the intuitive relationship that pressure and flow are related - just like in a fluid.

This is just me thinking outloud though, ill have a more detailed look into this - interesting