def setUpClass(self):

        Logger.pushLogData("unitTesting", __name__)
        forceWorkingDirectory()

        pyswing.database.overrideDatabase("output/TestMultipleIndicatorRule.db")
        pyswing.constants.pySwingStartDate = datetime.datetime(2013, 1, 1)

        deleteFile(pyswing.database.pySwingDatabase)

        args = "-n %s" % ("unitTesting")
        createDatabase(args.split())

        pretendDate = datetime.datetime(2015, 9, 1)
        with patch.object(Equity, "_getTodaysDate", return_value=pretendDate) as mock_method:

            self._equityCBA = Equity("WOR.AX")
            self._equityCBA.importData()

        indicatorSMA = IndicatorSMA(self._equityCBA.dataFrame(), "WOR.AX")
        indicatorSMA.updateIndicator()
Exemple #2
0
    def test_IndicatorSMA(self):

        cbaIndicatorSMA = IndicatorSMA(self._equityCBA.dataFrame(), "CBA.AX")

        dataPoint = cbaIndicatorSMA._indicatorDataFrame.ix[
            '2015-08-31 00:00:00']

        # These tests will fail if the Adjusted Close values change...
        self.assertAlmostEqual(dataPoint['SMA_5'], 72.93, 2)
        self.assertAlmostEqual(dataPoint['SMA_10'], 72.96, 2)
        self.assertAlmostEqual(dataPoint['SMA_15'], 73.78, 2)
        self.assertAlmostEqual(dataPoint['SMA_20'], 74.80, 2)
        self.assertAlmostEqual(dataPoint['SMA_50'], 77.72, 2)
        self.assertAlmostEqual(dataPoint['SMA_200'], 78.98, 2)
    def setUpClass(self):

        Logger.pushLogData("unitTesting", __name__)
        forceWorkingDirectory()

        pyswing.database.overrideDatabase(
            "output/TestMultipleIndicatorRule.db")
        pyswing.constants.pySwingStartDate = datetime.datetime(2013, 1, 1)

        deleteFile(pyswing.database.pySwingDatabase)

        args = "-n %s" % ("unitTesting")
        createDatabase(args.split())

        pretendDate = datetime.datetime(2015, 9, 1)
        with patch.object(Equity, '_getTodaysDate',
                          return_value=pretendDate) as mock_method:

            self._equityCBA = Equity("WOR.AX")
            self._equityCBA.importData()

        indicatorSMA = IndicatorSMA(self._equityCBA.dataFrame(), "WOR.AX")
        indicatorSMA.updateIndicator()
Exemple #4
0
def updateIndicators(argv):
    """
    Update Indicators.

    :param argv: Command Line Parameters.

    -n = Name

    Example:

    python -m pyswing.UpdateIndicators -n asx
    """

    Logger.log(logging.INFO, "Log Script Call", {"scope": __name__, "arguments": " ".join(argv)})
    Logger.pushLogData("script", __name__)

    marketName = ""

    try:
        shortOptions = "n:dh"
        longOptions = ["marketName=", "debug", "help"]
        opts, __ = getopt.getopt(argv, shortOptions, longOptions)
    except getopt.GetoptError as e:
        Logger.log(logging.ERROR, "Error Reading Options", {"scope": __name__, "exception": str(e)})
        usage()
        sys.exit(2)

    for opt, arg in opts:
        if opt in ("-d", "--debug"):
            Logger().setLevel(logging.DEBUG)
        elif opt in ("-h", "--help"):
            print("?")
            usage()
            sys.exit()
        elif opt in ("-n", "--marketName"):
            marketName = arg

    if marketName != "":

        pyswing.database.initialiseDatabase(marketName)

        Logger.log(logging.INFO, "Update Indicators", {"scope": __name__, "market": marketName})

        tickerCodesRelativeFilePath = "resources/%s.txt" % (marketName)

        market = Market(tickerCodesRelativeFilePath)

        # Market Indicators
        adiIndicator = IndicatorADI()
        adiIndicator.updateIndicator()

        # Equity Indicators
        for index, row in market.tickers.iterrows():
            tickerCode = row[0]
            equity = Equity(tickerCode)
            equityDataFrame = equity.dataFrame()

            smaIndicator = IndicatorSMA(equityDataFrame, tickerCode)
            smaIndicator.updateIndicator()

            emaIndicator = IndicatorEMA(equityDataFrame, tickerCode)
            emaIndicator.updateIndicator()

            bbIndicator = IndicatorBB20(equityDataFrame, tickerCode)
            bbIndicator.updateIndicator()

            rocIndicator = IndicatorROC(equityDataFrame, tickerCode)
            rocIndicator.updateIndicator()

            macdIndicator = IndicatorMACD(equityDataFrame, tickerCode)
            macdIndicator.updateIndicator()

            stochIndicator = IndicatorSTOCH(equityDataFrame, tickerCode)
            stochIndicator.updateIndicator()

            rsiIndicator = IndicatorRSI(equityDataFrame, tickerCode)
            rsiIndicator.updateIndicator()

            adxIndicator = IndicatorADX(equityDataFrame, tickerCode)
            adxIndicator.updateIndicator()

            aroonIndicator = IndicatorAROON(equityDataFrame, tickerCode)
            aroonIndicator.updateIndicator()

            dxIndicator = IndicatorDX(equityDataFrame, tickerCode)
            dxIndicator.updateIndicator()

        TeamCity.setBuildResultText("Updated Indicators")

    else:
        Logger.log(logging.ERROR, "Missing Options", {"scope": __name__, "options": str(argv)})
        usage()
        sys.exit(2)
