Ejemplo n.º 1
0
def googleAmazonLowPatternSearchTest(createTestFile=False):
    """
    This pattern is looking for low prices of Amazon and Google at the same minute.
    PATTERN AND(AmazonStockPriceUpdate a, GoogleStockPriceUpdate g)
    WHERE a.PeakPrice <= 73 AND g.PeakPrice <= 525
    WITHIN 1 minute
    """
    googleAmazonLowPattern = Pattern(
        AndOperator([QItem("AMZN", "a"),
                     QItem("GOOG", "g")]),
        AndFormula(
            SmallerThanEqFormula(
                IdentifierTerm("a", lambda x: x["Peak Price"]),
                AtomicTerm(73)),
            SmallerThanEqFormula(
                IdentifierTerm("g", lambda x: x["Peak Price"]),
                AtomicTerm(525))), timedelta(minutes=1))
    runTest('googleAmazonLow', [googleAmazonLowPattern], createTestFile)
Ejemplo n.º 2
0
def amazonSpecificPatternSearchTest(createTestFile=False):
    """
    This pattern is looking for an amazon stock in peak price of 73.
    """
    amazonSpecificPattern = Pattern(
        SeqOperator([QItem("AMZN", "a")]),
        EqFormula(IdentifierTerm("a", lambda x: x["Peak Price"]),
                  AtomicTerm(73)))
    runTest('amazonSpecific', [amazonSpecificPattern], createTestFile)
Ejemplo n.º 3
0
def frequencyTailoredPatternSearchTest(createTestFile=False):
    pattern = Pattern(
        SeqOperator(
            [QItem("DRIV", "a"),
             QItem("MSFT", "b"),
             QItem("CBRL", "c")]),
        AndFormula(
            GreaterThanFormula(
                IdentifierTerm("a", lambda x: x["Opening Price"]),
                IdentifierTerm("b", lambda x: x["Opening Price"])),
            GreaterThanFormula(
                IdentifierTerm("b", lambda x: x["Opening Price"]),
                IdentifierTerm("c", lambda x: x["Opening Price"]))),
        timedelta.max)
    frequencyDict = {"MSFT": 256, "DRIV": 257, "CBRL": 1}
    pattern.setAdditionalStatistics(StatisticsTypes.FREQUENCY_DICT,
                                    frequencyDict)
    runTest('frequencyTailored1', [pattern], createTestFile,
            AscendingFrequencyAlgorithm(), nasdaqEventStream)
Ejemplo n.º 4
0
def hierarchyPatternSearchTest(createTestFile=False):
    """
    The following pattern is looking for Amazon < Apple < Google cases in one minute windows.
    PATTERN AND(AmazonStockPriceUpdate a, AppleStockPriceUpdate b, GoogleStockPriceUpdate c)
    WHERE a.PeakPrice < b.PeakPrice AND b.PeakPrice < c.PeakPrice
    WITHIN 1 minute
    """
    hierarchyPattern = Pattern(
        AndOperator(
            [QItem("AMZN", "a"),
             QItem("AAPL", "b"),
             QItem("GOOG", "c")]),
        AndFormula(
            SmallerThanFormula(IdentifierTerm("a", lambda x: x["Peak Price"]),
                               IdentifierTerm("b", lambda x: x["Peak Price"])),
            SmallerThanFormula(IdentifierTerm("b", lambda x: x["Peak Price"]),
                               IdentifierTerm("c",
                                              lambda x: x["Peak Price"]))),
        timedelta(minutes=1))
    runTest('hierarchy', [hierarchyPattern], createTestFile)
Ejemplo n.º 5
0
def googleAscendPatternSearchTest(createTestFile=False):
    """
    This pattern is looking for a short ascend in the Google peak prices.
    PATTERN SEQ(GoogleStockPriceUpdate a, GoogleStockPriceUpdate b, GoogleStockPriceUpdate c)
    WHERE a.PeakPrice < b.PeakPrice AND b.PeakPrice < c.PeakPrice
    WITHIN 3 minutes
    """
    googleAscendPattern = Pattern(
        SeqOperator(
            [QItem("GOOG", "a"),
             QItem("GOOG", "b"),
             QItem("GOOG", "c")]),
        AndFormula(
            SmallerThanFormula(IdentifierTerm("a", lambda x: x["Peak Price"]),
                               IdentifierTerm("b", lambda x: x["Peak Price"])),
            SmallerThanFormula(IdentifierTerm("b", lambda x: x["Peak Price"]),
                               IdentifierTerm("c",
                                              lambda x: x["Peak Price"]))),
        timedelta(minutes=3))
    runTest('googleAscend', [googleAscendPattern], createTestFile)
