Thursday, 6 August 2015

Systems building - accounting

If you tell someone you're trading, the first thing they'll usually ask is "Have you made any money?"

It isn't usually this easy to tell if a trader has made money or not

Most traders I've known are pretty obsessed with that question as well. Knowing the answer to that query isn't as important as you might think, since it's better to be focused on process than outcome, although I must admit I do check my own profit more often than I need to.

As a well known expert on risk and gambling said "You never count your money, When you're sittin' at the table, There'll be time enough for counting, When the dealin's done".

Nevertheless it's necessary to have some idea of your profitability for a number of reasons. In this post I'll explain how I do it. This is the fifth post in a series giving pointers on the nuts and bolts of building systematic trading systems.


Why do we need to know p&l?


Apart from being able to answer questions from nosy people at dinner parties, why do you need to know your profit and loss? I can think of a few reasons, in reverse order of importance:

  • To evaluate whether your trading is successful
  • To decompose your performance, eg by instrument or trading rule
  • For professional money managers: to tell clients and calculate fees
  • For amateurs and onshore managers: To work out taxes due
  • To evaluate whether your trading performance matches a simulation / back test
  • To check if trading costs (commissions, fees, taxes and slippage) are as expected
  • To check if your realised risk is as expected
  • To scale your risk in proportion to your overall capital (as per the Kelly criteria)
Some of these are important, others meaningless data. For a start; almost nobody* has a track record long enough to say in a statistically meaningful way whether they are a successful trader or not.

* Yeah Rob, I hear you cry, but what about Buffet / Soros / .... insert name of manager here. Well there are probably at least 100,000 people globally professionally managing money, and millions if not tens of millions of people trading on a semi-serious basis, plus at least a hundred million who actively invest their own money. At best a few dozen of these people have a multi decade track record. That is a very small percentage of the total indeed. I'm sticking to "almost nobody".
 

A meaningless statistical outlier


 Similarly, although performance decomposition is interesting, and clients often care about it, what exactly do you do with that information? Again it's incredibly rare that you'll have enough data to draw any statistically interesting and useful conclusions like "Looks like I should trade more S&P500 and less NASDAQ".

Calculating fees and taxes, and reporting to clients, is just stuff you have to do.  Let's file that into the 'useful and 'uninteresting' bucket.

Checking realised performance versus a backtest is a more valid exercise, and many hundreds of man hours are spent annually at all systematic quant funds doing this, since if you can't realise your backtested performance you have a problem.

However it is important to look at the components of where your performance is coming from, and not just the bottom line figure. For this reason you should first focus on process not outcomes; check to see if the trades you did were in line with what your simulation did. Then check to see if the prices were in line. Finally check to see if the fills you get were what the simulation expected (see the next point).

So the last three reasons in the list above are the ones I am personally most interested in.  Firstly I'm obsessed with trading costs (as I think I've mentioned in this blog before).

Secondly every profit or loss number you get is effectively realised risk; it's a single draw from a hidden, every changing, latent distribution of possible returns.

Drawing from a binary distribution of returns

Modelling that distribution, and sizing your positions to it, is at the core of investing and trading correctly. You need to check how good your model estimate are. I monitor both the total, and by instrument, realised versus expected risk.

Thirdly if you lose 1% of your bankroll, then you should cut your risk by 1%. No exceptions. I call this process volatility targeting. To do that of course you need to know how thick your bankroll currently is. Most collective funds do that kind of resizing on a weekly, monthly or quarterly basis depending on their liquidity, to account for new money and redemptions.

With a higher risk target you need to do it more frequently; since there is more chance of your bankroll moving by more between checks (eg with an annualised risk target of 50% a two sigma daily move would change your bankroll by 6.25%; worth making an adjustment for). I do it hourly, which is possibly excessive, but I'm terrified of possible black swans.

Notice that for costs and realised risks it isn't really necessary to check profits daily (or hour by hour.... or worse....), except to check for extremes. The normal daily information you get on these is basically just noise from which you can't draw too many conclusions.

So I do look at my trading costs daily to check for really bad fills that might indicate a problem with my execution algo; otherwise a review every few weeks is fine. Similarly if you got a six sigma daily return (plus or minus) there might be something seriously wrong with the way you are estimating / forecasting your expected risk (or it could just be one of those genuine six sigma events that happen every 4 million years couple of years).


What makes up p&l


It's worth understanding what the various components of p&l are. This will be a very brief discussion; anyone serious about trading using any kind of leverage should have a good understanding about basic accounting*.

* This would also be a help if you were trading an equity value strategy. Or, you know, running a hedge fund business.

P&L is essentially the change in your account value. An important point: when thinking about measuring account value for volatility targeting purposes we need to include withdrawals (to pay taxes, fees or living costs) and additions of new money. However when working out profitability for other reasons these need to be factored out (withdrawing £10K from your account doesn't mean you've lost money).


We also have the split between realised and unrealised p&l. The former is what we've already made trading on closed positions. The latter is essentially the mark to market. There is a similar split between cash and accruals for things like interest, bond coupon payments, and equity dividends. Commissions and data fees are usually paid spot and don't accrue.

For realised p&l as well as subtracting commissions paid we should separate out what we sold something for into what we could have sold it for at the mid price, versus what we actually got (which is the execution cost or slippage).

