Пример #1
0
def generate_reports(report_id, reports_folder, temps_folder, temp_file, data=None):
    '''Given a report ID and format it returns a report
    '''

    code = 200
    msg = None
    filename = None

    # Does the report exist?
    try:
        db_report = db.session.query(models.Reports).filter_by(id=report_id).one()
    except NoResultFound:
        code = 404
        msg = f"report '{report_id}' not found"
    else:
        # ... Is the report being processed?
        if db_report.processing:
            msg = f"Report '{report_id}' is being generated"
        else:
            code = 301
            # ... Do we need to generate a new report?
            if not db_report.pdf_path:
                # Set 'processing' flag to 1 to avoid others to regenerate the reports
                db.session. \
                    query(models.Reports). \
                    filter_by(id=report_id). \
                    update({'processing': 1})
                rep_gen = ReportGenerator(reports_folder=reports_folder,
                                          temps_folder=temps_folder,
                                          data=json.loads(db_report.content) if not data else data)
                rep_gen.filename = join(reports_folder, str(report_id))
                rep_gen.run(temp_file)
                filename = rep_gen.filename
                # Update paths and toggle 'processing' flag
                db.session.\
                    query(models.Reports).\
                    filter_by(id=report_id).\
                    update({'xml_path': f'{filename}.xml', 'pdf_path': f'{filename}.pdf', 'processing': 0})
                msg = f"Report {report_id} has just been generated"
            # ... or does the report exist?
            else:
                filename, *rest = db_report.pdf_path.split('.')
                msg = f"Report {report_id} is was already available"

    return {
        'code': code,
        'msg': msg,
        'filename': filename
    }
Пример #2
0
def set_tickers():
    global rg
    global tickers
    content = request.get_json()
    tickers = content['tickers']
    rfr = content['risk-free-rate']
    rg = ReportGenerator(tickers, rfr)
    return jsonify({"new_tickers": rg.tickers})
Пример #3
0
class DataCollector:
    df_cols = ['contractSymbol','expiration','type','spot','strike','BSM Value','BSM% over ask', 'lastPrice', 'bid', 'ask', 'B/E','d% for BE','openInterest','Delta','Gamma','Theta','Vega','Rho','impliedVolatility', 'Annual Vol']
    """
    Tickers: list of tickers who's options you want to trade
    filename: output csv
    rfr: risk free rate
    """
    def __init__(self,tickers,filename,rfr,last_expiry_date=None):
        self.tickers = tickers
        self.filename = filename
        self.rfr = rfr
        self.rg = ReportGenerator(tickers,rfr)
        self.end_expiry = last_expiry_date
    
    def update(self,percent_above_below):
        print("gathering below ATM")
        below_ATM = self.rg.get_ATM_multi_report_plus_x_percent(percent_above_below,self.end_expiry)
        print("gathering above ATM")
        above_ATM = self.rg.get_ATM_multi_report_plus_x_percent(percent_above_below,self.end_expiry)
        print("gathering ATM")
        ATM = self.rg.get_ATM_multi_report(self.end_expiry)

        print('retrieval complete')
        below_ATM['Date Retrieved'] = [datetime.now() for i in range(len(below_ATM.index))]
        above_ATM['Date Retrieved'] = [datetime.now() for i in range(len(above_ATM.index))]
        ATM['Date Retrieved'] = [datetime.now() for i in range(len(ATM.index))]

        try:
            existing_data = pd.read_csv(self.filename)
        except pd.errors.EmptyDataError:
            existing_data = pd.DataFrame()

        existing_data = existing_data.append(below_ATM)
        existing_data = existing_data.append(above_ATM)
        existing_data = existing_data.append(ATM)

        existing_data = existing_data[self.df_cols]
        existing_data = existing_data.reset_index(drop=True)
        existing_data.to_csv(self.filename)
Пример #4
0
def rep_gen(tmp_path):
    temp_reports = tmp_path / 'reports'
    temp_reports.mkdir()
    _rep_gen=ReportGenerator(reports_folder=temp_reports, temps_folder=test_utils.TEMPLATE_FOLDER, data=test_utils.data)
    _rep_gen.filename = join(temp_reports, str(uuid.uuid4()).replace('-', ''))
    return _rep_gen
Пример #5
0
from datetime import date

from src.report_generator import ReportGenerator

datafile = 'data/bonds.csv'
eval_date = date(2020, 11, 30)

report = ReportGenerator(datafile, eval_date)
Пример #6
0
def test(tkrs):
    tic = time.perf_counter()
    rg = ReportGenerator(tkrs,rfr)
    report_atm = rg.get_ATM_multi_report()
    toc = time.perf_counter()
    return (toc-tic,len(report_atm.index),len(tkrs))
Пример #7
0
def specified_strikes_and_expirations():
    strikes = {'AAPL': 140, 'GOOG': 2200, 'NVDA': 610}
    expr_date = "2021-09-17"
    rg = ReportGenerator(tickers, 0.012)
    rg.get_report(expr_date, strikes).to_csv("outputfilename.csv")
Пример #8
0
def ATM_strikes_plus_relative_x_no_expirations():
    rg = ReportGenerator(tickers, 0.012)
    rg.get_ATM_multi_report_plus_x_percent(.10).to_csv("outputfilename.csv")
Пример #9
0
def ATM_strikes_plus_absolute_x_no_expirations():
    rg = ReportGenerator(tickers, 0.012)
    rg.get_ATM_multi_report_plus_x(10).to_csv("outputfilename.csv")
Пример #10
0
def ATM_strikes_plus_relative_x_with_expirations():
    expr_date = "2021-09-17"
    rg = ReportGenerator(tickers, 0.012)
    rg.get_ATM_plus_x_percent(expr_date, .10).to_csv("outputfilename.csv")
Пример #11
0
def ATM_strikes_no_expiration():
    rg = ReportGenerator(tickers, 0.012)
    rg.get_ATM_multi_report().to_csv("outputfilename.csv")
Пример #12
0
def ATM_strikes_with_expiration():
    expr_date = "2021-09-17"
    rg = ReportGenerator(tickers, 0.012)
    rg.get_ATM_report(expr_date).to_csv("outputfilename.csv")
Пример #13
0
def specified_strikes_no_expirations():
    strikes = {'AAPL': 140, 'GOOG': 2200, 'NVDA': 610}
    rg = ReportGenerator(tickers, 0.012)
    rg.get_multi_expiration_report(strikes).to_csv("outputfilename.csv")
Пример #14
0
 def __init__(self,tickers,filename,rfr,last_expiry_date=None):
     self.tickers = tickers
     self.filename = filename
     self.rfr = rfr
     self.rg = ReportGenerator(tickers,rfr)
     self.end_expiry = last_expiry_date
Пример #15
0
from src.report_generator import ReportGenerator
import time
from datetime import date
if __name__ == '__main__':
    tickers = [
        'AAPL', 'AMD'
    ]  # 'AMGN', 'AMZN', 'CSCO', 'FB', 'GOOG','IBM', 'INTC', 'MSFT', 'MU', 'NFLX', 'NVDA', 'SHOP']

    rfr = 0.012  # risk free rate
    #lower and upper date cutoffs
    expr_begin = "2021-03-01"
    expr_end = "2021-05-03"
    # initialize report generator for tickers
    report = ReportGenerator(tickers,
                             rfr).get_ATM_multi_report(dateRange=(expr_begin,
                                                                  expr_end))
    print(report)
    # ReportGenerator(tickers, rfr).get_ATM_multi_report_plus_x_percent(-.4,(None,endDate)).to_csv('reports/report_ATM_-40%_' + str(date.today())+'.csv')