Пример #1
0
        'oneWeekAgo':
        getValueFromCSV(csv, dates['oneWeekAgo'].strftime('%Y-%m-%d'), 'DATE',
                        'DGS3MO'),
        'yesterday':
        getValueFromCSV(csv, dates['yesterday'].strftime('%Y-%m-%d'), 'DATE',
                        'DGS3MO'),
        'today':
        getValueFromCSV(csv, dates['today'].strftime('%Y-%m-%d'), 'DATE',
                        'DGS3MO'),
    }

    # Send tweet
    tweet = f"US 3-Month Treasury Rate - {lastDate.strftime('%Y-%m-%d')}: {values['today']}%\n\
1d: {values['yesterday']}% ({((values['today']-values['yesterday'])/values['yesterday'])*100:.1f}%)\n\
1w: {values['oneWeekAgo']}% ({((values['today']-values['oneWeekAgo'])/values['oneWeekAgo'])*100:.1f}%)\n\
2w: {values['twoWeeksAgo']}% ({((values['today']-values['twoWeeksAgo'])/values['twoWeeksAgo'])*100:.1f}%)\n\
1m: {values['oneMonthAgo']}% ({((values['today']-values['oneMonthAgo'])/values['oneMonthAgo'])*100:.1f}%)\n\
3m: {values['threeMonthsAgo']}% ({((values['today']-values['threeMonthsAgo'])/values['threeMonthsAgo'])*100:.1f}%)\n\
3m: {values['sixMonthsAgo']}% ({((values['today']-values['sixMonthsAgo'])/values['sixMonthsAgo'])*100:.1f}%)\n\
1y: {values['oneYearAgo']}% ({((values['today']-values['oneYearAgo'])/values['oneYearAgo'])*100:.1f}%)\n\
2y: {values['twoYearsAgo']}% ({((values['today']-values['twoYearsAgo'])/values['twoYearsAgo'])*100:.1f}%)"

    notification(tweet)

else:
    print('Not updated, no new data, last data is ' +
          lastAvailableDate.strftime('%Y-%m-%d %H:%M:%S'))

# Update save file
savePickle(saveFile, lastDate)
Пример #2
0
growth_estimate = re.findall('-?[0-9]+.[0-9]', estimate)[0]
date_of_estimate_str = re.findall('—.*', estimate)[0]
date_of_estimate_str = date_of_estimate_str.replace('—','')

# Check if this estimate is newer than last available estimate
# If so, post on Twitter and update CSV
date_of_estimate = datetime.strptime(date_of_estimate_str, '%B %d, %Y')

if lastAvailableDate < date_of_estimate:
    tweet = f"US GDP Economy Now - {date_of_estimate_str}\n\
    Next qtr: {growth_estimate}%"

    notification(tweet)

    if os.path.isfile('economynow.csv'):
        with open('economynow.csv', 'a') as f:
            writer = csv.writer(f)
            writer.writerow([date_of_estimate, growth_estimate])
    else:
        with open('economynow.csv', 'w', newline='') as f:
            writer = csv.writer(f)
            writer.writerow(["date","growth_estimate"])
            writer.writerow([date_of_estimate,growth_estimate])

    # Update save file with latest estimate date
    savePickle(saveFile, date_of_estimate)

else:
    print('Not updated, no new data, last available data is ' + lastAvailableDate.strftime('%Y-%m-%d %H:%M:%S'))

    tweet = f"Smart/Dumb Money Confidence - {datetime.strftime(max(df['date']), '%Y-%m-%d')}\n\
Smart: {thisMth['smart']}\n\n\
1 mth ago: {lastMth['smart']} (MoM: {(float(lastMth['smart']) - float(thisMth['smart'])) / float(thisMth['smart']) * 100:.1f}%)\n\
1 qtr ago: {lastQtr['smart']} (QoQ: {(float(lastQtr['smart']) - float(thisMth['smart'])) / float(thisMth['smart']) * 100:.1f}%)\n\
1 yr ago: {lastYr['smart']} (YoY: {(float(lastYr['smart']) - float(thisMth['smart'])) / float(thisMth['smart']) * 100:.1f}%)\n\n\
Dumb: {thisMth['dumb']}\n\n\
1 mth ago: {lastMth['dumb']} (MoM: {(float(lastMth['dumb']) - float(thisMth['dumb'])) / float(thisMth['dumb']) * 100:.1f}%)\n\
1 qtr ago: {lastQtr['dumb']} (QoQ: {(float(lastQtr['dumb']) - float(thisMth['dumb'])) / float(thisMth['dumb']) * 100:.1f}%)\n\
1 yr ago: {lastYr['dumb']} (YoY: {(float(lastYr['dumb']) - float(thisMth['dumb'])) / float(thisMth['dumb']) * 100:.1f}%)"

    notification(tweet)

    if os.path.isfile('smart_money_confidence.csv'):
        with open('smart_money_confidence.csv', 'w') as f:
            writer = csv.writer(f)
            writer.writerow(thisMth)
    else:
        with open('smart_money_confidence.csv', 'w', newline='') as f:
            writer = csv.writer(f)
            writer.writerow(['date', 'smart', 'spy', 'dumb'])
            writer.writerows(df)

else:
    print('Not updated, no new data, last available data is ' +
          lastAvailableDate.strftime('%Y-%m-%d %H:%M:%S'))

savePickle(saveFile, max(df['date']))

print(df)
Пример #4
0
#print(date_of_sentiments) For debugging
#print(sentiments)

if lastAvailableDate < max(date_of_sentiments):
    tweet = f"NDR Crowd Sentiment - {max(date_of_sentiments).strftime('%Y-%m-%d')}\n\
    5-day MA: {sentimentAvg:.3f}\n\n"

    # Add data from each day to twee
    max_length = max(len(date_of_sentiments),len(sentiments))

    for i in range(max_length):
        tweet += f"{date_of_sentiments[i]}: {sentiments[i]:.3f}\n"

    notification(tweet)

    with open('ndr_crowd_sentiment.csv','w') as f:
        writer = csv.writer(f)

        if os.path.isfile('ndr_crowd_sentiment.csv'):
            writer.writerow(['date', 'sentiment'])

        for i in range(max_length-1, -1, -1):
            writer.writerow([date_of_sentiments[i], sentiments[i]])

    savePickle(saveFile, max(date_of_sentiments))

else:
    print('Not updated, no new data, last available data is ' + lastAvailableDate.strftime('%Y-%m-%d %H:%M:%S'))


1 yr ago: {lastYearData[1]:.2f} (YoY: {(float(newestData[1]) - float(lastYearData[1])) / float(lastYearData[1]) * 100:.1f}%)'

    notification(tweet)

    # Write CSV file
    if os.path.exists('cass_intermodal_price_index.csv'):
        df = pd.read_csv('cass_intermodal_price_index.csv')

        for month in responseJson['dataset'][
                'data']:  # if there is a datapoint ("month") that is not in csv, add it
            if month[0] not in df.index:
                df.loc[month[0]] = [month[1]]
        df.to_csv('cass_intermodal_price_index.csv')

    else:
        # add all datapoints in json to csv
        index = []
        value = []
        for month in responseJson['dataset']['data']:
            index.append(month[0])
            value.append(month[1])
        df = pd.DataFrame(index=index, columns=['value'])
        df['value'] = value
        df.to_csv('cass_intermodal_price_index.csv')

else:
    print('Not updated, no new data, last available data is ' +
          lastAvailableDate.strftime('%Y-%m-%d %H:%M:%S'))

savePickle(saveFile, newestAvailableDate)