Ejemplo n.º 6
0
def frequencyPatternSearch2Test(createTestFile=False):
    pattern = Pattern(
        SeqOperator(
            [QItem("LOCM", "a"),
             QItem("AMZN", "b"),
             QItem("AAPL", "c")]),
        AndFormula(
            SmallerThanFormula(
                IdentifierTerm("a", lambda x: x["Opening Price"]),
                IdentifierTerm("b", lambda x: x["Opening Price"])),
            SmallerThanFormula(
                IdentifierTerm("b", lambda x: x["Opening Price"]),
                IdentifierTerm("c", lambda x: x["Opening Price"]))),
        timedelta(minutes=5))
    pattern.setAdditionalStatistics(StatisticsTypes.FREQUENCY_DICT, {
        "AAPL": 2,
        "AMZN": 3,
        "LOCM": 1
    })
    runTest("frequency2", [pattern], createTestFile,
            AscendingFrequencyAlgorithm())
Ejemplo n.º 7
0
def simplePatternSearchTest(createTestFile=False):
    """
    PATTERN SEQ(AppleStockPriceUpdate a, AmazonStockPriceUpdate b, AvidStockPriceUpdate c)
    WHERE   a.OpeningPrice > b.OpeningPrice
        AND b.OpeningPrice > c.OpeningPrice
    WITHIN 5 minutes
    """
    pattern = Pattern(
        SeqOperator(
            [QItem("AAPL", "a"),
             QItem("AMZN", "b"),
             QItem("AVID", "c")]),
        AndFormula(
            GreaterThanFormula(
                IdentifierTerm("a", lambda x: x["Opening Price"]),
                IdentifierTerm("b", lambda x: x["Opening Price"])),
            GreaterThanFormula(
                IdentifierTerm("b", lambda x: x["Opening Price"]),
                IdentifierTerm("c", lambda x: x["Opening Price"]))),
        timedelta(minutes=5))
    runTest("simple", [pattern], createTestFile)
Ejemplo n.º 8
0
def zStreamPatternSearchTest(createTestFile=False):
    pattern = Pattern(
        SeqOperator([
            QItem("MSFT", "a"),
            QItem("DRIV", "b"),
            QItem("ORLY", "c"),
            QItem("CBRL", "d")
        ]),
        AndFormula(
            AndFormula(
                SmallerThanFormula(
                    IdentifierTerm("a", lambda x: x["Peak Price"]),
                    IdentifierTerm("b", lambda x: x["Peak Price"])),
                SmallerThanFormula(
                    IdentifierTerm("b", lambda x: x["Peak Price"]),
                    IdentifierTerm("c", lambda x: x["Peak Price"]))),
            SmallerThanFormula(IdentifierTerm("c", lambda x: x["Peak Price"]),
                               IdentifierTerm("d",
                                              lambda x: x["Peak Price"]))),
        timedelta(minutes=3))
    selectivityMatrix = [[1.0, 0.9457796098355941, 1.0, 1.0],
                         [0.9457796098355941, 1.0, 0.15989723367389616, 1.0],
                         [1.0, 0.15989723367389616, 1.0, 0.9992557393942864],
                         [1.0, 1.0, 0.9992557393942864, 1.0]]
    arrivalRates = [
        0.016597077244258872, 0.01454418928322895, 0.013917884481558803,
        0.012421711899791231
    ]
    pattern.setAdditionalStatistics(
        StatisticsTypes.SELECTIVITY_MATRIX_AND_ARRIVAL_RATES,
        (selectivityMatrix, arrivalRates))
    runTest('zstream1', [pattern], createTestFile, ZStreamAlgorithm(),
            nasdaqEventStream)
Ejemplo n.º 9
0
def nonsensePatternSearchTest(createTestFile=False):
    """
    This pattern is looking for something that does not make sense.
    PATTERN AND(AmazonStockPriceUpdate a, AvidStockPriceUpdate b, AppleStockPriceUpdate c)
    WHERE a.PeakPrice < b.PeakPrice AND b.PeakPrice < c.PeakPrice AND c.PeakPrice < a.PeakPrice
    """
    nonsensePattern = Pattern(
        AndOperator(
            [QItem("AMZN", "a"),
             QItem("AVID", "b"),
             QItem("AAPL", "c")]),
        AndFormula(
            SmallerThanFormula(IdentifierTerm("a", lambda x: x["Peak Price"]),
                               IdentifierTerm("b", lambda x: x["Peak Price"])),
            AndFormula(
                SmallerThanFormula(
                    IdentifierTerm("b", lambda x: x["Peak Price"]),
                    IdentifierTerm("c", lambda x: x["Peak Price"])),
                SmallerThanFormula(
                    IdentifierTerm("c", lambda x: x["Peak Price"]),
                    IdentifierTerm("a", lambda x: x["Peak Price"])))),
        timedelta(minutes=1))
    runTest('nonsense', [nonsensePattern], createTestFile)
Ejemplo n.º 10
0
def oneArgumentsearchTest(createTestFile=False):
    pattern = Pattern(
        SeqOperator([QItem("AAPL", "a")]),
        GreaterThanFormula(IdentifierTerm("a", lambda x: x["Opening Price"]),
                           AtomicTerm(135)), timedelta.max)
    runTest("one", [pattern], createTestFile)