This is the first of a series of problems on quant trading. Quant traders seek to optimize investment performance devising trading strategies (i.e. rules) that exploit patterns found in historical market data.
Creative solutions, comments and suggestions for improvement of the problem are appreciated! Please respect basic courtesy guidelines: e.g. refrain from using Cody hacks to get a leading score.
Goal
• Trade one single security, based on one single trading signal (observed variable)
• Use an all or nothing, fractional trading strategy, with no leverage nor short selling - each day invest either 100% of the funds at market open, or leave them all in cash)
• Maximize the compound annual growth return (CAGR) of your investment, over the test period
• Check <https://en.wikipedia.org/wiki/Compound_annual_growth_rate>
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
• t, a scalar threshold that determines this simple trading strategy: invest all the available funds in the security when S>t, stay in cash otherwise
Assumptions
• You transact once per day at market open
• You buy and sell the security instantaneously at market open
• You can buy, sell, and hold fractional volumes of the security
• You don't incur in transaction costs, nor do you receive any return on the funds left in cash
Hints
• The array of daily returns can be calculated by R = D.*(S(1:n-1)>t), where D is the day-ahead price change, i.e. D=P(2:n)./P(1:n-1)-1;
• You can assume there are 252 trading days/year, so your goal is to maximize CAGR = prod(1+D.*(S(1:n-1)>t))^(252/n)-1;
• You can find the solution by maximizing the sum of log returns or, more simply, maximizes sum(log(1+D.*(S(1:n-1)>t)));

### Solution Stats

0.0% Correct | 100.0% Incorrect
Last Solution submitted on Aug 12, 2023

#### Problem Recent Solvers0

No solvers yet, be the first player to solve this problem.

### Community Treasure Hunt

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

Start Hunting!