finished converter
This commit is contained in:
parent
1b00f9500a
commit
e080b70c80
23
.idea/csv-plugin.xml
generated
Normal file
23
.idea/csv-plugin.xml
generated
Normal file
@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CsvFileAttributes">
|
||||
<option name="attributeMap">
|
||||
<map>
|
||||
<entry key="/data/EURUSD_price_candlestick.csv">
|
||||
<value>
|
||||
<Attribute>
|
||||
<option name="separator" value="," />
|
||||
</Attribute>
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="/data/candlesticks/EURUSD_5S_2020.09.01_2020.09.30.csv">
|
||||
<value>
|
||||
<Attribute>
|
||||
<option name="separator" value="," />
|
||||
</Attribute>
|
||||
</value>
|
||||
</entry>
|
||||
</map>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
||||
3
.idea/misc.xml
generated
3
.idea/misc.xml
generated
@ -1,4 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Poetry (marketTrade)" project-jdk-type="Python SDK" />
|
||||
<component name="PyCharmProfessionalAdvertiser">
|
||||
<option name="shown" value="true" />
|
||||
</component>
|
||||
</project>
|
||||
@ -2,4 +2,6 @@ import pathlib
|
||||
|
||||
ROOT_PATH = pathlib.Path(__file__).parent.parent
|
||||
_CANDLESTICK_DATASETS_RELATIVE_PATH = pathlib.Path('data/candlesticks')
|
||||
_TEST_CANDLESTICK_RELATIVE_PATH = pathlib.Path('data/EURUSD_price_candlestick.csv')
|
||||
CANDLESTICK_DATASETS_PATH = ROOT_PATH / _CANDLESTICK_DATASETS_RELATIVE_PATH
|
||||
TEST_CANDLESTICKS_PATH = ROOT_PATH / _TEST_CANDLESTICK_RELATIVE_PATH
|
||||
|
||||
28
market_trade/dataloader.py
Normal file
28
market_trade/dataloader.py
Normal file
@ -0,0 +1,28 @@
|
||||
import pandas as pd
|
||||
|
||||
|
||||
class DukaMTInterface:
|
||||
"""
|
||||
Interface between my askbid candlesticks and sasha's price candlesticks
|
||||
|
||||
has two attributes -- bids and asks
|
||||
"""
|
||||
|
||||
def __init__(self, duka_candlesticks_filepath):
|
||||
# reading index from column 0 and header takes two rows, because of multirow indexers
|
||||
self.duka_dataset = pd.read_csv(duka_candlesticks_filepath, index_col=0, header=[0, 1], parse_dates=True)
|
||||
|
||||
# renaming timestamp to date
|
||||
self.duka_dataset['date'] = self.duka_dataset.index
|
||||
|
||||
# droppnig old timestamp index
|
||||
self.duka_dataset.reset_index(inplace=True, drop=True)
|
||||
|
||||
|
||||
# adding bids
|
||||
self.bid_candlesticks = self.duka_dataset['bid'].copy()
|
||||
self.bid_candlesticks['date'] = self.duka_dataset['date']
|
||||
|
||||
# adding asks
|
||||
self.ask_candlesticks = self.duka_dataset['ask'].copy()
|
||||
self.ask_candlesticks['date'] = self.duka_dataset['date']
|
||||
@ -3,7 +3,7 @@
|
||||
|
||||
# Let's try to get filepath of any candlesticks file.
|
||||
|
||||
# In[2]:
|
||||
# In[1]:
|
||||
|
||||
|
||||
import market_trade.constants
|
||||
@ -15,7 +15,7 @@ candlesticks_filepath
|
||||
|
||||
# Let's import that file to pandas
|
||||
|
||||
# In[18]:
|
||||
# In[2]:
|
||||
|
||||
|
||||
import pandas as pd
|
||||
@ -24,13 +24,22 @@ import pandas as pd
|
||||
candlesticks_df = pd.read_csv(candlesticks_filepath,index_col=0, header=[0,1], parse_dates=True)
|
||||
candlesticks_df['date'] = candlesticks_df.index
|
||||
candlesticks_df.reset_index(inplace=True, drop=True)
|
||||
ask_candlesticks_df = candlesticks_df['ask']
|
||||
ask_candlesticks_df = candlesticks_df['ask'].copy()
|
||||
ask_candlesticks_df.head()
|
||||
|
||||
|
||||
# Everything imported beatifully.
|
||||
# Everything imported beatifully, let's attach the date to it
|
||||
|
||||
# In[17]:
|
||||
# In[3]:
|
||||
|
||||
|
||||
ask_candlesticks_df['date'] = candlesticks_df['date']
|
||||
ask_candlesticks_df.head()
|
||||
|
||||
|
||||
# Let's test it
|
||||
|
||||
# In[4]:
|
||||
|
||||
|
||||
"""
|
||||
@ -43,11 +52,115 @@ ind_params = {'MeanType': 'SMA', 'window': 5, 'valueType': 'low', 'kDev': 2}
|
||||
# df_candle[:3000],ind_params,True,False,True
|
||||
# window 5..100 (5) | valueType: 'open', 'low' | 'kdev' : 1..4 (0.1)
|
||||
indEl1 = {
|
||||
'df': ask_candlesticks_df[:3000],
|
||||
'df': ask_candlesticks_df,
|
||||
'params': ind_params,
|
||||
'needFig': False,
|
||||
'showOnlyIndex': False,
|
||||
'drawFig': True
|
||||
}
|
||||
a = market_trade.signals.Signal1.SignalBollingerBands1({'BB': indEl1})
|
||||
a.analiz
|
||||
|
||||
|
||||
# Let's test that i didn't broke the file. Let's import test file, and compare results.
|
||||
#
|
||||
# Importing
|
||||
|
||||
# In[5]:
|
||||
|
||||
|
||||
test_candlesticks = pd.read_csv(market_trade.constants.TEST_CANDLESTICKS_PATH)
|
||||
test_candlesticks['date'] = test_candlesticks['timestamp']
|
||||
test_candlesticks.drop(['timestamp'], axis=1, inplace=True)
|
||||
test_candlesticks.head()
|
||||
|
||||
|
||||
# Comparing results
|
||||
|
||||
# In[6]:
|
||||
|
||||
|
||||
"""
|
||||
expected results
|
||||
{'chstota': 0.3555926544240401,
|
||||
'zeroNum %': 0.5963272120200334,
|
||||
't %': 0.37963272120200336,
|
||||
'f %': 0.024040066777963272,
|
||||
'toch': 0.9404466501240695}
|
||||
"""
|
||||
|
||||
import market_trade.signals.Signal1
|
||||
|
||||
|
||||
ind_params = {'MeanType': 'SMA', 'window': 5, 'valueType': 'low', 'kDev': 2}
|
||||
# df_candle[:3000],ind_params,True,False,True
|
||||
# window 5..100 (5) | valueType: 'open', 'low' | 'kdev' : 1..4 (0.1)
|
||||
indEl1 = {
|
||||
'df': test_candlesticks[:3000],
|
||||
'params': ind_params,
|
||||
'needFig': False,
|
||||
'showOnlyIndex': False,
|
||||
'drawFig': True
|
||||
}
|
||||
a = market_trade.signals.Signal1.SignalBollingerBands1({'BB': indEl1})
|
||||
a.analiz
|
||||
|
||||
|
||||
# Nice! And lets try full file
|
||||
|
||||
# In[16]:
|
||||
|
||||
|
||||
ind_params = {'MeanType': 'SMA', 'window': 5, 'valueType': 'low', 'kDev': 2}
|
||||
# df_candle[:3000],ind_params,True,False,True
|
||||
# window 5..100 (5) | valueType: 'open', 'low' | 'kdev' : 1..4 (0.1)
|
||||
indEl1 = {
|
||||
'df': test_candlesticks[:10000],
|
||||
'params': ind_params,
|
||||
'needFig': False,
|
||||
'showOnlyIndex': False,
|
||||
'drawFig': True
|
||||
}
|
||||
a = market_trade.signals.Signal1.SignalBollingerBands1({'BB': indEl1})
|
||||
a.analiz
|
||||
|
||||
|
||||
# Let's test our file loading
|
||||
|
||||
# In[8]:
|
||||
|
||||
|
||||
candlesticks_filepaths
|
||||
|
||||
|
||||
# Let's choose EURUSD candletsicks
|
||||
|
||||
# In[11]:
|
||||
|
||||
|
||||
candlesticks_filepath = candlesticks_filepaths[5]
|
||||
|
||||
candlesticks_df = pd.read_csv(candlesticks_filepath,index_col=0, header=[0,1], parse_dates=True)
|
||||
candlesticks_df['date'] = candlesticks_df.index
|
||||
candlesticks_df.reset_index(inplace=True, drop=True)
|
||||
ask_candlesticks_df = candlesticks_df['ask'].copy()
|
||||
ask_candlesticks_df['date'] = candlesticks_df['date']
|
||||
ask_candlesticks_df.head()
|
||||
|
||||
|
||||
# Let's test
|
||||
|
||||
# In[15]:
|
||||
|
||||
|
||||
ind_params = {'MeanType': 'SMA', 'window': 5, 'valueType': 'low', 'kDev': 2}
|
||||
indEl1 = {
|
||||
'df': ask_candlesticks_df[:10000],
|
||||
'params': ind_params,
|
||||
'needFig': False,
|
||||
'showOnlyIndex': False,
|
||||
'drawFig': True
|
||||
}
|
||||
a = market_trade.signals.Signal1.SignalBollingerBands1({'BB': indEl1})
|
||||
a.analiz
|
||||
|
||||
|
||||
12
market_trade/tests/test_dataloader.py
Normal file
12
market_trade/tests/test_dataloader.py
Normal file
@ -0,0 +1,12 @@
|
||||
import market_trade.dataloader
|
||||
import market_trade.constants
|
||||
|
||||
def test_dataloader(data_path):
|
||||
duka_interface = (market_trade.dataloader.DukaMTInterface(data_path))
|
||||
print(duka_interface.ask_candlesticks)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
candlesticks_filepaths = [filepath for filepath in market_trade.constants.CANDLESTICK_DATASETS_PATH.iterdir()]
|
||||
candlesticks_filepath = candlesticks_filepaths[0]
|
||||
test_dataloader(candlesticks_filepath)
|
||||
Loading…
x
Reference in New Issue
Block a user