# Problem 45884. Algorithmic Trading - 3 (short selling and leverage)

This is the third of a series of problems on quant trading. It builds on earlier problems 45776 and 45860
Goal
Similar to problem 45860, allowing short-selling and leverage. Check <https://www.sec.gov/answers/shortsale.htm> and <https://en.wikipedia.org/wiki/Leverage_(finance)>
Use a fractional trading strategy, allowing short selling and leverage, as follows:
• Each day invest fraction E of the available funds, with -2 <= E <= 3
• This is referred as a limit of 3x leverage on long positions, and 2x leverage on short positions
You are given
• P, a [n x 1] vector of daily prices of the traded security, at market open (always positive)
• S, a [n x 1] vector of trading signals, calculated just ahead of market open (can take any real value)
• These will serve both as training and test set
Your function should return
• t, a scalar threshold that determines the state of the trading signal S
• E, a 2 x 1 vector of security exposures in each state, i.e.: invest a fraction E(1) of the available equity when S(i) < t, and a fraction E(2) when S(i) >= t, with -2 <= E(k) <= 3, for any k
Hints
• The array of daily returns can be calculated by R = D.*E(1+(S(1:end-1)>=t))'

### Solution Stats

100.0% Correct | 0.0% Incorrect
Last Solution submitted on Nov 06, 2020

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!