Arbitration¶
- class src.lib.analysis.arbitration.Arbitration¶
Bases:
object
- arbitrate()¶
Calculate the arbitration (combined strategy) which is a complex logic using other previous methods (e.g. MACD, RSI) or different sources (e.g. Machine Learning).
The higher priority trigger in the overall logic is for crash protection. So if a stock value drops more than 10% in a single day a sell order will take the priority over all the other analysis. This trigger is only valid from the most recent entry.
The first observation using data from many symbols is that the MACD by itself can produce relative positive performance (comparing to a buy-hold) strategy, if the stock is not on a strong upward (bullish) movement. To calculate the overall state of the stock, the average gains and average loses over the data period is calculated and produce a ratio:
\[Ratio = \frac{AverageGain}{AverageLoss}\]Where the Average for both the Gain and Loss is done by sum of positive deltas (between days) or negative deltas (in absolute value).
A Ratio below 1.1 or 1.2, by empirical observation, seems the limit for produce better results with pure MACD.
- define_actions(source_column: str, result_column: str = '', result_dataframe: Optional[pandas.core.frame.DataFrame] = None)¶
- recommend_threshold_cross(source_column: str, threshold_upper: float, threshold_lower: float, mode: str = 'abs', hysteresis: bool = True, values_upper_mid_lower: tuple = ('BUY', 'HOLD', 'SELL'), result_column: str = '')¶
Calculate a recommendation to buy or sell based on a threshold crossing. Strategy methods: Functions which will return a final recommendation about a ticker. The returned value is a value between -1 and 1 indicating possible buy or sell actions.
- Parameters
source_column (string) – Name of the column in the Pandas Dataframe which contains the series to be analyzed or based of the calculation.
threshold_upper (float) – Upper threshold for the crossing. When different from the lower threshold it will automatically introduce an histeresys in the method. Depending on the parameter mode this value represents an absolute value or a relative (to the peak in the total series).
threshold_lower (float) – Upper threshold for the crossing. When different from the upper threshold it will automatically introduce an histeresys in the method. Depending on the parameter mode this value represents an absolute value or a relative (to the peak in the total series).
mode (string, optional) –
Mode of calculation, 2 inputs are possible:
”abs”: The threshold are used absolute values.
”norm”: The threshold are used as relative values to the peaks (normalization).
- recommend_threshold_curve(source_column: str, reference_column_upper: str, reference_column_lower: str, hysteresis: bool = True, values_upper_mid_lower: tuple = ('BUY', 'HOLD', 'SELL'), result_column: str = '', result_dataframe: Optional[pandas.core.frame.DataFrame] = None)¶