Skip to content
nickjacob edited this page Mar 23, 2012 · 3 revisions

Overview

The backend package contains all of the backend code for tradeup. This includes:

  • Implementation of expression,reciperow, recipe, trigger
  • Data storage for performance
  • Data evaluation/format

Model Classes

Each object in the recipe-builder of the gui is modeled by a separate class.

BackendObj

This implements a couple of functions common among all of the model classes:

  • json - returns a json representation of the object's data() dict method. For debugging in most classes
  • performance_update - this updates the performance information, or, if there was no trigger() called, it returns the last value. TODO: figure out what this needs to actually be doing (i.e. there should be an update portfolio function. We need to keep track of what securities we're trading!)

Expression

Models an expression used; i.e. price("IBM). Each RecipeRow has 2 of these.

  • data - returns a dict representing the expression, with the name of the .func (contained in exprfuncs.py)
  • eval(self,data) - takes a piece of data (a datetime.datetime object) and evaluates the function

RecipeRow

A row in the recipe: 2 expressions and a comparator.

  • eval - returns a boolean
  • data - a dictionary representation of it (calls data in the expressions)

Recipe:

A recipe that can have rows added to it. Also contains a trigger and a color to represent it on the graph. The recipe is evaluated, if all of the rows in the recipe evaluate to true, the trigger is executed and the change is recorded in the recipe.

Portfolio:

The portfolio contains the recipes. When it is evaluated, it eval()s all of the recipes, and returns a dictionary of each recipe performance hashed to its color along with itself hashed to its color. Eval should be called here, with the output being sent to the gui controller class.

Trigger

The trigger simply contains a function and a boolean. This prevents the function from being evaluated every time the trigger is called. If the trigger is called twice in a row, the second time it will simply return None, which will cause the recipe's data to stay the same (this needs to call some update() function instead that updates the prices of the securities. This is a todo.)

Parsing

The parser class is responsible for parsing .algo files (created by calling Portfolio.to_file()) and creating a new recipe.

TODO/Status

  • Consider moving Parser and Portfolio to different files -- maybe split everything up much more.
  • Need to figure out how to track the portfolio itself (i.e. the trigger needs to interface with the portfolio, and the portfolio needs to have an update() method that checks the prices of all of the securities listed in the portfolio's dictionary of securities/shares. I.e.; when the data isn't being changed, it should at least be updated.
  • Interface fully with front-end.

Status: The backend is probably about 55% done.

Clone this wiki locally