forked from lab/TPM
parent
9e7c4c973b
commit
645fb069fd
9 changed files with 51 additions and 61 deletions
File diff suppressed because one or more lines are too long
@ -1,36 +0,0 @@ |
||||
import psycopg2 |
||||
import yfinance as yf |
||||
import numpy as np |
||||
from psycopg2.extensions import register_adapter, AsIs |
||||
psycopg2.extensions.register_adapter(np.int64, psycopg2._psycopg.AsIs) |
||||
|
||||
ticker = 'SPY' |
||||
start = '2011-8-1' |
||||
end = '2021-9-1' |
||||
stock_data = yf.download(ticker, start=start, end=end ) |
||||
stock_data.index = np.datetime_as_string(stock_data.index, unit='D') |
||||
print(stock_data.index) |
||||
stock_data['Ticker'] = ticker |
||||
stock_data = stock_data.rename(columns={"Adj Close": "Adj_Close"}) |
||||
column = ["Open" , "High" , "Low" , "Close" , "Volume"] |
||||
stock_data = stock_data.drop(column, axis=1) |
||||
records = stock_data.to_records(index=True) |
||||
print(records) |
||||
|
||||
conn = psycopg2.connect( |
||||
database="profolio_platform", user='postgres', password='password', host='db',port ='5432' |
||||
) |
||||
conn.autocommit = True |
||||
cur = conn.cursor() |
||||
# print(stock_data["Date"]) |
||||
# print(stock_data["Adj_Close"]) |
||||
# print(stock_data["Ticker"]) |
||||
# print(type(stock_data["Date"])) |
||||
# print(type(stock_data["Adj_Close"])) |
||||
# print(type(stock_data["Ticker"])) |
||||
query = """INSERT INTO stock_price (date,price,ticker) |
||||
VALUES (%s, %s, %s)""" |
||||
cur = conn.cursor() |
||||
cur.executemany(query, records) |
||||
conn.close() |
||||
print("Data Insert Successfully") |
||||
Loading…
Reference in new issue