Clear Filters
Clear Filters

Alternative for an increasing number of conditions in if-statements

3 views (last 30 days)
Dear all,
My issue:
  • I have got a date vector with portfolio rebalancing dates. As the time goes by, the vector length increases as one rebalances. The rebalance frequency is unknown.
  • There is also a time table with rankings for each member in the portfolio for a certain period (daily rankings).
For each day I need the rankings from the time table mentioned above in order to compute the daily returns to another matrix (nDates,nAssets). However, the rankings stay unchanged from rebalance date to rebalance date.
I can use a if statement like this:
If ReturnDate>= first rebalance date OR < second rebalance date
do operation which consists of getting the rankings
elseif ReturnDate>= second rebalance Date OR > third rebalance date
do operation which consists of getting other rankings
The code continues… However, as the number of rebalance dates increases the elseif statements increases and the code as well. It gets inefficient and by each rebalance date I need to change the code.
Is there any other alternative instead of increasing the number of conditions?

Answers (0)

Categories

Find more on Portfolio Optimization and Asset Allocation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!