Exemplo n.º 1
0
def main(argv=None):
    parser = argparse.ArgumentParser(description="Stock Gravity.")
    parser.add_argument("SID", type=str, metavar="Stock-ID", help="Stock-ID, e.g. 1301.TW, 6121.TWO, ^TWII")
    parser.add_argument(
        "--years", type=int, default=2, choices=xrange(1, 11), help="Years to show, in range 1-10, default: 2"
    )
    parser.add_argument(
        "--form",
        type=str,
        default="Google",
        choices=["Google", "Highstock"],
        help="Display in {Google | Highstock} form, default: Google",
    )
    parser.add_argument(
        "--month", type=int, default=22, choices=xrange(1, 32), help="Work-days of a month, default: 22"
    )
    parser.add_argument(
        "--quarter", type=int, default=65, choices=range(31, 92), help="Work-days of a quarter, default: 65"
    )
    parser.add_argument("--yahoo", action="store_true", help="Fetch data from Yahoo!")
    parser.add_argument("--m20", action="store_true", help="Draw mean of 20-work-days")
    parser.add_argument("--m60", action="store_true", help="Draw mean of 60-work-days")
    parser.add_argument("--rg", type=float, default=10, help="Rate of gravity range in percent. 0-50 (%%)")
    # Test case
    #    args = parser.parse_args('1301.TW --year 5 --form Highstock'.split())
    args = parser.parse_args()
    if args.rg < 0 or args.rg > 50:
        parser.parse_args("-h".split())
        return

    d = fetchStockData(stockId=args.SID, years=args.years)
    if args.yahoo:
        d.fetchData("Yahoo")
    else:
        d.fetchData()

    if len(d.stockData) < 120:
        print u"Too few data for decision-making: %d" % len(d.stockData)
    else:
        if d.stockCat != "":
            sID = str(d.stockNum) + "." + d.stockCat
        else:
            sID = d.stockId
        h = genSGHtml(
            stockId=sID,
            stockName=d.stockName,
            stockIndProp=d.stockIndProp,
            wm=args.month,
            wq=args.quarter,
            m20=args.m20,
            m60=args.m60,
            rg=args.rg,
        )
        h.genHtml(d.stockData, args.form)

    return
Exemplo n.º 2
0
def main(argv=None):
    parser = argparse.ArgumentParser(description='Stock Gravity.')
    parser.add_argument('SID', type=str, metavar='Stock-ID',
                        help="Stock-ID, e.g. 1301.TW, 6121.TWO, ^TWII")
    parser.add_argument('--years', type=int, default=2,
                        choices=xrange(1,11),
                        help="Years to show, in range 1-10, default: 2")
    parser.add_argument('--form', type=str, default='Google',
                        choices=['Google', 'Highstock'],
                        help="Display in {Google | Highstock} form, default: Google")
    parser.add_argument('--month', type=int, default=22,
                        choices=xrange(1,32),
                        help="Work-days of a month, default: 22")
    parser.add_argument('--quarter', type=int, default=65,
                        choices=range(31,92),
                        help="Work-days of a quarter, default: 65")
    parser.add_argument('--yahoo', action='store_true',
                        help="Fetch data from Yahoo!")
    parser.add_argument('--m20', action='store_true',
                        help="Draw mean of 20-work-days")
    parser.add_argument('--m60', action='store_true',
                        help="Draw mean of 60-work-days")
    parser.add_argument('--rg', type=float, default=10,
                        help="Rate of gravity range in percent. 0-50 (%%)")
    # Test case
    #    args = parser.parse_args('1301.TW --year 5 --form Highstock'.split())
    args = parser.parse_args()
    if args.rg < 0 or args.rg > 50:
        parser.parse_args('-h'.split())
        return

    d = fetchStockData(stockId = args.SID, years=args.years)
    if args.yahoo:
        d.fetchData('Yahoo')
    else:
        d.fetchData()

    if len(d.stockData) < 120:
        print u'Too few data for decision-making: %d' % len(d.stockData)
    else:
        if d.stockCat != '':
            sID = str(d.stockNum) + '.' + d.stockCat
        else:
            sID = d.stockId
        h = genSGHtml(stockId = sID,
                      stockName = d.stockName,
                      stockIndProp = d.stockIndProp,
                      wm = args.month, wq = args.quarter,
                      m20=args.m20, m60=args.m60,
                      rg=args.rg)
        h.genHtml(d.stockData, args.form)

    return
Exemplo n.º 3
0
def testCase():
    d = fetchStockData(stockId="1301.TW", years=2)
    # 'Yahoo', 'TW', 'TWO'
    d.fetchData("TW")
    h = genSGHtml(d.stockId)
    h.genHtml(d.stockData, "Google")
