I understand this is quite the common question but I haven't been able to understand this concept through the previous posts.

My situation is that each day, I'm interested in buying/selling one financial instrument (always the same). Every day, I have a signal that tells me if I should buy or sell or do nothing. In order to test this signal, I'm trying to backtest the strategy on a 5 years period and I have two questions:

  1. How do I compute the PnL? I believe I should specify an initial fortune $V_0$ that I'm willing to invest on day 0. Then, if say my first signal tells me to buy, should I substract the today's price of the instrument $S_0$ to $V_0$ and my PnL today would be $V_0 - S_0$? What about the other days and the total PnL?

What if my first signal tells me to sell? How can I do that when I don't have any positions?

  1. My signals are the expected value $\mu_t$ and the risk $\sigma_t$ of the instrument's return on each day $t$. I can from then compute a daily Sharpe ratio $\text{Sharpe}_t = \mu_t/\sigma_t$ . If I want to have a Sharpe ratio of at least $1$ at the end of the 5 years, then I believe I should buy/sell on day $t$ if $|\text{Sharpe}_t| > 1/\sqrt{5\times250}$, is that right?

Thanks in advance.

  • 1
    $\begingroup$ Regarding Q1, at time 0 the price hasn't changed yet, so your holdings would be what you've spent buying stock ($kS_0$, with $k$ the number of shares) plus what you have left over: $V_0 - kS_0$. In any case, your day-0 wealth is your initial capital $V_0$. In terms of PnL, you select a "benchmark" (typically your initial wealth $V_0$) and use $V_t-V_0$ as your PnL (so how much you've made so far). You can also use percentages for this, e.g. $(V_t-V_0)/V_0$ or log-returns, etc. $\endgroup$ – Alex Lostado Apr 8 at 17:11

On any day you should keep track of two things: The cash on hand $V_t$ and the amount of the asset you own $A_t$ ($A$ can be negative if you allow short positions. Or if you want you can restrict $A$ to a range such as $0\le A_t \le U$ for example, or $-1 \le A_t \le 1$ for a simple startegy that is either neutral or long/short 1 unit). You don't allow the cash $V_t$ to go negative (print an error message if this happens).

When you buy the asset, $V$ decreases by the cost of the asset and $A$ increases by 1. When you sell, the opposite: the cash $V$ increases by the price of the asset and $A$ decreases by 1. It does not matter which event come first.

On any day your wealth is $W_t=V_t+P_t*A_t$, where $P$ is the price of the asset. The P&L is $\pi_t=W_t-W_{t-1}$ and the return is $r_t=\frac{W_t-W_{t-1}}{W_{t-1}} $

  • $\begingroup$ Thank you for your detailled answer. Do you know if my reasoning for the second question is correct? $\endgroup$ – Oskyr Apr 8 at 16:51
  • $\begingroup$ I don't know about the 2d question. $\endgroup$ – noob2 Apr 8 at 17:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.