Skip to content

Commit ac54fe8

Browse files
authored
Update readme.md
1 parent d0cad42 commit ac54fe8

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

Trading/utils/criterion/readme.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,49 @@
11
# Numerical and logical expression wrapper
2+
3+
Wrapper for logical expressions that can be debugged, printed, enabled and disabled.
4+
5+
Here is a practical example:
6+
```python
7+
from Trading.utils.criterion.expression import Numerical, and_
8+
import operator
9+
10+
payout_criterion = Numerical(
11+
"Payout ratio", operator.lt, payout_ratio, max_payout_ratio
12+
)
13+
yield_criterion = Numerical(
14+
"Dividend yield", operator.ge, dividend_yield, min_yield
15+
)
16+
debt_criterion = Numerical(
17+
"Debt-to-equity ratio", operator.le, debt_equity, max_debt_equity
18+
)
19+
roe_criterion = Numerical("Return on equity", operator.ge, roe, min_roe)
20+
free_cashflow_criterion = Numerical(
21+
"Free cash flow", operator.ge, free_cashflow, min_free_cashflow
22+
)
23+
criteria = and_(
24+
payout_criterion,
25+
yield_criterion,
26+
debt_criterion,
27+
roe_criterion,
28+
free_cashflow_criterion,
29+
)
30+
print(criteria.formatted())
31+
```
32+
33+
*Console output:*
34+
```txt
35+
( (Payout ratio 250.0 < 80 False) &
36+
( (Dividend yield 12.93 >= 2.0 True) &
37+
( (Debt-to-equity ratio 1.16 <= 0.5 False) &
38+
( (Return on equity 4.45 >= 10.0 False) &
39+
(Free cash flow 200260256 >= 10000000.0 True) False) False) False) False)
40+
```
41+
Whenever you have complex criteria in your program, you should really use this framework.
42+
43+
Calling `.debug` on a criterion will list the conditions that make it evaluate to `False`.
44+
45+
By inspecting this output, you can painlessly debug why your criteria doesn't evaluate to `True` when expected.
46+
247
```python
348
import operator
449
roe = Threshold("Return on Equity: ", operator.ge, 10.0)

0 commit comments

Comments
 (0)