Esempio n. 1
0
def main():
    parser = build_parser()
    options = parser.parse_args()
    if not os.path.exists("./" + config.DATA_SAVE_DIR):
        os.makedirs("./" + config.DATA_SAVE_DIR)
    if not os.path.exists("./" + config.TRAINED_MODEL_DIR):
        os.makedirs("./" + config.TRAINED_MODEL_DIR)
    if not os.path.exists("./" + config.TENSORBOARD_LOG_DIR):
        os.makedirs("./" + config.TENSORBOARD_LOG_DIR)
    if not os.path.exists("./" + config.RESULTS_DIR):
        os.makedirs("./" + config.RESULTS_DIR)

    if options.mode == "train":
        import finrl.autotrain.training

        finrl.autotrain.training.train_one()

    elif options.mode == "download_data":
        from finrl.marketdata.yahoodownloader import YahooDownloader

        df = YahooDownloader(start_date=config.START_DATE,
                             end_date=config.END_DATE,
                             ticker_list=config.DOW_30_TICKER).fetch_data()
        now = datetime.datetime.now().strftime("%Y%m%d-%Hh%M")
        df.to_csv("./" + config.DATA_SAVE_DIR + "/" + now + ".csv")
Esempio n. 2
0
def fetch_and_store(start_date=config.START_DATE,
                    end_date=None,
                    interval=None,
                    ticker_list=config.CRYPTO_TICKER):
    print("==============Start Fetching Data===========")

    df = YahooDownloader(start_date=start_date,
                         end_date=end_date
                         or datetime.utcnow().strftime("%Y-%m-%d"),
                         ticker_list=ticker_list).fetch_data()
    now = datetime.now().strftime(config.DATETIME_FMT)
    filename = f'./{config.DATA_SAVE_DIR}/{now}.csv'
    df.to_csv(filename)
    return df
Esempio n. 3
0
def main():
    parser = build_parser()
    options = parser.parse_args()

    # add following folders
    if not os.path.exists("./" + config.DATA_SAVE_DIR):
        os.makedirs("./" + config.DATA_SAVE_DIR)

    # From config.py file get following:
    # start_date
    START_DATE = config.START_DATE

    # end_date
    END_DATE = config.END_DATE

    # list of stocks#
    STOCK_LIST = config.DOW_30_TICKER

    print("All stocks used for training:", STOCK_LIST)
    print("Historical data are used from: ", START_DATE)
    print("Till end date: ", END_DATE)

    # Download and save the data in a pandas DataFrame:
    data_frame = YahooDownloader(start_date=START_DATE,
                                 end_date=END_DATE,
                                 ticker_list=STOCK_LIST).fetch_data()

    print("Data Frame shape is: ", data_frame.shape)
    print("Data Frame format is following: \n\n", data_frame.head())

    ##
    ## Save downloaded data to file
    ##
    if os.path.exists("./" + config.DATA_SAVE_DIR + "/" + options.name +
                      ".csv"):
        os.remove("./" + config.DATA_SAVE_DIR + "/" + options.name + ".csv")
        print("The download data file deleted")
    else:
        print("The download data file does not exist")

    data_frame.to_csv("./" + config.DATA_SAVE_DIR + "/" + options.name +
                      ".csv")

    print(
        "Successfuly completed the task of downloading and saving financial data."
    )