def test_ExitValues(self):

        exitValues = ExitValuesTrailingStop("WOR.AX", 0.03, 2)
        exitValues.calculateExitValues()

        dataPointBuyWin = exitValues._buyExitValueDataFrame.ix['2015-07-02 00:00:00']
        self.assertAlmostEqual(dataPointBuyWin['ExitValue'], 1.581, 3)

        dataPointBuyLose = exitValues._buyExitValueDataFrame.ix['2015-07-13 00:00:00']
        self.assertAlmostEqual(dataPointBuyLose['ExitValue'], -1.741, 3)

        dataPointSellWin = exitValues._sellExitValueDataFrame.ix['2015-07-03 00:00:00']
        self.assertAlmostEqual(dataPointSellWin['ExitValue'], 6.000, 3)

        dataPointSellLose = exitValues._sellExitValueDataFrame.ix['2015-07-14 00:00:00']
        self.assertAlmostEqual(dataPointSellLose['ExitValue'], -4.832, 3)

        strategies = getExitStrategies()
        self.assertTrue(len(strategies) == 1)
示例#2
0
    def test_ExitValues(self):

        exitValues = ExitValuesTrailingStop("WOR.AX", 0.03, 2)
        exitValues.calculateExitValues()

        dataPointBuyWin = exitValues._buyExitValueDataFrame.ix[
            '2015-07-02 00:00:00']
        self.assertAlmostEqual(dataPointBuyWin['ExitValue'], 1.581, 3)

        dataPointBuyLose = exitValues._buyExitValueDataFrame.ix[
            '2015-07-13 00:00:00']
        self.assertAlmostEqual(dataPointBuyLose['ExitValue'], -1.741, 3)

        dataPointSellWin = exitValues._sellExitValueDataFrame.ix[
            '2015-07-03 00:00:00']
        self.assertAlmostEqual(dataPointSellWin['ExitValue'], 6.000, 3)

        dataPointSellLose = exitValues._sellExitValueDataFrame.ix[
            '2015-07-14 00:00:00']
        self.assertAlmostEqual(dataPointSellLose['ExitValue'], -4.832, 3)

        strategies = getExitStrategies()
        self.assertTrue(len(strategies) == 1)
示例#3
0
def calculateExitValues(argv):
    """
    Calculate Exit Values.

    :param argv: Command Line Parameters.

    -n = Name

    Example:

    python -m pyswing.CalculateExitValues -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, "Calculate Exit Values", {"scope":__name__, "market":marketName})

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

        market = Market(tickerCodesRelativeFilePath)

        for index, row in market.tickers.iterrows():
            tickerCode = row[0]

            exitValuesTrailingStop3 = ExitValuesTrailingStop(tickerCode, 0.03, 2)
            exitValuesTrailingStop3.calculateExitValues()

            # exitValuesTrailingStop2 = ExitValuesTrailingStop(tickerCode, 0.02, 3)
            # exitValuesTrailingStop2.calculateExitValues()
            #
            # exitValuesYesterday2 = ExitValuesYesterday(tickerCode, 0.02, 3)
            # exitValuesYesterday2.calculateExitValues()
            #
            # exitValuesYesterday3 = ExitValuesYesterday(tickerCode, 0.03, 2)
            # exitValuesYesterday3.calculateExitValues()

        TeamCity.setBuildResultText("Calculated Exit Values")

    else:
        Logger.log(logging.ERROR, "Missing Options", {"scope": __name__, "options": str(argv)})
        usage()
        sys.exit(2)
示例#4
0
def calculateExitValues(argv):
    """
    Calculate Exit Values.

    :param argv: Command Line Parameters.

    -n = Name

    Example:

    python -m pyswing.CalculateExitValues -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, "Calculate Exit Values", {
            "scope": __name__,
            "market": marketName
        })

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

        market = Market(tickerCodesRelativeFilePath)

        for index, row in market.tickers.iterrows():
            tickerCode = row[0]

            exitValuesTrailingStop3 = ExitValuesTrailingStop(
                tickerCode, 0.03, 2)
            exitValuesTrailingStop3.calculateExitValues()

            # exitValuesTrailingStop2 = ExitValuesTrailingStop(tickerCode, 0.02, 3)
            # exitValuesTrailingStop2.calculateExitValues()
            #
            # exitValuesYesterday2 = ExitValuesYesterday(tickerCode, 0.02, 3)
            # exitValuesYesterday2.calculateExitValues()
            #
            # exitValuesYesterday3 = ExitValuesYesterday(tickerCode, 0.03, 2)
            # exitValuesYesterday3.calculateExitValues()

        TeamCity.setBuildResultText("Calculated Exit Values")

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