# How to calculate returns of backtested strategy?

Lets say I have some strategy (long/short) backtested for certain period. Strategy has entries/exits only at the end of the day and may have overnight positions hold. Now I would like to compare returns of my strategy to the market (for instance SPY as benchmark) and find correlation coeff. between my returns and market.

So my question is what's right/standard rule for calculating returns for strategy ? I'm considering using Unrealized+Realized value

Following is simplified matlab code for single stock (there is no transaction cost accounted).

# "Backtester"

% positions sizes for every day
positions = [2 1 -10 15 5 0];

% execution prices (daily closes)
price=[50.0 51.0 49.0 51.0 53.0 52.0];

% here cash for positions

% and here I calculate my mark-to-market potrtfolio value
markToMarketPnL = cash + (positions).*price;

disp(markToMarketPnL)


It gives MTM (actually real+unreal) for every day.

0 2 0 -20 10 5

Now I need to compare it to market return. For finding market returns I use SPY's prices and returns as $r_m = \frac{SPY(i)}{SPY(i-1)} - 1$

So the question now - what is 'standard' way to calculting daily returns for my 'strategy' to be compared with $r_m$ in sense of finding correlation coefficient or $\beta$ etc ?

First thought is to use following : $$r(i) = \frac{MTM(i)}{MTM(i-1)} - 1$$

But in this case sometimes I may get values near/equal to 0 in denominator and my ret. goes to infinity (see results of example).

Someone uses 'invested money' as denominator, but I'm unsure about this. What should be in this case there in denominator ? long+short exposure for previous day ?

Another idea I got is to use NAV (net asset value) for portfolio to derive returns. For single stock it'd be equal to used stock prices of course, but for many stocks it has sense of price of some 'synthetical' portfolio

$$NAV(i) = \frac{\sum_{j \in long}{pos(j,i)\cdot mktPrice(j,i)} + \sum_{k \in short}{\lvert pos(k,i)\rvert \cdot mktPrice(k,i)}}{\sum_{j \in long}{pos(j,i)} + \sum_{k \in short}{\lvert pos(k,i)\rvert}}$$

where $pos(i,j)$ - position size of i-th stock at j-th day, $mktPrice(i,j)$ - close/current price of i-th stock at j-th day

Pls advice or point me to good resource for these kind of things.

• You definitely need to include invested money as part of the computation. This is easy for long positions. For short positions, determine the margin requirement that a broker would've required to allow you to take that short position.
– user59
Oct 29 '14 at 16:23
• @barrycarter Yes, seems it's only reasonable solution.
– mde
Oct 31 '14 at 15:36
{"ft_lang_label":"__label__en","ft_lang_prob":0.8517553,"math_prob":0.96606857,"size":2306,"snap":"2021-31-2021-39","text_gpt3_token_len":637,"char_repetition_ratio":0.098175496,"word_repetition_ratio":0.005376344,"special_character_ratio":0.27797052,"punctuation_ratio":0.09050772,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9932051,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-09-20T05:38:36Z\",\"WARC-Record-ID\":\"<urn:uuid:98173dbd-9fb6-4b18-bbe1-576acde96ff8>\",\"Content-Length\":\"157213\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:3f27ae0f-380b-4253-88d9-2e87d65662ee>\",\"WARC-Concurrent-To\":\"<urn:uuid:619fa326-992b-4b9d-8e0c-7d07d39852d8>\",\"WARC-IP-Address\":\"151.101.1.69\",\"WARC-Target-URI\":\"https://quant.stackexchange.com/questions/15191/how-to-calculate-returns-of-backtested-strategy\",\"WARC-Payload-Digest\":\"sha1:QVKTYJRFXR7CJM4VBBW6OMM4XUTE4ZBG\",\"WARC-Block-Digest\":\"sha1:QA7HNRHOMU66JXV5SKQRET3NLD7OUZVO\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-39/CC-MAIN-2021-39_segments_1631780057018.8_warc_CC-MAIN-20210920040604-20210920070604-00640.warc.gz\"}"}