-
Notifications
You must be signed in to change notification settings - Fork 0
/
empirical_analysis.py
40 lines (32 loc) · 1.52 KB
/
empirical_analysis.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from pandas import datetime
import helper
import numpy as np
import pandas as pd
import yahoo_finance as yf
def perform_empirical_analysis(ticker, freq, polarities):
yf.download_from_yahoo_finance([ticker], "2020-12-07",
datetime.today().strftime('%Y-%m-%d'))
file_name = ticker + "_" + freq + ".csv"
dataset = pd.read_csv(file_name)
if type(polarities) == str:
stocks = helper.itemize_emp_data(dataset)
else:
stocks = helper.itemize_pol_data(dataset, polarities)
stocks = helper.get_normalised_data(stocks)
print(stocks.head())
print("\n")
print("Open --- mean :", np.mean(stocks['Open']), " \t Std: ", np.std(stocks['Open']), " \t Max: ",
np.max(stocks['Open']), " \t Min: ", np.min(stocks['Open']))
print("Close --- mean :", np.mean(stocks['Close']), " \t Std: ", np.std(stocks['Close']), " \t Max: ",
np.max(stocks['Close']), " \t Min: ", np.min(stocks['Close']))
print("Volume --- mean :", np.mean(stocks['Volume']), " \t Std: ", np.std(stocks['Volume']), " \t Max: ",
np.max(stocks['Volume']), " \t Min: ", np.min(stocks['Volume']))
if type(polarities) != str:
print("Polarity --- mean :", np.mean(stocks['Polarity']), " \t Std: ", np.std(stocks['Polarity']),
" \t Max: ",
np.max(stocks['Polarity']), " \t Min: ", np.min(stocks['Polarity']))
# Print the dataframe head and tail
print(stocks.head())
print("---")
print(stocks.tail())
return stocks