-
大小: 517KB文件類型: .zip金幣: 2下載: 1 次發(fā)布日期: 2021-06-17
- 語言: Python
- 標(biāo)簽:
資源簡(jiǎn)介
利用深度學(xué)習(xí)預(yù)測(cè)比特幣價(jià)格

代碼片段和文件信息
import?os
import?shutil
import?sys
from?time?import?time
from?uuid?import?uuid4
import?numpy?as?np
import?pandas?as?pd
from?data_manager?import?file_processor
from?returns_quantization?import?add_returns_in_place
from?utils?import?*
np.set_printoptions(threshold=np.nan)
pd.set_option(‘display.max_rows‘?500)
pd.set_option(‘display.max_columns‘?500)
pd.set_option(‘display.width‘?1000)
def?generate_quantiles(data_folder?bitcoin_file):
????def?get_label(btc_df?btc_slice?i?slice_size):
????????class_name?=?str(btc_df[i?+?slice_size:i?+?slice_size?+?1][‘close_price_returns_labels‘].values[0])
????????return?class_name
????return?generate_cnn_dataset(data_folder?bitcoin_file?get_label)
def?generate_up_down(data_folder?bitcoin_file):
????def?get_price_direction(btc_df?btc_slice?i?slice_size):
????????#?last_price?=?btc_slice[-2:-1][‘price_close‘].values[0]?#this?is?actually?the?second?last?price
????????last_price?=?btc_slice[-1:][‘price_close‘].values[0]?#one?option?to?get?the?correct?last?price
????????#?last_price?=?btc_df[i?+?slice_size?-?1:i?+?slice_size][‘price_close‘].values[0]?#another?option?to?get?the?correct?last?price
????????next_price?=?btc_df[i?+?slice_size:i?+?slice_size?+?1][‘price_close‘].values[0]
????????if?last_price?????????????class_name?=?‘UP‘
????????else:
????????????class_name?=?‘DOWN‘
????????return?class_name
????return?generate_cnn_dataset(data_folder?bitcoin_file?get_price_direction)
def?generate_cnn_dataset(data_folder?bitcoin_file?get_class_name):
????btc_df?=?file_processor(bitcoin_file)
????btc_df?levels?=?add_returns_in_place(btc_df)
????print(‘-‘?*?80)
????print(‘Those?values?should?be?roughly?equal?to?1/len(levels):‘)
????for?ii?in?range(len(levels)):
????????print(ii?np.mean((btc_df[‘close_price_returns_labels‘]?==?ii).values))
????print(levels)
????print(‘-‘?*?80)
????slice_size?=?40
????test_every_steps?=?10
????n?=?len(btc_df)?-?slice_size
????shutil.rmtree(data_folder?ignore_errors=True)
????for?epoch?in?range(int(1e6)):
????????st?=?time()
????????i?=?np.random.choice(n)
????????btc_slice?=?btc_df[i:i?+?slice_size]
????????if?btc_slice.isnull().values.any():
????????????#?sometimes?prices?are?discontinuous?and?nothing?happened?in?one?5min?bucket.
????????????#?in?that?case?we?consider?this?slice?as?wrong?and?we?raise?an?exception.
????????????#?it‘s?likely?to?happen?at?the?beginning?of?the?data?set?where?the?volumes?are?low.
????????????raise?Exception(‘NaN?values?detected.?Please?remove?them.‘)
????????class_name?=?get_class_name(btc_df?btc_slice?i?slice_size)
????????save_dir?=?os.path.join(data_folder?‘train‘?class_name)
????????if?epoch?%?test_every_steps?==?0:
????????????save_dir?=?os.path.join(data_folder?‘test‘?class_name)
????????mkdir_p(save_dir)
????????filename?=?save_dir?+?‘/‘?+?str(uuid4())?+?‘.png‘
????????save_to_file(btc_slice?filename=filename)
????????print(‘epoch?=?{0}?time?=?{1:.3f}?filename?=?{2}‘.format(str(epoch).zfill(8)?ti
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2018-07-27?06:53??deep-learning-bitcoin-master\
?????文件????????1181??2018-07-27?06:53??deep-learning-bitcoin-master\.gitignore
?????文件?????????394??2018-07-27?06:53??deep-learning-bitcoin-master\Dockerfile
?????文件???????11357??2018-07-27?06:53??deep-learning-bitcoin-master\LICENSE
?????文件????????3959??2018-07-27?06:53??deep-learning-bitcoin-master\README.md
?????目錄???????????0??2018-07-27?06:53??deep-learning-bitcoin-master\assets\
?????文件??????151782??2018-07-27?06:53??deep-learning-bitcoin-master\assets\1.png
?????文件??????405816??2018-07-27?06:53??deep-learning-bitcoin-master\assets\2.png
?????文件?????????119??2018-07-27?06:53??deep-learning-bitcoin-master\data_download.sh
?????文件????????3528??2018-07-27?06:53??deep-learning-bitcoin-master\data_generator.py
?????文件?????????952??2018-07-27?06:53??deep-learning-bitcoin-master\data_manager.py
?????文件??????????24??2018-07-27?06:53??deep-learning-bitcoin-master\requirements.txt
?????文件?????????924??2018-07-27?06:53??deep-learning-bitcoin-master\returns_quantization.py
?????文件????????1546??2018-07-27?06:53??deep-learning-bitcoin-master\utils.py
評(píng)論
共有 條評(píng)論