In this Package we try input data from stock markets and evaluate some of the machine learnings models
(for Now and later maybe we add other options )
- Befor use you should know--> how can read and input data
- Classification
- Regression
- TensorFlow
- Random Forest
- Ada Boost
- K-Nearest Neighbors
- Decision Trees
- Support Vector Machines
- TensorFlow
- Support Vector Regression
- Decision Tree Regression
- ridge Regression
Read More: Stock Markets
from ReadData import MetaTrader
df_raw=my_obj.df_type1_raw
df_raw.tail()
- if it is profitable in sell means our signal should be 'Sell'
- if it is profitable in buy means our signal should be 'Buy'
- if the model does not take profit in any of them before reaching the stop loss --> our signal is 'Nothing' in that candles close time
- buy signals by->1
- sell signals by->2
- and Do Nothings by->0
def create_y(dataframe):
"""
Please pass your raw dataframe
"""
df=dataframe.copy()
#create an empty y values
y=pd.DataFrame(np.nan,index=np.arange(len(df)),columns=["y_true"])
# in this part from time the only thing that matters to us is the hour
df['time'] = df['time'].apply(lambda num: num.hour)
for pos in np.arange(0, len(df)):
close_price = df.loc[pos, 'close']
# calculate distance of stop loss and create tp points
sl_buy = close_price-df.loc[pos, 'Low26']
sl_sell = df.loc[pos, 'High26']- close_price
tp_buy = sl_buy * 2.1
tp_sell = sl_sell * 2.1
signal = 0 # default signal is Zero (do nothing)
# we don't trade after 11 p.m until 4 a.m menas in this hour signals should be Zero
if (df.loc[pos, 'time'] < 23) and (df.loc[pos, 'time'] > 4):
for last in np.arange(1, 25):# This is the part where we give maximum time to the model: 24 candles
if (pos + last) < len(df):
high_last = df.loc[pos + last, 'High26'] - close_price
low_last = close_price- df.loc[pos + last, 'Low26']
low_now = close_price- df.loc[pos + last, 'low']
high_now = df.loc[pos + last, 'high'] - close_price
if (low_last <= sl_buy) and (high_now > tp_buy):
signal = 1
break
elif (high_last <= sl_sell) and (low_now > tp_sell):
signal = 2
break
y.loc[pos] = signal
return y
y=create_y(df_raw)
from Learnings import Classifications
df = my_obj.df_type1_changed
y = pd.to_numeric(y['y_true'], downcast='integer')
Class_obj = Classifications(df,y)
model = Class_obj.tensorflow()
Class_obj.evaluates.plot_confusion_matrix()
model = Class_obj.random_forest()
Class_obj.evaluates.plot_confusion_matrix()
- when our model predict 0 mean no signal --> We don't lose money AND We don't earn money
- when our model predict 1 or 2 --> We have Buy/Sell signal
- if we loss --> we lose money by stop loss (SL)
- if we won --> we earn money by take profit (TP>2*SL)
- 0-> No Signal -> No Point
- 1/2 (Buy/Sell) if it was True --> We GET 2 Point (2*SL)
- 1/2 (Buy/Sell) if it was False --> We LOSE 1 point (SL)
- Final Score= True Signals*2 - False Signal
- if distance is positive means next candle is lower than this candle As long as the distance
- if distance is negative means next candle is upper than this candle As long as the distance
def create_y(dataframe):
"""
Please pass your raw dataframe
"""
df=dataframe.copy()
y = df.apply(lambda row: df["close"][row.name]-df["close"][row.name+1]
if row.name<(len(df)-1) else np.nan,axis=1)
return y
from Learnings import Regression
model = Class_obj.tensorflow()
Class_obj.evaluates.mean_errors()
Class_obj.evaluates.plot_df_y()
df_y[df_y['y_pred']<=-2]