OpenRules Platform

Decision Optimization

Risky Stocks

Model conflicting stock-trading rules with probabilities and find a decision that minimizes total rule violations.

The problem was defined in the DMCommunity Risky Stocks challenge:

DMCommunity Risky Stocks challenge

Real-world trading systems produce buy and sell recommendations based on many more rules; the challenge above represents only a small business case. More importantly, financial experts may change these rules every morning and even during the day. People who have used such systems know how difficult it is to maintain frequently changing rules, especially when they conflict with each other. Such systems are usually rules-based and contain both hard rules and soft rules (preferences) that can be violated when necessary.

Keeping these considerations in mind, we applied Rules and Constraints with Probabilities, supported by Rule Solver and designed for business analysts without programming skills.

We start with the following business glossary:

Risky Stocks business glossary

It has four input variables and two output variables, “Stock Is Risky” and “Buy Stock Shares,” with the possible values 1 for Yes and 0 for No.

The first three rules specify the conditions under which a stock may be risky. They can be implemented in Rule Solver by posting these constraints with different probabilities:

Decision table posting risky-stock constraints with probabilities

Rule Solver supports the following probability values:

NEVER, VERY_LOW, LOW, BELOW_MID, MID, ABOVE_MID, HIGH, VERY_HIGH, ALWAYS

Rule 4 specifies when to buy or not buy a stock. We can implement it using the following decision table:

Decision table posting stock-purchase constraints

As usual for Rule Solver, the top-level Define and Solve tables look as follows:

Top-level Define and Solve decision tables

When Rule Solver executes the decision model, it looks for a solution that minimizes the total constraint violation: the higher a constraint’s probability, the more expensive its violation. The standard SolverFindSolution method called from the Solve table automatically decides which constraints will be violated while ensuring that the total constraint violation is minimal.

Here are the test cases for this decision model:

Risky Stocks decision-model test cases

All results matched the challenge’s expected recommendations. Here is the execution protocol for Test E:

Rule Solver execution protocol for Risky Stocks Test E

Conclusion. This challenge contains conflicting rules. When the number of rules is small, a pure rules-based solution may look sufficient. However, adding more rules can make conventional decision tables too difficult to understand and maintain. In such situations, it is more practical to apply rules with probabilities and find a solution that minimizes total rule violations.

Try Rule Solver

Build decision models that find the best answer.

Start with the free evaluation, then install Rule Solver and explore its optimization examples.