For overseas cash items (as distinguished from derivatives, eg US stocks if you're a UK investor) p&l can come from both changes in price, and changes in the exchange rate.

Even cash itself has p&l; my account is denominated in GBP but I have to hold, or borrow, cash for margin purposes. The value of this cash will change as exchange rates move.

It's important to understand these differences, because different measures of p&l which we'll discuss below encompass various combinations of the above items - none gives a complete picture.


Where can you get p&l from?


How do you actually know if you've made money or not? Here are some places where I get my p&l data from (the examples in this list are specific to my broker interactive brokers; but should hopefully cover what other brokers with trading API's offer).

  • From your broker, total value of your account  (IB net liquidation value received from updateAccountValue. If you don't know how to get this see the relevant post from my IB API how to series)
  • From your broker, the portfolio value of each position held (the realisedPNL and unrealisedPNL values return by IB function updatePortfolio)
  • From your broker, the value of other items: cash and accruals held (values returned by IB function accountSummary)
  • From your broker, a record of trades done including commissions and taxes paid (Can't be accessed via the IB API - except for todays trades - but you can use my python code to analyse IB reports)
  • From my own database records, a history of trades done including the expected execution slippage (half the spread) and what I actually paid
  • From my own database records, a history of price movements (note I get these prices from IB, but in principal they could come from another provider as a cross check)
  • From my own database records, an hourly estimate of p&l for each instrument, from trading and mark to market movements
This might seem overkill, but each of this sources is slightly different. No individual source gives you the complete picture, and it's also useful to be able to compare different sources.

I use the total value to work out my capital for volatility scaling. Note that if I withdraw cash from my account I ought to include this change in my calculation of capital at risk. However the way I run my account is to have substantially more than the 'capital at risk' in the account, and then to make periodic withdrawals of cash. This means I need to make manual tweaks if I withdraw money, otherwise the system thinks I must have lost money when all I've done is taken some out.

I also use total value as my 'gold standard' for total profits, because it includes all the elements of profitability including accruals, fees and so on. This is what I look at for a headline check on realised risk.

In my regular p&l reports (of which more later) I do report on profit by position from the changes in portfolio value. This however is only accurate if you haven't done any trading in the reporting period. So it's just a secondary source, used for checking purposes.

I don't use other items in an automated way, but if you look at my annual report on performance you can see I use them there. The brokers record of trades is what I use for calculating my tax records, but as I can't get it an automated way I don't use it for any other purpose. I do analyse it though to extract the commissions I am paying on each instrument.

My own history of trades is used heavily; I report on it daily, regularly analyse the execution costs I am paying (remember it's vital to know about costs), and it's also used to create my hourly estimate of p&l.

By using the history of trades, and history of price movements, I can reconstruct a historical estimate of what my p&l should have been in the past (as you'll see below I call this my 'retro' estimate). This is another secondary source of individual instrument p&l.

My 'gold standard' of p&l for individual instrument positions is based on my hourly estimate. Every hour I get the most recent price from my history, and combine that with any traded prices, to work out what the p&l has been since the report was last run. This is then saved into a database. I call this my 'current' estimate. This is what I use to check profits as realised risk for each position.

Even then they are calculating the same thing these methods will all give slightly different answers (due to using prices captured at different times), so it's worth having multiple sources for comparision. Over periods of more than a few days the 'current' and 'retro' methods give very similar results. The 'portfolio value' method is only useful for short periods (so it won't show any profits on a position you no longer hold for example).


Reporting on p&l data


I run three regular kinds of reports which use p&l data. Remember in my opinion the three main uses of this data are:

  • To check if trading costs are as expected
  • To check if your realised risk is as expected
  • To scale your risk in proportion to your overall capital (volatility targeting)
Less important, but it's only human nature to think about them are:
  • To evaluate whether your trading is successful
(For taxation purposes I also run an annual process, but that is documented here. I also periodically look at the decomposition of my trading profits, eg here.).

For costs I run a report every day which lists all my trades (based on my own records) and identifies the costs of each. If I see a large cost (positive or negative) I will check my logs and diagnostics. I also run a report every couple of weeks, and semi regularly but at least annually, just to check that my total costs are coming in under expectations (for both the total and the individual components, eg commissions and execution slippage).

I run a daily risk report which measures my realised p&l (over 10 business days) by instrument (using the 'current' method) and for the total portfolio (source: 'total value'), and compares it to expectations. I also then stare hard at the expected risk, and mentally work out how many sigma up or down I am on the day. For some reason I've not automated this calculation. Perhaps because it is at the heart of position risk management, I like to be forced to have that intuition. The daily risk report also tells me what the volatility targeting calculations are.

Last, and should be least, I run pure p&l reports for various periods (daily, weekly, fortnightly..... annually, all history). These look at the total p&l, and also cross check different measures ('current', 'retro' and 'portfolio value'). As I keep saying to you, and to myself, these are just random numbers but it's very hard not to be excited by a good day, or hacked off with a bad one. So I'm clearly to emotional to be a discretionary trader - systematic trading is the way to go.

This is only a brief description; there will be more detail on reports in the next post "checks and balances".


Fin 


You should now have a rough idea of how to calculate roughly how successful you have been. Or not.


According to google images this is what a successful trader looks like. He certainly appears to be wealthy enough to afford the largest monitor I have ever seen. Or perhaps he is just a very small man standing in front of a normal sized monitor.


In the next post "checks and balances" I'll look at what reports I run, how to keep a close eye on the system, and make sure it isn't doing anything crazy.

This is the fifth post in a series on building systematic trading systems.

The first four posts are:

http://qoppac.blogspot.co.uk/2015/04/system-building-data-capture.html
http://qoppac.blogspot.co.uk/2015/05/systems-building-futures-rolling.html
http://qoppac.blogspot.co.uk/2015/06/systems-building-deciding-positions.html
http://qoppac.blogspot.co.uk/2015/07/systems-building-execution.html


The next post is:

http://qoppac.blogspot.co.uk/2015/09/systems-building-checks-and-balances.html

No comments:

Post a Comment