Exemplo n.º 4
0
    def OnbtnShowIt(self, e):
        sID = self.StockID.GetValue()
        #wx.MessageBox(str(sID), 'Info', wx.OK | wx.ICON_INFORMATION)
        if len(sID) == 0:
            wx.MessageBox('Invalid stock ID, e.g. 1301.TW', 'Error',
                          wx.OK | wx.ICON_INFORMATION)
            return

        self.btnShowIt.SetLabel('In Progress')
        self.btnShowIt.Disable()
        try:
            # Fetcing data
            stkData = fetchStockData(
                stockId=sID,
                years=(self.choice_Year.GetCurrentSelection() + 1))
            if self.SG_Server.GetSelection() == 0:
                # By end-notation
                stkData.fetchData()
            else:
                # Yahoo
                stkData.fetchData('Yahoo')

            if len(stkData.stockData) < 120:
                wx.MessageBox(
                    'Too few data for decision-making: ' +
                    str(len(stkData.stockData)), 'Error',
                    wx.OK | wx.ICON_INFORMATION)
                self.btnShowIt.SetLabel('Show it')
                self.btnShowIt.Enable()
                return
            else:
                if stkData.stockId[0] == '^':
                    sID = stkData.stockId
                else:
                    sID = str(stkData.stockNum) + '.' + stkData.stockCat
                # Generate Stock-Gravity HTML
                stkHtml = genSGHtml(stockId=sID,
                                    stockName=stkData.stockName,
                                    stockIndProp=stkData.stockIndProp,
                                    wm=self.SpinCtrl_WM.GetValue(),
                                    wq=self.SpinCtrl_WQ.GetValue())
                if self.SG_Chart.GetSelection() == 0:
                    # Google
                    stkHtml.genHtml(stockData=stkData.stockData, form='Google')
                else:
                    # Highstock
                    stkHtml.genHtml(stockData=stkData.stockData,
                                    form='Highstock')
                hName = stkHtml.HtmlName
        except:
            wx.MessageBox('Invalid stock ID, e.g. 1301.TW', 'Error',
                          wx.OK | wx.ICON_INFORMATION)
            self.btnShowIt.SetLabel('Show it')
            self.btnShowIt.Enable()
            return

        if hName == None:
            wx.MessageBox('Invalid stock ID, e.g. 1301.TW', 'Error',
                          wx.OK | wx.ICON_INFORMATION)
            self.btnShowIt.SetLabel('Show it')
            self.btnShowIt.Enable()
            return

        if os.path.exists(self.html_dst) != True:
            os.makedirs(self.html_dst)
        #print hName
        shutil.copyfile(hName, self.html_dst + '/' + hName)
        os.remove(hName)
        if platform.system() == 'Windows':
            fn = os.getcwd() + '\\' + self.html_dst + '\\' + hName
        else:
            fn = os.getcwd() + '/' + self.html_dst + '/' + hName
        #print fn
        webbrowser.open_new_tab(fn)

        del stkData
        del stkHtml
        self.btnShowIt.SetLabel('Show it')
        self.btnShowIt.Enable()
        e.Skip()
Exemplo n.º 5
0
    def OnbtnShowIt(self, e):
        sID = self.StockID.GetValue()
        #wx.MessageBox(str(sID), 'Info', wx.OK | wx.ICON_INFORMATION)
        if len(sID) == 0:
            wx.MessageBox('Invalid stock ID, e.g. 1301.TW', 'Error', wx.OK | wx.ICON_INFORMATION)
            return

        self.btnShowIt.SetLabel('In Progress')
        self.btnShowIt.Disable()
        try:
            # Fetcing data
            stkData = fetchStockData(stockId = sID,
                                     years=(self.choice_Year.GetCurrentSelection() +1))
            if self.SG_Server.GetSelection() == 0:
                # By end-notation
                stkData.fetchData()
            else:
                # Yahoo
                stkData.fetchData('Yahoo')

            if len(stkData.stockData) < 120:
                wx.MessageBox('Too few data for decision-making: ' + str(len(stkData.stockData)),
                              'Error', wx.OK | wx.ICON_INFORMATION)
                self.btnShowIt.SetLabel('Show it')
                self.btnShowIt.Enable()
                return
            else:
                if stkData.stockId[0] == '^':
                    sID = stkData.stockId
                else:
                    sID = str(stkData.stockNum) + '.' + stkData.stockCat
                # Generate Stock-Gravity HTML
                stkHtml = genSGHtml(stockId = sID,
                                    stockName = stkData.stockName,
                                    stockIndProp = stkData.stockIndProp,
                                    wm = self.SpinCtrl_WM.GetValue(),
                                    wq = self.SpinCtrl_WQ.GetValue())
                if self.SG_Chart.GetSelection() == 0:
                    # Google
                    stkHtml.genHtml(stockData = stkData.stockData, form = 'Google')
                else:
                    # Highstock
                    stkHtml.genHtml(stockData = stkData.stockData, form = 'Highstock')
                hName = stkHtml.HtmlName
        except:
            wx.MessageBox('Invalid stock ID, e.g. 1301.TW', 'Error', wx.OK | wx.ICON_INFORMATION)
            self.btnShowIt.SetLabel('Show it')
            self.btnShowIt.Enable()
            return

        if hName == None:
            wx.MessageBox('Invalid stock ID, e.g. 1301.TW', 'Error', wx.OK | wx.ICON_INFORMATION)
            self.btnShowIt.SetLabel('Show it')
            self.btnShowIt.Enable()
            return

        if os.path.exists(self.html_dst) != True:
            os.makedirs(self.html_dst)
        #print hName
        shutil.copyfile(hName, self.html_dst+'/' + hName)
        os.remove(hName)
        if platform.system() == 'Windows':
            fn = os.getcwd() + '\\' + self.html_dst + '\\' + hName
        else:
            fn = os.getcwd() + '/' + self.html_dst + '/' + hName
        #print fn
        webbrowser.open_new_tab(fn)

        del stkData
        del stkHtml
        self.btnShowIt.SetLabel('Show it')
        self.btnShowIt.Enable()
        e.Skip()
Exemplo n.º 6
0
def testCase():
    d = fetchStockData(stockId = '1301.TW', years = 2)
    # 'Yahoo', 'TW', 'TWO'
    d.fetchData('TW')
    h = genSGHtml(d.stockId)
    h.genHtml(d.stockData, 'Google')