コード例 #1
0
def OpportunityFinder(tickerList: list):
    outputFolder = 'data/dailypicks/'
    summaryFile = '_summary.txt'
    overBoughtList = []
    oversoldList = []
    highDeviationList = []
    for root, dirs, files in os.walk(outputFolder):
        for f in files:
            if f.endswith('.txt') or f.endswith('.png'):
                os.unlink(os.path.join(root, f))

    for ticker in tickerList:
        prices = PricingData(ticker)
        print('Checking ' + ticker)
        if prices.LoadHistory(True):
            prices.CalculateStats()
            psnap = prices.GetCurrentPriceSnapshot()
            titleStatistics = ' 5/15 dev: ' + str(
                round(psnap.fiveDayDeviation * 100, 2)) + '/' + str(
                    round(psnap.fifteenDayDeviation * 100, 2)) + '% ' + str(
                        psnap.low) + '/' + str(
                            psnap.nextDayTarget) + '/' + str(
                                psnap.high) + str(snapshotDate)
            if psnap.low > psnap.channelHigh:
                overBoughtList.append(ticker)
            if psnap.high < psnap.channelLow:
                oversoldList.append(ticker)
                prices.GraphData(None, 60, ticker + ' 60d ' + titleStatistics,
                                 False, True, '60d', outputFolder)
            if psnap.fiveDayDeviation > .0275:
                highDeviationList.append(ticker)
                prices.GraphData(None, 60, ticker + ' 60d ' + titleStatistics,
                                 False, True, '60d', outputFolder)
    print('Over bought:')
    print(overBoughtList)
    print('Over sold:')
    print(oversoldList)
    print('High deviation:')
    print(highDeviationList)
    f = open(outputFolder + summaryFile, 'w')
    f.write('Over bought:\n')
    for t in overBoughtList:
        f.write(t + '\n')
    f.write('\nOver sold:\n')
    for t in oversoldList:
        f.write(t + '\n')
    f.write('\nHigh deviation:\n')
    for t in highDeviationList:
        f.write(t + '\n')
    f.close()
コード例 #2
0
def DownloadAndGraphStocks(tickerList: list):
    for ticker in tickerList:
        prices = PricingData(ticker)
        print('Loading ' + ticker)
        if prices.LoadHistory(True):
            print('Calcualting stats ' + ticker)
            prices.NormalizePrices()
            prices.CalculateStats()
            prices.PredictPrices(2, 15)
            prices.NormalizePrices()
            prices.SaveStatsToFile(True)
            psnap = prices.GetCurrentPriceSnapshot()
            titleStatistics = ' 5/15 dev: ' + str(
                round(psnap.fiveDayDeviation * 100, 2)) + '/' + str(
                    round(psnap.fifteenDayDeviation * 100, 2)) + '% ' + str(
                        psnap.low) + '/' + str(
                            psnap.nextDayTarget) + '/' + str(
                                psnap.high) + ' ' + str(
                                    psnap.snapshotDate)[:10]
            print('Graphing ' + ticker + ' ' + str(psnap.snapshotDate)[:10])
            for days in [90, 180, 365, 2190, 4380]:
                prices.GraphData(None,
                                 days,
                                 ticker + '_days' + str(days) + ' ' +
                                 titleStatistics, (days < 1000),
                                 True,
                                 str(days).rjust(4, '0') + 'd',
                                 trimHistoricalPredictions=False)
コード例 #3
0
def DownloadAndGraphStocks(tickerList: list):
    for ticker in tickerList:
        prices = PricingData(ticker)
        print('Loading ' + ticker)
        if prices.LoadHistory(requestedEndDate=GetTodaysDate()):
            print('Calcualting stats ' + ticker)
            prices.NormalizePrices()
            prices.CalculateStats()
            prices.PredictPrices(2, 15)
            prices.NormalizePrices()
            #prices.SaveStatsToFile(includePredictions=True, verbose=True)
            psnap = prices.GetCurrentPriceSnapshot()
            titleStatistics = ' 5/15 dev: ' + str(
                round(psnap.fiveDayDeviation * 100, 2)) + '/' + str(
                    round(psnap.fifteenDayDeviation * 100, 2)) + '% ' + str(
                        psnap.low) + '/' + str(
                            psnap.nextDayTarget) + '/' + str(
                                psnap.high) + ' ' + str(
                                    psnap.snapShotDate)[:10]
            print('Graphing ' + ticker + ' ' + str(psnap.snapShotDate)[:10])
            for days in [90, 180, 365, 2190, 4380]:
                prices.GraphData(endDate=None,
                                 daysToGraph=days,
                                 graphTitle=ticker + '_days' + str(days) +
                                 ' ' + titleStatistics,
                                 includePredictions=(days < 1000),
                                 saveToFile=True,
                                 fileNameSuffix=str(days).rjust(4, '0') + 'd',
                                 trimHistoricalPredictions=False)
コード例 #4
0
def GraphTimePeriod(ticker: str, endDate: str, days: int):
    prices = PricingData(ticker)
    print('Loading ' + ticker)
    if prices.LoadHistory():
        prices.GraphData(endDate=endDate,
                         daysToGraph=days,
                         graphTitle=None,
                         includePredictions=False,
                         saveToFile=True,
                         fileNameSuffix=None)
        print('Chart saved to \data\charts')
