-
Notifications
You must be signed in to change notification settings - Fork 31
/
main.py
62 lines (54 loc) · 2.61 KB
/
main.py
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import matplotlib.pyplot as plt
import pandas as pd
from Algorithms import *
from tabulate import tabulate
scheme_code = input('Enter the MF Scheme code:- ')
@getDataFrame(scheme_code)
def forecasting_mutual_fund(df, details):
# pred_SMA = SMA(df)
pred_linear, rmse_linear = linear(df)
pred_autoReg, rmse_auto = AutoR(df)
pred_arima, rmse_arima = arima(df)
pred_expo, rmse_expo = exponential(df)
# pred_arima, rmse_arima = arima_new(df)
pred_LSTM, rmse_lstm = lstm(df)
data = [
['Linear', pred_linear[0], pred_linear[1], pred_linear[2], pred_linear[3], pred_linear[4]
, min(pred_linear), max(pred_linear)],
['Auto Regression',pred_autoReg[0], pred_autoReg[1],pred_autoReg[2],pred_autoReg[3]
,pred_autoReg[4],min(pred_autoReg),max(pred_autoReg)],
['ARIMA', pred_arima[0], pred_arima[1], pred_arima[2], pred_arima[3], pred_arima[4],
min(pred_arima), max(pred_arima)],
['Exponential', pred_expo[0], pred_expo[1], pred_expo[2], pred_expo[3], pred_expo[4],
min(pred_expo), max(pred_expo)],
['LSTM', pred_LSTM[0], pred_LSTM[1],pred_LSTM[2],pred_LSTM[3],pred_LSTM[4]
,min(pred_LSTM),max(pred_LSTM)]
]
print("\n Time Series Forecasting for " + details['scheme_name'] + " (" + str(details['scheme_code']) + ")\n")
print(tabulate(data, headers=["Algorithm", "Day 1", "Day 2", "Day 3", "Day 4", "Day 5",
"1 Month Low", "1 Month High"], tablefmt='orgtbl'))
df_30 = df['nav'].iloc[-100:].astype(float)
Y = [np.nan for i in range(len(df_30))]
# plt.plot(df_30.values, color='black', label='Trend') # last 100 days
# plt.plot(np.append(Y, pred_linear), color='green', label="Linear")
# plt.plot(np.append(Y, pred_autoReg), color='blue', label="Auto Regression")
# plt.plot(np.append(Y,pred_arima), color='red',label='ARIMA')
# plt.plot(np.append(Y,pred_expo), color='yellow',label='Exponential')
# plt.plot(np.append(Y, pred_LSTM), color='orange', label='LSTM')
plt.xlabel('Days [last 100 + 30 forecasted]')
plt.ylabel('NAV')
plt.title("Forecasting for " + details['scheme_name'])
plt.legend()
s = df_30.append(pd.Series([np.nan for i in range(30)]))
sns.set(style="ticks")
data_preproc = pd.DataFrame({
'Trends': s.values,
'Linear': np.append(Y, pred_linear),
'Auto Regression': np.append(Y, pred_autoReg),
'ARIMA': np.append(Y, pred_arima),
'Exponential': np.append(Y, pred_expo),
'LSTM': np.append(Y, pred_LSTM),
})
sns.lineplot(data=data_preproc)
plt.show()
forecasting_mutual_fund()