MCPcopy Create free account
hub / github.com/ScottfreeLLC/AlphaPy / vtree

Function vtree

alphapy/variables.py:248–290  ·  view source on GitHub ↗

r"""Get all of the antecedent variables. Before applying a variable to a dataframe, we have to recursively get all of the child variables, beginning with the starting variable's expression. Then, we have to extract the variables from all the subsequent expressions. This process con

(vname)

Source from the content-addressed store, hash-verified

246#
247
248def vtree(vname):
249 r"""Get all of the antecedent variables.
250
251 Before applying a variable to a dataframe, we have to recursively
252 get all of the child variables, beginning with the starting variable's
253 expression. Then, we have to extract the variables from all the
254 subsequent expressions. This process continues until all antecedent
255 variables are obtained.
256
257 Parameters
258 ----------
259 vname : str
260 A valid variable stored in ``Variable.variables``.
261
262 Returns
263 -------
264 all_variables : list
265 The variables that need to be applied before ``vname``.
266
267 Other Parameters
268 ----------------
269 Variable.variables : dict
270 Global dictionary of variables
271
272 """
273 allv = []
274 def vwalk(allv, vname):
275 vxlag, root, plist, lag = vparse(vname)
276 if root in Variable.variables:
277 root_expr = Variable.variables[root].expr
278 expr = vsub(vname, root_expr)
279 av = allvars(expr)
280 for v in av:
281 vwalk(allv, v)
282 else:
283 for p in plist:
284 if valid_name(p):
285 vwalk(allv, p)
286 allv.append(vname)
287 return allv
288 allv = vwalk(allv, vname)
289 all_variables = list(OrderedDict.fromkeys(allv))
290 return all_variables
291
292
293#

Callers 1

vapplyFunction · 0.85

Calls 1

vwalkFunction · 0.85

Tested by

no test coverage detected