Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Explanation of Daily Positions and Gains

Hi guys,

Sounds pretty simplistic, but I cannot make heads or tails of the "Position" and "Gains" columns of Q's evaluation reports when you click "Daily Positions and Gains". At first blush, it appears that your Positions is your m/m running balance at the end of the day, while the "Gains" is the cumulative total of all gains and losses.

But this cannot be, since they soon start to diverge by more than the amount of starting capital.
e.g. total:$107,970.13 total:$4,579.66

Can somebody explain this to me? Is there a way of exporting these values to a "csv" file in order to load them to a spreadsheet and perform cross-checking?

Thanks

12 responses

For a given equity that you are holding: the position is the dollar-value of the shares of the equity. The gain is the price-increase of the shares of the equity up to that day.

E.g. if you hold $10k in Apple, that's your position. If it goes up 5%, you make $500, i.e. have a gain of $500.

I'm not sure what you mean by "diverge by more than the amount of starting capital." Can you clarify your question?

John Loeber ,

To my understanding, Serge asking what metric is in the column Gain of Daily Positions and Gains report.
It should be what you explain to Serge but in reality it is not daily gain.
What is it?

Hi John,

Are you saying the gain is the gain on that day regardless of whether or not the share had made or lost money in days prior to that?
eg.
30jan buy 100 shares aapl at $130 position value $13000 gain 0.00 (assuming shares don't rise by end of day)
02feb aapl price drops to $127 position value $12700 loss $100 (assume price fell that day from 128 to $127)
03feb aapl price rises to 127.20 position value $12720 gain 0.20

In that case, to judge how your overall portfolio is doing you should just concentrate on position value. Position gain is of no use in evaluating your
overall profit/loss on that security, but is helpful in determing if your situation in that security - whether it's a big loss or a big gain - is improving or declining.

Is my understanding correct now?

Thanks

Hi Serge,

No, sorry for the confusion. Gain is a cumulative measure, over all time. I suggest running the sample algorithm over a month and looking at the output. For example, here's some data:

2015-06-08 -- AAL -- Position: $29,496.40 -- Gain: $138.38
2015-06-09 -- AAL -- Position: $29,836.80 -- Gain: $478.78
2015-06-10 -- AAL -- Position: $29,918.20 -- Gain: $560.18

So you can see that the difference between the position values is the same as the difference between the gains.

John,
If gain is a cumulative measure, then there is something wrong with the summary calculations.
Please see the algo labeled " value template long-only w/trend filter cloned" run for the period from 2002-01-03 to 2012-06-30 with $100,000 initial capital (minute data)
At first it start out fine, must as you show in your posting above:

2004-08-27-- Position: total:$119,800.94 Gains =total:$9,132.60

But then as time proceeds
2004-11-25-- Position: total:$156,097.49 Gains =total:$9,132.60

This should be showing gains of $56,000 .

What gives?

Thanks
Serge

Serge, can you please link me to the algorithm? I want to make sure that I look at the right one. Thanks!

Or, better yet, add me as a collaborator on your algorithm ([email protected]).

Hi John,

Just added you as a collaborator. Thanks.

Serge, I'm looking at the daily position results of your algo and I'm confused. The portfolio for 2004-08-27 is all-cash, $146,642.74, with blank gains.

2004-11-25 was not a trading day. I think you meant 2004-11-24. For that, I've got the following data:

image

Which looks fine to me. What's going on?

OK, from your image: If you have total positions worth $154k and started with $100k then you should have profits of around $54k, not $8021 shown. What am I misunderstanding?

I'm not sure about my answer, but it looks to me as if your gains are calculated only for currently open positions -- that's why, whenever your portfolio is cash-only, the gains are blank. I think gains are calculated only for positions that are currently open. Please check if that sounds right.

OK , John,

I think I've figured it out. You seem to be correct. The gain reflects the profit and loss since inception on that security. The reason I show a larger gain in my positions column is that the latter reflects gains and losses (net gains in this example) for positions that we are no longer holding.

e.g. Jul buy AAPL CSCO 1000 SHARES OF EACH
Aug sell AAPL but not CSCO, making profit of $20k
Sep CSCO position showing with Positions 128,598 Gain 8,598

So we have mark to market gain of $8598 on CSCO ,but overall gain of $128,598 - $100,000 on overall portfolio, of which $20k is
gain of AAPL that is no longer featured in our daily summary..

Hope this will help someone else.
Thanks for your help on this John.

Glad to hear that was it. Cheers.