コード例 #5
0
def PlotPrediction(ticker: str = '^SPX',
                   predictionMethod: int = 0,
                   daysToGraph: int = 60,
                   daysForward: int = 5,
                   learnhingEpochs: int = 500):
    print('Plotting predictions for ' + ticker)
    prices = PricingData(ticker)
    if prices.LoadHistory(True):
        prices.NormalizePrices()
        prices.PredictPrices(predictionMethod, daysForward, learnhingEpochs)
        prices.NormalizePrices()
        prices.GraphData(None, daysToGraph,
                         ticker + ' ' + str(daysToGraph) + 'days', True, True,
                         str(daysToGraph) + 'days')
        prices.SaveStatsToFile(True)
コード例 #6
0
def OpportunityFinder(tickerList: list):
    outputFolder = 'data/dailypicks/'
    summaryFile = '_DailyPicks.csv'
    candidates = pd.DataFrame(columns=list([
        'Ticker', 'hp2Year', 'hp1Year', 'hp6mo', 'hp3mo', 'hp2mo', 'hp1mo',
        'currentPrice', 'channelHigh', 'channelLow', 'shortEMA', 'longEMA',
        '2yearPriceChange', '1yearPriceChange', '6moPriceChange',
        '3moPriceChange', '2moPriceChange', '1moPriceChange', 'dailyGain',
        'monthlyGain', 'monthlyLossStd', 'Comments'
    ]))
    candidates.set_index(['Ticker'], inplace=True)
    for root, dirs, files in os.walk(outputFolder):
        for f in files:
            if f.endswith('.png'): os.unlink(os.path.join(root, f))

    for ticker in tickerList:
        prices = PricingData(ticker)
        currentDate = GetTodaysDate()
        print('Checking ' + ticker)
        if prices.LoadHistory(requestedEndDate=currentDate):
            prices.CalculateStats()
            psnap = prices.GetPriceSnapshot(AddDays(currentDate, -730))
            hp2Year = psnap.fiveDayAverage
            psnap = prices.GetPriceSnapshot(AddDays(currentDate, -365))
            hp1Year = psnap.fiveDayAverage
            psnap = prices.GetPriceSnapshot(AddDays(currentDate, -180))
            hp6mo = psnap.fiveDayAverage
            psnap = prices.GetPriceSnapshot(AddDays(currentDate, -90))
            hp3mo = psnap.fiveDayAverage
            psnap = prices.GetPriceSnapshot(AddDays(currentDate, -60))
            hp2mo = psnap.fiveDayAverage
            psnap = prices.GetPriceSnapshot(AddDays(currentDate, -30))
            hp1mo = psnap.fiveDayAverage
            psnap = prices.GetCurrentPriceSnapshot()
            currentPrice = psnap.twoDayAverage
            Comments = ''
            if psnap.low > psnap.channelHigh:
                Comments += 'OverBought; '
            if psnap.high < psnap.channelLow:
                Comments += 'OverSold; '
            if psnap.fiveDayDeviation > .0275:
                Comments += 'HighDeviation; '
            if Comments != '':
                titleStatistics = ' 5/15 dev: ' + str(
                    round(psnap.fiveDayDeviation * 100, 2)) + '/' + str(
                        round(psnap.fifteenDayDeviation * 100,
                              2)) + '% ' + str(psnap.low) + '/' + str(
                                  psnap.nextDayTarget) + '/' + str(
                                      psnap.high) + str(psnap.snapShotDate)
                prices.GraphData(None, 60, ticker + ' 60d ' + titleStatistics,
                                 False, True, '60d', outputFolder)
                if (currentPrice > 0 and hp2Year > 0 and hp1Year > 0
                        and hp6mo > 0 and hp2mo > 0
                        and hp1mo > 0):  #values were loaded
                    candidates.loc[ticker] = [
                        hp2Year, hp1Year, hp6mo, hp3mo, hp2mo, hp1mo,
                        currentPrice, psnap.channelHigh,
                        psnap.channelLow, psnap.shortEMA, psnap.longEMA,
                        (currentPrice / hp2Year) - 1,
                        (currentPrice / hp1Year) - 1,
                        (currentPrice / hp6mo) - 1, (currentPrice / hp3mo) - 1,
                        (currentPrice / hp2mo) - 1, (currentPrice / hp1mo) - 1,
                        psnap.dailyGain, psnap.monthlyGain,
                        psnap.monthlyLossStd, Comments
                    ]
                else:
                    print(ticker, currentPrice, hp2Year, hp1Year, hp6mo, hp2mo,
                          hp1mo)
    print(candidates)
    candidates.to_csv(outputFolder + summaryFile)
コード例 #7
0
def GraphTimePeriod(ticker: str, endDate: datetime, days: int):
    prices = PricingData(ticker)
    print('Loading ' + ticker)
    if prices.LoadHistory():
        prices.GraphData(endDate, days, None, False, True, None)