-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_graph.py
More file actions
39 lines (31 loc) · 1.04 KB
/
get_graph.py
File metadata and controls
39 lines (31 loc) · 1.04 KB
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
import pandas as pd
import yfinance as yf
from yahoo_earnings_calendar import YahooEarningsCalendar
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler, MinMaxScaler
import pandas as pd
import numpy as np
import math
import datetime
import json
def get_graph(kode_saham):
ticker = yf.Ticker(kode_saham)
csv_data = ticker.history(period="max")
csv_data.head()
# Create the data
csv_data['Date'] = csv_data.index
graph_date = list(csv_data['Date'].values.flat)
graph_close = list(csv_data['Close'].values.flat)
graph = []
for i, j in zip(graph_date, graph_close):
graph.append(
{
"tanggal": (pd.to_datetime(str(i)) + datetime.timedelta(days = 1)).strftime('%Y-%m-%d'),
"harga_penutupan": float(j)
}
)
#graph = [(pd.to_datetime(str(i)) + datetime.timedelta(days = 1)).strftime('%Y-%m-%d') for i in graph]
#list_actual = [float(i) for i in graph]
return {
"grafik": graph
}