def strategy(ticket, df):

    values = []
    ema = df['EMA_9'][-1]
    sma = df['SMA_40'][-1]
    price = df['Último'][-1]
    datum = Datum(ticket)
    if datum in data:
        datum = data[data.index(Datum(ticket))]

        if ema > sma:
            if datum.flag != 2:
                notify(ticket, 2, df.index[-1])
                save_datum(datum, 2)

        elif ema < sma:
            if datum.flag != 1:
                notify(ticket, 1, df.index[-1])
                save_datum(datum, 1)

        elif datum.flag != 0:
            save_datum(datum, 0)

    else:
        data.append(datum)
def strategy(ticket, df):

    values = []
    for window in windows:
        values.append(df['SMA_' + str(window)][-1])
    price = df['Último'][-1]
    datum = Datum(ticket)
    if datum in data:
        datum = data[data.index(Datum(ticket))]

        if price <= values[0] < values[1] < values[2] and bearish_fractal(df):
            if datum.flag != 2:
                notify(ticket, 2, df.index[-3])
                save_datum(datum, 2)

        elif price >= values[0] > values[1] > values[2] and bullish_fractal(
                df):
            if datum.flag != 1:
                notify(ticket, 1, df.index[-3])
                save_datum(datum, 1)

        elif datum.flag != 0:
            save_datum(datum, 0)

    else:
        data.append(datum)
Esempio n. 3
0
    def build_vdatum_input(self):
        datum_frame = tk.Frame(self.controller_panel)
        datum_frame.columnconfigure(0, weight=1)
        datum_frame.grid(row=3, sticky=tk.EW)
        tk.Label(datum_frame, text="VDatum Region",
                 font='Helvetica 10 bold').grid(row=0,
                                                columnspan=1,
                                                pady=(10, 0),
                                                sticky=tk.EW)

        datum = Datum()
        regions, mcu_values, default_msg = datum.get_vdatum_region_mcus()
        self.vdatum_regions = dict({(key, value)
                                    for (key,
                                         value) in zip(regions, mcu_values)})
        self.vdatum_regions.update({default_msg: 0})
        self.vdatum_region = tk.StringVar(self)
        self.vdatum_region.set(default_msg)
        self.vdatum_region_option_menu = tk.OptionMenu(
            datum_frame,
            self.vdatum_region,
            *sorted(self.vdatum_regions.keys()),
            command=self.update_vdatum_mcu_value)
        self.vdatum_region_option_menu.config(width=self.control_panel_width,
                                              anchor='w')
        self.vdatum_region_option_menu.grid(sticky=tk.EW)
Esempio n. 4
0
    def setFeaturesTrain(self, data):
        newData = []
        words = []

        for datum in data:
            words.append(datum.word)

        ## This is so that the feature factory code doesn't
        ## accidentally use the true label info
        previousLabel = "O"
        followingLabel = "O"
        for i in range(0, len(data)):
            datum = data[i]
            ## MY EDIT
            if i != len(data) - 1:
                followingDatum = data[i + 1]
            else:
                followingDatum = datum

            newDatum = Datum(datum.word, datum.label)
            newDatum.followingLabel = followingDatum.label
            newDatum.features = self.computeFeatures(words, previousLabel, i,
                                                     followingDatum.label)
            newDatum.previousLabel = previousLabel
            newData.append(newDatum)
            previousLabel = datum.label

        return newData
Esempio n. 5
0
    def setFeaturesTest(self, data):
        newData = []
        words = []
        labels = []
        labelIndex = {}

        for datum in data:
            words.append(datum.word)
            if datum.label not in labelIndex:
                labelIndex[datum.label] = len(labels)
                labels.append(datum.label)

        # This is so that the feature factory code doesn't
        # accidentally use the true label info
        for i in range(0, len(data)):
            datum = data[i]

            if i == 0:
                previousLabel = "O"
                datum.features = self.computeFeatures(words, previousLabel, i)

                newDatum = Datum(datum.word, datum.label)
                newDatum.features = self.computeFeatures(words, previousLabel, i)
                newDatum.previousLabel = previousLabel
                newData.append(newDatum)
            else:
                for previousLabel in labels:
                    datum.features = self.computeFeatures(words, previousLabel, i)

                    newDatum = Datum(datum.word, datum.label)
                    newDatum.features = self.computeFeatures(words, previousLabel, i)
                    newDatum.previousLabel = previousLabel
                    newData.append(newDatum)

        return newData
