When stocks are purchased the portfolio cash is always reduced by the purchase price plus any commission. When stocks are sold the portfolio cash is increased by the sale price less any commission. This is exactly what would happen in a real brokerage account.
Therefore the comment above isn't exactly correct
if my portfolio value (yesterday) is 100 and I would invest 50 in a new security (with leverage) and this security and my portfolio of 100 would stay at the same price during that day I would have made a return of 50% according to the definition above. So return value is added out of nothing.
Let's follow the chain of events when purchasing a stock (long). For simplicity assume (for now) that the end of day closing price of our stock XYZ stays the same at $100/share. Also assume commissions are $0.
day 1 - opening balance of $100,000
cash: $100,000
stock value: $0
portfolio value: $100,000 (100000 + 0)
leverage: 0 (0 / 100000)
day 2 - purchase shares with existing cash
buy 1000 shares XYZ @ $100/share
cash: $0
stock value: $100,000
portfolio value: $100,000 (0 + 100000)
leverage: 1 (100000 / 100000)
daily returns: 0% (100000 - 100000) / 100000
day 3 - purchase shares on margin
buy 1000 shares XYZ @ $100/share
cash: -$100,000
stock value: $200,000
portfolio value: $100,000 (-100000 + 200000)
leverage: 2 (200000 / 100000)
daily returns: 0% ((100000 - 100000) / 100000)
day 4 - purchase more shares on margin
buy 1000 shares XYZ @ $100/share
cash: -$200,000
stock value: $300,000
portfolio value: $100,000 (-200000 + 300000)
leverage: 3 (300000 / 100000)
daily returns: 0% ((100000 - 100000) / 100000)
day 5 - sell all the shares
sell 3000 shares XYZ @ $100/share
cash: $100,000
stock value: $0
portfolio value: $100,000 (100000 + 0)
leverage: 0 (0 / 100000)
daily returns: 0% ((100000 - 100000) / 100000)
A few things to note about the above. 1) the portfolio value always stays at $100,000 even as more shares are bought with margin and leverage increases. 2) the daily returns, and net return over the 5 days, is 0%. 3) the cash in the account goes negative when leverage is over 1. A negative cash amount implies funds which are borrowed and need to be paid back.
So, what does a similar transaction look like if the stock price goes up? Again assume no commissions but now our XYZ goes up to $101. First with a leverage of 1.
day 1 - opening balance of $100,000
cash: $100,000
stock value: $0
portfolio value: $100,000 (100000 + 0)
leverage: 0 (0 / 100000)
day 2 - purchase shares with existing cash
buy 1000 shares XYZ @ $100/share
cash: $0
stock value: $100,000
portfolio value: $100,000 (0 + 100000)
leverage: 1 (100000 / 100000)
daily returns: 0% (100000 - 100000) / 100000
day 3 - sell all the shares at $101
sell 1000 shares XYZ @ $101/share
cash: $101,000
stock value: $0
portfolio value: $101,000 (101000 + 0)
leverage: 0 (0 / 101000)
daily returns: 1% ((101000 - 100000) / 100000)
Looks good. We made 1%. Now look at the same transaction but buy on margin for a leverage of 2.
day 1 - opening balance of $100,000
cash: $100,000
stock value: $0
portfolio value: $100,000 (100000 + 0)
leverage: 0 (0 / 100000)
day 2 - purchase 2000 shares using margin
buy 2000 shares XYZ @ $100/share
cash: $-100,000
stock value: $200,000
portfolio value: $100,000 (-100000 + 200000)
leverage: 2 (200000 / 100000)
daily returns: 0% (100000 - 100000) / 100000
day 3 - sell all the shares at $101
sell 2000 shares XYZ @ $101/share
cash: $102,000 ((2000x101) + (-100000))
stock value: $0
portfolio value: $102,000 (102000 + 0)
leverage: 0 (0 / 102000)
daily returns: 2% ((102000 - 100000) / 100000)
Notice that by adding leverage we multiply our returns. Even though we do not directly increase our net portfolio value with leverage we do multiply any gains. This is why using margin can be a great tool. However, notice I intentionally used the word multiply and not increase. If one had daily losses (eg -1%) leverage will multiply those and be -2%.
When comparing strategies it's typically best to have an 'apples to apples' comparison and ensure one's leverage is the same. Try to keep leverage around 1. In the real world, individuals are typically limited to a leverage of 2 by one's broker (and the SEC). Additionally, borrowing money is not free. The backtester doesn't take any borrowing costs into account. So, while the returns on highly leveraged portfolios are technically correct they would probably not be realized in live trading.