Exemple #5
0
def updateIndicators(argv):
    """
    Update Indicators.

    :param argv: Command Line Parameters.

    -n = Name

    Example:

    python -m pyswing.UpdateIndicators -n asx
    """

    Logger.log(logging.INFO, "Log Script Call", {
        "scope": __name__,
        "arguments": " ".join(argv)
    })
    Logger.pushLogData("script", __name__)

    marketName = ""

    try:
        shortOptions = "n:dh"
        longOptions = ["marketName=", "debug", "help"]
        opts, __ = getopt.getopt(argv, shortOptions, longOptions)
    except getopt.GetoptError as e:
        Logger.log(logging.ERROR, "Error Reading Options", {
            "scope": __name__,
            "exception": str(e)
        })
        usage()
        sys.exit(2)

    for opt, arg in opts:
        if opt in ("-d", "--debug"):
            Logger().setLevel(logging.DEBUG)
        elif opt in ("-h", "--help"):
            print("?")
            usage()
            sys.exit()
        elif opt in ("-n", "--marketName"):
            marketName = arg

    if marketName != "":

        pyswing.database.initialiseDatabase(marketName)

        Logger.log(logging.INFO, "Update Indicators", {
            "scope": __name__,
            "market": marketName
        })

        tickerCodesRelativeFilePath = "resources/%s.txt" % (marketName)

        market = Market(tickerCodesRelativeFilePath)

        # Market Indicators
        adiIndicator = IndicatorADI()
        adiIndicator.updateIndicator()

        # Equity Indicators
        for index, row in market.tickers.iterrows():
            tickerCode = row[0]
            equity = Equity(tickerCode)
            equityDataFrame = equity.dataFrame()

            smaIndicator = IndicatorSMA(equityDataFrame, tickerCode)
            smaIndicator.updateIndicator()

            emaIndicator = IndicatorEMA(equityDataFrame, tickerCode)
            emaIndicator.updateIndicator()

            bbIndicator = IndicatorBB20(equityDataFrame, tickerCode)
            bbIndicator.updateIndicator()

            rocIndicator = IndicatorROC(equityDataFrame, tickerCode)
            rocIndicator.updateIndicator()

            macdIndicator = IndicatorMACD(equityDataFrame, tickerCode)
            macdIndicator.updateIndicator()

            stochIndicator = IndicatorSTOCH(equityDataFrame, tickerCode)
            stochIndicator.updateIndicator()

            rsiIndicator = IndicatorRSI(equityDataFrame, tickerCode)
            rsiIndicator.updateIndicator()

            adxIndicator = IndicatorADX(equityDataFrame, tickerCode)
            adxIndicator.updateIndicator()

            aroonIndicator = IndicatorAROON(equityDataFrame, tickerCode)
            aroonIndicator.updateIndicator()

            dxIndicator = IndicatorDX(equityDataFrame, tickerCode)
            dxIndicator.updateIndicator()

        TeamCity.setBuildResultText("Updated Indicators")

    else:
        Logger.log(logging.ERROR, "Missing Options", {
            "scope": __name__,
            "options": str(argv)
        })
        usage()
        sys.exit(2)