1- from Historic_Crypto import HistoricalData
1+ rom
2+ Historic_Crypto
3+ import HistoricalData
24from datetime import datetime
35import yfinance as yf
46import talib as ta
911'''
1012
1113
12- '''
13- This functions takes a symbol for a crypto and returns it's historic data.
14-
15- Input:
16- symbol (Required) - Takes the exchanged pairs: ETH-USD or BTC_ETH, or BTC-USD
17- interval (optional) - Takes the interval of prices: 1d, 1h, 5m or 1m.
18- start_date (optional) - The earliest historic data you want in form YYYY-MM-DD-HH-SS: 2000-01-01-00-00
19- end_date (optional) - The latest historic data you want in form YYYY-MM-DD-HH-SS: 2000-01-01-00-00
20-
21- Output:
22- A data frame with the High, Low, Open, Close and Volume prices. This is the historic prices. By default it returns
23- all daily prices unless otherwise specified.
24-
25- Examples:
26- get_crypto_data('BTC-USD',interval='1h',start_date='2021-04-01-00-00')
27- get_crypto_data('BTC-USD',interval='1h',start_date='2021-04-01-00-00',end_date='2021-06-01-00-00')
28- get_crypto_data('ETH-USD')
29- '''
30- def get_crypto_data (symbol ,** kwargs ):
31- interval = kwargs .get ('interval' ,'1d' )
14+ def get_crypto_data (symbol , ** kwargs ):
15+ '''
16+ This functions takes a symbol for a crypto and returns it's historic data.
17+ Input:
18+ symbol (Required) - Takes the exchanged pairs: ETH-USD or BTC_ETH, or BTC-USD
19+ interval (optional) - Takes the interval of prices: 1d, 1h, 5m or 1m.
20+ start_date (optional) - The earliest historic data you want in form YYYY-MM-DD-HH-SS: 2000-01-01-00-00
21+ end_date (optional) - The latest historic data you want in form YYYY-MM-DD-HH-SS: 2000-01-01-00-00
22+ Output:
23+ A data frame with the High, Low, Open, Close and Volume prices. This is the historic prices. By default it returns
24+ all daily prices unless otherwise specified.
25+
26+ Examples:
27+ get_crypto_data('BTC-USD',interval='1h',start_date='2021-04-01-00-00')
28+ get_crypto_data('BTC-USD',interval='1h',start_date='2021-04-01-00-00',end_date='2021-06-01-00-00')
29+ get_crypto_data('ETH-USD')
30+ '''
31+ interval = kwargs .get ('interval' , '1d' )
3232 start_date = kwargs .get ('start_date' , '2000-01-01-00-00' )
3333 end_date = kwargs .get ('end_date' , datetime .today ().strftime ('%Y-%m-%d-%H-%M' ))
3434 seconds = 0
@@ -40,76 +40,75 @@ def get_crypto_data(symbol,**kwargs):
4040 seconds = 300
4141 elif interval == '1m' :
4242 seconds = 60
43- data = HistoricalData (symbol ,seconds ,start_date ,end_date ).retrieve_data ()
44- data = data .rename (columns = {"open" : "Open" , "high" : "High" ,"low" : "Low" , "close" : "Close" ,'volume' :'Volume' })
43+ data = HistoricalData (symbol , seconds , start_date , end_date ).retrieve_data ()
44+ data = data .rename (columns = {"open" : "Open" , "high" : "High" , "low" : "Low" , "close" : "Close" , 'volume' : 'Volume' })
4545 return data
4646
4747
48- '''
49- This functions takes a symbol for a stock and returns it's historic data.
50-
51- Input:
52- symbol (Required) - Takes the exchanged pairs: ETH-USD or BTC_ETH, or BTC-USD
53- interval (optional) - Takes the interval of prices: 1d, 1h, 5m or 1m.
54- start_date (optional) - The earliest historic data you want in form YYYY-MM-DD: 2000-01-01
55- end_date (optional) - The latest historic data you want in form YYYY-MM-DD: 2000-01-01
56- period (optional) - Instead of specifying an end_date you can specify a period: 1d, 1y, 1m, 2y
57-
58- Output:
59- A data frame with the High, Low, Open, Close and Volume prices. This is the historic prices. By default it returns
60- all daily prices unless otherwise specified.
61-
62- ** Note: yFinance is limited in what it can return in terms of intraday data so be aware.
63-
64- Examples:
65- data_source = DR.get_stock_data('DIA',interval='1d',period='2y')
66- data_source = DR.get_stock_data('AAPL',start_date='2021-04-01',end_date='2021-06-01')
67- '''
68- def get_stock_data (symbol ,** kwargs ):
69- interval = kwargs .get ('interval' ,'1d' )
48+ def get_stock_data (symbol , ** kwargs ):
49+ '''
50+ This functions takes a symbol for a stock and returns it's historic data.
51+ Input:
52+ symbol (Required) - Takes the exchanged pairs: ETH-USD or BTC_ETH, or BTC-USD
53+ interval (optional) - Takes the interval of prices: 1d, 1h, 5m or 1m.
54+ start_date (optional) - The earliest historic data you want in form YYYY-MM-DD: 2000-01-01
55+ end_date (optional) - The latest historic data you want in form YYYY-MM-DD: 2000-01-01
56+ period (optional) - Instead of specifying an end_date you can specify a period: 1d, 1y, 1m, 2y
57+ Output:
58+ A data frame with the High, Low, Open, Close and Volume prices. This is the historic prices. By default it returns
59+ all daily prices unless otherwise specified.
60+ ** Note: yFinance is limited in what it can return in terms of intraday data so be aware.
61+ Examples:
62+ data_source = DR.get_stock_data('DIA',interval='1d',period='2y')
63+ data_source = DR.get_stock_data('AAPL',start_date='2021-04-01',end_date='2021-06-01')
64+ '''
65+ interval = kwargs .get ('interval' , '1d' )
7066 start_date = kwargs .get ('start_date' , '2000-01-01' )
7167 end_date = kwargs .get ('end_date' , datetime .today ().strftime ('%Y-%m-%d' ))
7268 period = kwargs .get ('period' , None )
7369
7470 stock = yf .Ticker (symbol )
7571 if period != None :
76- return stock .history (period = period ,interval = interval )
77-
78- return stock .history (interval = interval ,start = start_date ,end = end_date )
72+ return stock .history (period = period , interval = interval )
7973
80- '''
81- This functions takes a data frame of historic data and adds the SMA to it.
74+ return stock .history (interval = interval , start = start_date , end = end_date )
8275
83- Input:
84- data (required) - A dataframe of historic data that SMA will be added to.
8576
86- Output:
87- A data frame with the SMA added.
88- Examples:
89- add_SMA(data_source)
90- '''
9177def add_SMA (data ):
78+ '''
79+ This functions takes a data frame of historic data and adds the SMA to it.
80+ Input:
81+ data (required) - A dataframe of historic data that SMA will be added to.
82+ Output:
83+ A data frame with the SMA added.
84+ Examples:
85+ add_SMA(data_source)
86+ '''
9287 # Adding SMA
9388 sma = ta .SMA (data ['Close' ])
9489 data ['SMA' ] = sma
95- data = data .iloc [29 :, :]
90+ data = data .iloc [29 :, :]
9691 return data
9792
98- '''
99- This functions takes a data frame of historic data and adds the EMA to it.
100-
101- Input:
102- data (required) - A dataframe of historic data that EMA will be added to.
10393
104- Output:
105- A data frame with the EMA added.
106- Examples:
107- add_EMA(data_source)
108- '''
10994def add_EMA (data ):
95+ '''
96+ This functions takes a data frame of historic data and adds the EMA to it.
97+ Input:
98+ data (required) - A dataframe of historic data that EMA will be added to.
99+ Output:
100+ A data frame with the EMA added.
101+ Examples:
102+ add_EMA(data_source)
103+ '''
110104 # Adding EMA
111105 ema = ta .EMA (data ['Close' ])
112106 data ['EMA' ] = ema
113- data = data .iloc [29 :, :]
107+ data = data .iloc [29 :, :]
114108 return data
115109
110+
111+ add_technical_indicators = {
112+ 'EMA' : add_EMA ,
113+ 'SMA' : add_SMA
114+ }
0 commit comments