r"""Trade the given system. Parameters ---------- model : alphapy.Model The model object with specifications. system : alphapy.System The long/short system to run. space : alphapy.Space Namespace of instrument prices. intraday : bool If True,
(model, system, space, intraday, name, quantity)
| 139 | # |
| 140 | |
| 141 | def trade_system(model, system, space, intraday, name, quantity): |
| 142 | r"""Trade the given system. |
| 143 | |
| 144 | Parameters |
| 145 | ---------- |
| 146 | model : alphapy.Model |
| 147 | The model object with specifications. |
| 148 | system : alphapy.System |
| 149 | The long/short system to run. |
| 150 | space : alphapy.Space |
| 151 | Namespace of instrument prices. |
| 152 | intraday : bool |
| 153 | If True, then run an intraday system. |
| 154 | name : str |
| 155 | The symbol to trade. |
| 156 | quantity : float |
| 157 | The amount of the ``name`` to trade, e.g., number of shares |
| 158 | |
| 159 | Returns |
| 160 | ------- |
| 161 | tradelist : list |
| 162 | List of trade entries and exits. |
| 163 | |
| 164 | Other Parameters |
| 165 | ---------------- |
| 166 | Frame.frames : dict |
| 167 | All of the data frames containing price data. |
| 168 | |
| 169 | """ |
| 170 | |
| 171 | # Unpack the model data. |
| 172 | |
| 173 | directory = model.specs['directory'] |
| 174 | extension = model.specs['extension'] |
| 175 | separator = model.specs['separator'] |
| 176 | |
| 177 | # Unpack the system parameters. |
| 178 | |
| 179 | longentry = system.longentry |
| 180 | shortentry = system.shortentry |
| 181 | longexit = system.longexit |
| 182 | shortexit = system.shortexit |
| 183 | holdperiod = system.holdperiod |
| 184 | scale = system.scale |
| 185 | |
| 186 | # Determine whether or not this is a model-driven system. |
| 187 | |
| 188 | entries_and_exits = [longentry, shortentry, longexit, shortexit] |
| 189 | active_signals = [x for x in entries_and_exits if x is not None] |
| 190 | use_model = False |
| 191 | for signal in active_signals: |
| 192 | if any(x in signal for x in ['phigh', 'plow']): |
| 193 | use_model = True |
| 194 | |
| 195 | # Read in the price frame |
| 196 | pf = Frame.frames[frame_name(name, space)].df |
| 197 | |
| 198 | # Use model output probabilities as input to the system |
no test coverage detected