예제 #1
0
def pickleStock(ndays):
    symbols = md.getAllPortfoliosSymbols()
    dfnrow = getRowNDaysAgo(ndays, symbols)
    if len(dfnrow.index.values) == 0:
        print('{} {}'.format('Failed', ndays))
        raise ConnectionError('{} {}'.format('Failed', ndays))
    rdate = getRowYmdDate(dfnrow)
    dfnrow.to_pickle(getPickleName(rdate))
예제 #2
0
def getMdbRowForDate(adate,db_coll):
    try:
        mdb_data = db_coll.find({'Date': adate})[0]
    except:
        print('index error',adate)
        ndays = md.getNBusDaysFromDateStr(adate.strftime("%Y-%m-%d"))
        df = md.getRowNDaysAgo(ndays, md.getAllPortfoliosSymbols())
        mdb_data = addCloseVolumeRowToMdb(df,db_coll)
    return md.MdbToDataframeForPercent(mdb_data)
예제 #3
0
def getMissingMarketRow(ndays, db_coll, symbols):
    dbaction = None
    df = md.getNdaysRowFromMdb(ndays, db_coll)
    if df.size == 0: #missing whole row of data, missing all symbole
        missing_symbols = md.getAllPortfoliosSymbols()
        dbaction = 'ADD'
    else:
        dfs = set(df.columns)
        missing_symbols = set(symbols).difference(dfs)
        dbaction = 'UPDATE'
    if len(missing_symbols) > 0:
        return (md.getRowNDaysAgo(ndays, missing_symbols),dbaction)
    else:
        return (pd.DataFrame({}),dbaction)
예제 #4
0
from datetime import datetime
from pymongo import MongoClient
from bson import json_util
from pandas import json_normalize
import json
import pandas as pd
import market_data as md
import rh

client = MongoClient()
db = client['stock_market']
earnings_col = db['market_data_earnings']

symbols = md.getAllPortfoliosSymbols()
#symbols = ['HD','LOW','BEP','LU']
year, month, day = rh.getYearMonthDay()
current_month_dates = rh.getEarnings(symbols, year, month)
current_month_dates = filter(lambda x: x[1][8:10] >= day, current_month_dates)
df = pd.DataFrame(current_month_dates, columns=['symbol', 'earnings_date'])
df.drop_duplicates(inplace=True)

# delete current mdb records and insert new
result = earnings_col.delete_many({})
print(result.deleted_count, " documents deleted.")
try:
    result = md.addRowToMdb(df, earnings_col)
    print(len(result.inserted_ids), ' documents inserted')
except Exception as e:
    print('error ', e)
def testrowndays(ndays):
    symbols = md.getAllPortfoliosSymbols()
    df = md.getRowNDaysAgo(ndays, symbols)
    print(df)