Esempio n. 6
0
def parse_csv_line(line, optimized_indexes=[]):
    """
    Parse a csv line and return a list of string
    """
    parsed_line = line.rstrip().split(SEPARATOR)

    if len(optimized_indexes) == 0:
        return Datum(parsed_line)

    result = [
        parsed_line[i] for i in range(len(parsed_line))
        if i in optimized_indexes
    ]
    return Datum(result)
    def setFeaturesTrain(self, data):
        newData = []
        words = []

        for datum in data:
            words.append(datum.word)

        ## This is so that the feature factory code doesn't
        ## accidentally use the true label info
        previousLabel = "O"
        for i in range(0, len(data)):
            datum = data[i]

            newDatum = Datum(datum.word, datum.label)
            newDatum.features = self.computeFeatures(words, previousLabel, i)
            newDatum.previousLabel = previousLabel
            newData.append(newDatum)

            previousLabel = datum.label

        return newData
    def setFeaturesTest(self, data):
        newData = []
        words = []
        labels = []
        labelIndex = {}

        for datum in data:
            words.append(datum.word)
            if not labelIndex.has_key(datum.label):
                labelIndex[datum.label] = len(labels)
                labels.append(datum.label)
        
        ## This is so that the feature factory code doesn't
        ## accidentally use the true label info
        for i in range(0, len(data)):
            datum = data[i]

            if i == 0:
                previousLabel = "O"
                datum.features = self.computeFeatures(words, previousLabel, i)

                newDatum = Datum(datum.word, datum.label)
                newDatum.features = self.computeFeatures(words, previousLabel, i)
                newDatum.previousLabel = previousLabel
                newData.append(newDatum)
            else:
                for previousLabel in labels:
                    datum.features = self.computeFeatures(words, previousLabel, i)

                    newDatum = Datum(datum.word, datum.label)
                    newDatum.features = self.computeFeatures(words, previousLabel, i)
                    newDatum.previousLabel = previousLabel
                    newData.append(newDatum)

        return newData
Esempio n. 9
0
 def standard_read(self):
     with open(self.source_data_file) as fopen:
         doc_id = 0
         tokens, glabels = [], []
         for line in fopen.readlines():
             line = line.replace(' ', '\t')
             if line.strip():
                 tokens.append(line.strip().split('\t')[0])
                 glabels.append(line.strip().split('\t')[1])
             elif line.strip() == '' and tokens:
                 doc = ' '.join(tokens)
                 datum = Datum(doc_id, doc, tokens, glabels, [])
                 self.Datums.append(datum)
                 doc_id += 1
                 tokens, glabels = [], []
    def readTestData(self, ch_aux):
        data = []

        for line in ch_aux.splitlines():
            line_split = line.split()
            # remove emtpy lines
            if len(line_split) < 2:
                continue
            word = line_split[0]
            label = line_split[1]

            datum = Datum(word, label)
            data.append(datum)

        return data
    def readData(self, filename):
        data = []

        for line in open(filename, 'r'):
            line_split = line.split()
            # remove emtpy lines
            if len(line_split) < 2:
                continue
            word = line_split[0]
            label = line_split[1]

            datum = Datum(word, label)
            data.append(datum)

        return data
Esempio n. 12
0
def strategy(ticket, mavs, time1):
    datum = Datum(ticket)
    b = check_mavs(ticket, mavs, time1)
    if datum in data:
        index = data.index(datum)
        if data[index].flag is False and b == 1:
            notify(ticket, 1, time1)
            data[index].flag = True
        elif data[index].flag is False and b == 2:
            notify(ticket, 2, time1)
            data[index].flag = True
        elif b == 0:
            data[index].flag = False
    else:
        data.append(datum)
Esempio n. 13
0
    def processLine(self, line):
        line = line.strip()
        line = line.lower()
        line = line.replace('"', '')
        line = line.replace(',', '')
        line = line.replace('.', '')
        line = line.replace('!', '')
        line = line.replace("'", '')
        line = line.replace(":", '')
        line = line.replace(";", '')
        if line == '':
            return None

        # p = PorterStemmer()
        # print 'input line: \n' + line
        # line = p.run_porter_stemmer(line)
        # print 'output line: \n' + line

        processed_tokens = Sentence()
        processed_tokens.append(Datum("<s>"))  # start symbol
        tokens = line.split()
        i = 0
        while i < len(tokens):
            token = tokens[i]
            if token == '<err':
                targ = tokens[i + 1]
                targ_splits = targ.split('=')
                # chop off the trailing '>'
                correct_token = targ_splits[1][:-1]
                correct_token_splits = correct_token.split()
                if len(correct_token_splits) > 2:  # targ with multiple words
                    # print 'targ with multiple words: "%s"' % targ
                    for correct_word in correct_token_splits:
                        processed_tokens.append(Datum(correct_word))
                elif tokens[i + 3] != '</err>':
                    processed_tokens.append(Datum(correct_token))
                else:
                    incorrect_token = tokens[i + 2]
                    processed_tokens.append(
                        Datum(correct_token, incorrect_token))
                i += tokens[i:].index('</err>') + 1  # update index
            else:  # regular word
                processed_tokens.append(Datum(token))
                i += 1
        processed_tokens.append(Datum("</s>"))
        return processed_tokens
