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
Problem Comments
-
1 Comment
jmac
on 22 Nov 2020
Test suite fixed
Solution Comments
Show commentsProblem Recent Solvers1
Suggested Problems
-
25949 Solvers
-
Determine whether a vector is monotonically increasing
19395 Solvers
-
Find all elements less than 0 or greater than 10 and replace them with NaN
15289 Solvers
-
20486 Solvers
-
Exhaust all possible logical vectors
17 Solvers
More from this Author10
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!