Exemple #1
0
 def _process(self):
     time.sleep(2)
     for stock in q01():
         #print stock
         #print stock['Empresa']
         #print empresasRiesgos
         for stock2 in empresasRiesgos:
             #print stock['Empresa']
             #print stock2['Enterprise']
             if stock['Empresa'] == stock2['Enterprise']:
                 print stock['ValorActual']
                 changePercentage = (stock['ValorActual'] -
                                     stock2['LastPrice']) / 100
                 stock2['LastPrice'] = stock['ValorActual']
                 if len(stock2['RisksValues']) >= 15:
                     stock2['RisksValues'].pop(0)
                     stock2['RisksValues'].append(changePercentage)
                 else:
                     stock2['RisksValues'].append(changePercentage)
                 print "Historic Risks of %s:" % stock2['Enterprise']
                 print stock2['RisksValues']
                 totalRisk = 0
                 for risk in stock2['RisksValues']:
                     totalRisk += risk
                     #print totalRisk
                 print "totalRisk: %s" % totalRisk
                 if totalRisk <= -7:
                     print '***********Notificar a gente de toma de decisiones*******************'
                     stock2['RisksValues'] = []
        def _process(self):
            #Wait for a message from the monitor agent
            time.sleep(3)

            for stock in q01():
                enterprise = stock['Empresa']
                if len(historic_prices[enterprise]) > 10:
                    historic_prices[enterprise] = []
                    historic_volumes[enterprise] = []
                historic_prices[enterprise].insert(0,stock['ValorActual'])
                historic_volumes[enterprise].insert(0,stock['Volumen'])

                #What strategy for this stock?
                strategy = q09(enterprise)

                # Strategy 1, If the value of my auction goes up 2 times
                if strategy == 1:
                    if len(historic_prices[enterprise]) > 2:
                        self.strategy1(enterprise,historic_prices[enterprise])
                #Strategy 2, If the value of the auction goes down 5 times
                elif strategy == 2:
                    if len(historic_prices[enterprise]) > 5:
                        self.strategy2(enterprise,historic_prices[enterprise])
                elif strategy == 3:
                #Strategy 3, If the value of an auction volume has an abnormal positive change, then buy
                    if len(historic_volumes[enterprise]) > 2:
                        self.strategy2(enterprise,historic_volumes[enterprise])
                elif strategy == 4:
                #Strategy 4 If the value of an auction volume has an abnormal negative change, then sell
                    if len(historic_volumes[enterprise]) > 2:
                        self.strategy2(enterprise,historic_volumes[enterprise])
                print "Watching stock %s with strategy %d NO CHANGES" %(enterprise, strategy[0]['EstrategiaInversion'])
            print "\n\n"
Exemple #3
0
        def _process(self):
            user_stocks = q01()
            for stock in user_stocks:
                enterprise = stock['Empresa']
                current_date = datetime.now()
                date = current_date.strftime('%Y-%m-%d ')
                volumen = stock['Volumen']
                precio_apertura = stock['PrecioApertura']
                volatilidad = stock['Volatilidad']
                valor_actual = stock['ValorActual']
                precio_clausura = stock['PrecioClausura']
                currentPrice = valor_actual

                currentVolume = volumen
                time.sleep(2)
                lastVolume = currentVolume
                randomVolumeFluctuation = random.randint(-100000, 100000)
                if randomVolumeFluctuation > 98000 or randomVolumeFluctuation < -98000:
                    currentVolume = currentVolume + randomVolumeFluctuation
                    print "*********** Sending information to coordinator Abnormal Volume detected!!!! ***********"
                    content = "\n\n ************* ALERT Abnormal Volume Flucutuation ************* \n The Enterprise %s last volume was : %f and its current volume is: %f\n" % (
                        enterprise, lastVolume, currentVolume)
                    self.myAgent.sendToCoordinator("inform", "Monitor",
                                                   content)
                else:
                    currentVolume = currentVolume + random.randint(-20, 40)

                print "The current volume for %s is: %d" % (enterprise,
                                                            currentVolume)
                q07(currentVolume, enterprise)
    def _setup(self):
        ''''''
        template = spade.Behaviour.ACLTemplate()
        template.setOntology("MaS")
        template.setPerformative("inform")
        template.setConversationId("Decision")
        mt = spade.Behaviour.MessageTemplate(template)
        self.addBehaviour(self.DecisionBehav(),mt)

        for stock in q01():
            enterprise = stock['Empresa']
            historic_prices[enterprise] = []
            historic_volumes[enterprise] = []
            historic_prices[enterprise].append(stock['ValorActual'])
            historic_volumes[enterprise].append(stock['Volumen'])


        print "\n\n*********** Decision Making Agent has Started\n\n"
Exemple #5
0
        def _process(self):
            user_stocks = q01()
            # Obtain the stock information of every asset
            for stock in user_stocks:
                enterprise = stock['Empresa']
                current_date = datetime.now()
                date = current_date.strftime('%Y-%m-%d ')
                volumen = stock['Volumen']
                precio_apertura = stock['PrecioApertura']
                volatilidad = stock['Volatilidad']
                valor_actual = stock['ValorActual']
                precio_clausura = stock['PrecioClausura']
                currentPrice = valor_actual

                time.sleep(2)
                lastPrice = currentPrice
                randomPriceFluctuation = random.randint(-1000, 1000)
                if randomPriceFluctuation > 900 or randomPriceFluctuation < -900:
                    currentPrice = currentPrice + randomPriceFluctuation
                    changePercentage = (currentPrice - lastPrice) / 100
                    print "******** Sending information to coordinator Abnormal Fluctuation detected!!!! ********"
                    content = "\n\n ************* ALERT Abnormal Price Flucutuation ************* \n The Enterprise %s last price was : %f and its current price is: %f the change percentage is %f\n" % (
                        enterprise, lastPrice, currentPrice, changePercentage)
                    print content
                    self.myAgent.sendToCoordinator("inform", "Monitor",
                                                   content)
                else:
                    currentPrice = currentPrice + random.uniform(-20.3, 40.0)
                    changePercentage = (currentPrice - lastPrice) / 100
                    content = {
                        'Enterprise': enterprise,
                        'date': date,
                        'lastPrice': lastPrice,
                        'currentPrice': currentPrice,
                        'changePercentage': changePercentage,
                    }
                #Update the database with the new values
                q08(currentPrice, enterprise)
                print "The current price for %s is: %f" % (enterprise,
                                                           currentPrice)
Exemple #6
0
 def q1(self):
     content = q01()
     self.myAgent.sendToCoordinator("request", "TechnicalAnalysis",
                                    content)
Exemple #7
0
import os
import sys
import time
import unittest
import spade
import random
import json
import ast

from datetime import datetime

from db.Queries import q01, q03, q04, q06

HOST = "127.0.0.1"

user_stocks = q01()
empresasRiesgos = []
for stock in user_stocks:
    #print stock
    enterprise = stock['Empresa']
    risksValues = []
    lastPrice = stock['ValorActual']
    enterpriseRisk = {
        'Enterprise': enterprise,
        'RisksValues': risksValues,
        'LastPrice': lastPrice,
    }
    empresasRiesgos.append(enterpriseRisk)


class Risk(spade.Agent.Agent):