Esempio n. 14
0
 def processLine(self, line):
     line = line.strip()
     line = line.lower()
     line = line.replace('"', '')
     line = line.replace(',', '')
     line = line.replace('.', '')
     line = line.replace('!', '')
     line = line.replace("'", '')
     line = line.replace(":", '')
     line = line.replace(";", '')
     if line == '':
         return None
     processed_tokens = Sentence()
     processed_tokens.append(Datum("<s>"))
     tokens = line.split()
     i = 0
     while i < len(tokens):
         token = tokens[i]
         if token == '<err':
             targ = tokens[i + 1]
             targ_splits = targ.split('=')
             correct_token = targ_splits[1][:-1]
             correct_token_splits = correct_token.split()
             if len(correct_token_splits) > 2:
                 for correct_word in correct_token_splits:
                     processed_tokens.append(Datum(correct_word))
             elif tokens[i + 3] != '</err>':
                 processed_tokens.append(Datum(correct_token))
             else:
                 incorrect_token = tokens[i + 2]
                 processed_tokens.append(
                     Datum(correct_token, incorrect_token))
             i += tokens[i:].index('</err>') + 1
         else:  # regular word
             processed_tokens.append(Datum(token))
             i += 1
     processed_tokens.append(Datum("</s>"))
     return processed_tokens
Esempio n. 15
0
 def processLine(self, line):
     '''
     Reads line contains misspell words like the following
     <ERR targ=That's> Thats </ERR> what <ERR targ=James> Jame </ERR>
     Returns sentence including a list of Datum(correct word, incorrect word)
     '''
     processed_tokens = Sentence()
     processed_tokens.append(Datum("<s>"))  # start symbol
     tokens = line.split()
     i = 0
     while i < len(tokens):
         token = tokens[i]
         # find out misspell word place
         if token == "<err":
             targ = tokens[i + 1]
             targ_splits = targ.split("=")
             correct_token = targ_splits[1][:
                                            -1]  # chop off the trailing '>'
             correct_token_splits = correct_token.split()
             if len(correct_token_splits) > 2:  # targ with multiple words
                 print 'targ with multiple words: "%s"' % targ
                 for correct_word in correct_token_splits:
                     processed_tokens.append(Datum(correct_word))
             # if miss one word in between, so no incorrect_token in this case
             elif tokens[i + 3] != '</err>':
                 processed_tokens.append(Datum(correct_token))
             else:
                 incorrect_token = tokens[i + 2]
                 processed_tokens.append(
                     Datum(correct_token, incorrect_token))
             # move index to one after </ERR> symbol
             i += tokens[i:].index('</err>') + 1
         else:
             # No mis-spell, correct sentence
             processed_tokens.append(Datum(token))
             i += 1
     processed_tokens.append(Datum("</s>"))  # stop symbol
     return processed_tokens
Esempio n. 16
0
  >>> s.getErrorSentence()
  ['i', 'lov', 'girls']

- getCorrectSentence(): this method returns the right word. So;
  >>> s.getCorrectSentence()
  ['i', 'love', 'girls']

- cleanSentence(): this method returns the right word but as a sentence. so;
  >>> print s.cleanSentence()
  i love girls

- isCorrection(): this method takes a list of strings and it iterates every word in the list and compare it with
  the Datum instances in the 'data' variable. So;
  >>> s.isCorrection(["i", "love", "girls"])
  True
  >>> s.isCorrection(["i", "lov", "girls"])
  False
  >>> s.isCorrection(["i", "lov", "Girls"])
  False

- getErrorIndex(): this method returns the index of the wrong word in the sentence and returns -1 if 
  there is no error. So;
  >>> s.getErrorIndex()
  1

"""
if __name__ == "__main__":
    lst = [Datum("i"), Datum("love", "lov"), Datum("girls")]
    s = Sentence(lst)
    s.put(0, Datum('I'))
    print s.isCorrection(["I", "love", "girls"])