├── .github └── FUNDING.yml ├── Examples ├── AlgoTradingImplementation │ └── main.py ├── SPX500Scanner │ ├── SPX500.csv │ └── main.py └── SingleStock │ └── main.py ├── License.txt ├── README.md ├── favicon.png ├── setup.cfg ├── setup.py └── stox ├── __init__.py ├── data.py ├── predicter.py └── stox.py /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | patreon: dopevog 2 | -------------------------------------------------------------------------------- /Examples/AlgoTradingImplementation/main.py: -------------------------------------------------------------------------------- 1 | ## Import The Modules 2 | import stox 3 | import pandas as pd 4 | 5 | stock_list = ['FB','AAPL','AMZN','NFLX','GOOG'] ## List Of Stocks You Would Want To Buy 6 | number_of_stocks = len(stock_list) 7 | print(number_of_stocks) 8 | 9 | x = 0 10 | starting_cash = 10000 ## Amount Of Money In Trading Account 11 | current_cash = starting_cash 12 | percent_to_spend = 5 13 | money_to_spend = (5/100)*percent_to_spend 14 | 15 | def buy(ticker, price, amt): 16 | ## Here Add Use Your Brocker's API To Buy 17 | cost = price*amt 18 | brockerage = 0.1 ## Your Brockerage % 19 | brockerage = brockerage/100 ## Convert To Decimel 20 | cost = cost + (cost*brockerage) ## Get Total Cost 21 | current_cash = current_cash - cost 22 | print("Bought!") 23 | return current_cash 24 | 25 | def short(ticker, price, amt): 26 | ## Use Your Brocker's API To Short 27 | cost = price*amt 28 | brockerage = 0.1 ## Your Brockerage % 29 | brockerage = brockerage/100 ## Convert To Decimel 30 | cost = cost + (cost*brockerage) ## Get Total Cost 31 | current_cash = current_cash - cost 32 | print("Shorted!") 33 | return current_cash 34 | 35 | while x < number_of_stocks: 36 | ticker = stock_list[x] ## Get The Current Ticker Symbol 37 | data = stox.stox.exec(ticker,'list') ## Get Analysis From Stox 38 | ## Import All Needed Data (Price, Prediction, Analysis, etc.) 39 | df = pd.DataFrame() 40 | df['Ticker'] = ticker 41 | df['Price'] = data[1] 42 | df['Prediction'] = data[2] 43 | df['Analysis'] = data[3] 44 | df['DateFor'] = data[4] 45 | good_pct = data[1]*0.02 46 | minus_pct = good_pct*-1 47 | ## Run Scan For Buy/Up/Down/Sell 48 | if data[2] - data[1] >= good_pct: 49 | if data[3] == "Bullish (Starting)": 50 | df['Signal'] = "Buy" 51 | if money_to_spend <= current_cash: ## Check If Enough Money Left 52 | price = df.Price 53 | amt = price 54 | current_cash = buy(ticker, price, amt) ## Call Buy Function 55 | print("Bought "+ticker) 56 | else: 57 | print("Not Enough Money Left!") 58 | elif data[3] == "Bullish (Already)": 59 | df['Signal'] = "Up" 60 | print(ticker+" is in a Uptrend") 61 | elif data[2] - data[1] <= minus_pct: 62 | if data[3] == "Bearish (Starting)": 63 | df['Signal'] = "Sell" 64 | if money_to_spend <= current_cash: ## Check If Enough Money Left 65 | price = df.Price 66 | amt = price 67 | current_cash = short(ticker, price, amt) ## Call Short Function 68 | print("Shorted "+ticker) 69 | else: 70 | print("Not Enough Money Left!") 71 | elif data[3] == "Bearish (Already)": 72 | df['Signal'] = "Down" 73 | print(ticker+" is in a Downtrend") 74 | else: 75 | df['Signal'] = "None" 76 | print("No Signal For "+ticker) 77 | x = x+1 78 | print("Done") ## Print 'Done' After Complete 79 | -------------------------------------------------------------------------------- /Examples/SPX500Scanner/SPX500.csv: -------------------------------------------------------------------------------- 1 | Symbols 2 | MMM 3 | AOS 4 | ABT 5 | ABBV 6 | ABMD 7 | ACN 8 | ATVI 9 | ADBE 10 | AAP 11 | AMD 12 | AES 13 | AFL 14 | A 15 | APD 16 | AKAM 17 | ALK 18 | ALB 19 | ARE 20 | ALXN 21 | ALGN 22 | ALLE 23 | LNT 24 | ALL 25 | GOOGL 26 | GOOG 27 | MO 28 | AMZN 29 | AMCR 30 | AEE 31 | AAL 32 | AEP 33 | AXP 34 | AIG 35 | AMT 36 | AWK 37 | AMP 38 | ABC 39 | AME 40 | AMGN 41 | APH 42 | ADI 43 | ANSS 44 | ANTM 45 | AON 46 | APA 47 | AAPL 48 | AMAT 49 | APTV 50 | ADM 51 | ANET 52 | AJG 53 | AIZ 54 | T 55 | ATO 56 | ADSK 57 | ADP 58 | AZO 59 | AVB 60 | AVY 61 | BKR 62 | BLL 63 | BAC 64 | BAX 65 | BDX 66 | BRK-B 67 | BBY 68 | BIO 69 | BIIB 70 | BLK 71 | BA 72 | BKNG 73 | BWA 74 | BXP 75 | BSX 76 | BMY 77 | AVGO 78 | BR 79 | BF-B 80 | CHRW 81 | COG 82 | CDNS 83 | CZR 84 | CPB 85 | COF 86 | CAH 87 | KMX 88 | CCL 89 | CARR 90 | CTLT 91 | CAT 92 | CBOE 93 | CBRE 94 | CDW 95 | CE 96 | CNC 97 | CNP 98 | CERN 99 | CF 100 | SCHW 101 | CHTR 102 | CVX 103 | CMG 104 | CB 105 | CHD 106 | CI 107 | CINF 108 | CTAS 109 | CSCO 110 | C 111 | CFG 112 | CTXS 113 | CME 114 | CMS 115 | KO 116 | CTSH 117 | CL 118 | CMCSA 119 | CMA 120 | CAG 121 | COP 122 | ED 123 | STZ 124 | CPRT 125 | GLW 126 | CTVA 127 | COST 128 | CCI 129 | CSX 130 | CMI 131 | CVS 132 | DHI 133 | DHR 134 | DRI 135 | DVA 136 | DE 137 | DAL 138 | XRAY 139 | DVN 140 | DXCM 141 | FANG 142 | DLR 143 | DFS 144 | DISCA 145 | DISCK 146 | DISH 147 | DG 148 | DLTR 149 | D 150 | DPZ 151 | DOV 152 | DOW 153 | DTE 154 | DUK 155 | DRE 156 | DD 157 | DXC 158 | EMN 159 | ETN 160 | EBAY 161 | ECL 162 | EIX 163 | EW 164 | EA 165 | EMR 166 | ENPH 167 | ETR 168 | EOG 169 | EFX 170 | EQIX 171 | EQR 172 | ESS 173 | EL 174 | ETSY 175 | RE 176 | EVRG 177 | ES 178 | EXC 179 | EXPE 180 | EXPD 181 | EXR 182 | XOM 183 | FFIV 184 | FB 185 | FAST 186 | FRT 187 | FDX 188 | FIS 189 | FITB 190 | FRC 191 | FE 192 | FISV 193 | FLT 194 | FLIR 195 | FMC 196 | F 197 | FTNT 198 | FTV 199 | FBHS 200 | FOXA 201 | FOX 202 | BEN 203 | FCX 204 | GPS 205 | GRMN 206 | IT 207 | GNRC 208 | GD 209 | GE 210 | GIS 211 | GM 212 | GPC 213 | GILD 214 | GPN 215 | GL 216 | GS 217 | GWW 218 | HAL 219 | HBI 220 | HIG 221 | HAS 222 | HCA 223 | PEAK 224 | HSIC 225 | HES 226 | HPE 227 | HLT 228 | HFC 229 | HOLX 230 | HD 231 | HON 232 | HRL 233 | HST 234 | HWM 235 | HPQ 236 | HUM 237 | HBAN 238 | HII 239 | IEX 240 | IDXX 241 | INFO 242 | ITW 243 | ILMN 244 | INCY 245 | IR 246 | INTC 247 | ICE 248 | IBM 249 | IFF 250 | IP 251 | IPG 252 | INTU 253 | ISRG 254 | IVZ 255 | IPGP 256 | IQV 257 | IRM 258 | JBHT 259 | JKHY 260 | J 261 | SJM 262 | JNJ 263 | JCI 264 | JPM 265 | JNPR 266 | KSU 267 | K 268 | KEY 269 | KEYS 270 | KMB 271 | KIM 272 | KMI 273 | KLAC 274 | KHC 275 | KR 276 | LB 277 | LHX 278 | LH 279 | LRCX 280 | LW 281 | LVS 282 | LEG 283 | LDOS 284 | LEN 285 | LLY 286 | LNC 287 | LIN 288 | LYV 289 | LKQ 290 | LMT 291 | L 292 | LOW 293 | LUMN 294 | LYB 295 | MTB 296 | MRO 297 | MPC 298 | MKTX 299 | MAR 300 | MMC 301 | MLM 302 | MAS 303 | MA 304 | MXIM 305 | MKC 306 | MCD 307 | MCK 308 | MDT 309 | MRK 310 | MET 311 | MTD 312 | MGM 313 | MCHP 314 | MU 315 | MSFT 316 | MAA 317 | MHK 318 | TAP 319 | MDLZ 320 | MPWR 321 | MNST 322 | MCO 323 | MS 324 | MSI 325 | MSCI 326 | NDAQ 327 | NTAP 328 | NFLX 329 | NWL 330 | NEM 331 | NWSA 332 | NWS 333 | NEE 334 | NLSN 335 | NKE 336 | NI 337 | NSC 338 | NTRS 339 | NOC 340 | NLOK 341 | NCLH 342 | NOV 343 | NRG 344 | NUE 345 | NVDA 346 | NVR 347 | NXPI 348 | ORLY 349 | OXY 350 | ODFL 351 | OMC 352 | OKE 353 | ORCL 354 | OTIS 355 | PCAR 356 | PKG 357 | PH 358 | PAYX 359 | PAYC 360 | PYPL 361 | PENN 362 | PNR 363 | PBCT 364 | PEP 365 | PKI 366 | PRGO 367 | PFE 368 | PM 369 | PSX 370 | PNW 371 | PXD 372 | PNC 373 | POOL 374 | PPG 375 | PPL 376 | PFG 377 | PG 378 | PGR 379 | PLD 380 | PRU 381 | PEG 382 | PSA 383 | PHM 384 | PVH 385 | QRVO 386 | QCOM 387 | PWR 388 | DGX 389 | RL 390 | RJF 391 | RTX 392 | O 393 | REG 394 | REGN 395 | RF 396 | RSG 397 | RMD 398 | RHI 399 | ROK 400 | ROL 401 | ROP 402 | ROST 403 | RCL 404 | SPGI 405 | CRM 406 | SBAC 407 | SLB 408 | STX 409 | SEE 410 | SRE 411 | NOW 412 | SHW 413 | SPG 414 | SWKS 415 | SNA 416 | SO 417 | LUV 418 | SWK 419 | SBUX 420 | STT 421 | STE 422 | SYK 423 | SIVB 424 | SYF 425 | SNPS 426 | SYY 427 | TMUS 428 | TROW 429 | TTWO 430 | TPR 431 | TGT 432 | TEL 433 | TDY 434 | TFX 435 | TER 436 | TSLA 437 | TXN 438 | TXT 439 | BK 440 | CLX 441 | COO 442 | HSY 443 | MOS 444 | TRV 445 | DIS 446 | TMO 447 | TJX 448 | TSCO 449 | TT 450 | TDG 451 | TRMB 452 | TFC 453 | TWTR 454 | TYL 455 | TSN 456 | USB 457 | UDR 458 | ULTA 459 | UAA 460 | UA 461 | UNP 462 | UAL 463 | UPS 464 | URI 465 | UNH 466 | UHS 467 | UNM 468 | VLO 469 | VAR 470 | VTR 471 | VRSN 472 | VRSK 473 | VZ 474 | VRTX 475 | VFC 476 | VIAC 477 | VTRS 478 | V 479 | VNO 480 | VMC 481 | WRB 482 | WBA 483 | WMT 484 | WM 485 | WAT 486 | WEC 487 | WFC 488 | WELL 489 | WST 490 | WDC 491 | WU 492 | WAB 493 | WRK 494 | WY 495 | WHR 496 | WMB 497 | WLTW 498 | WYNN 499 | XEL 500 | XLNX 501 | XYL 502 | YUM 503 | ZBRA 504 | ZBH 505 | ZION 506 | ZTS 507 | -------------------------------------------------------------------------------- /Examples/SPX500Scanner/main.py: -------------------------------------------------------------------------------- 1 | ## Import The Modules 2 | import stox 3 | import pandas as pd 4 | 5 | stock_list = pd.read_csv("SPX500.csv") ## Read Stock Ticker List CSV 6 | df = stock_list ## Store It As A Variable 7 | number_of_stocks = 505 ## Number Of Tickers In CSV 8 | x = 0 9 | while x < number_of_stocks: 10 | ticker = stock_list.iloc[x]["Symbols"] ## Get The Current Ticker Symbol 11 | data = stox.stox.exec(ticker,'list') ## Get Analysis From Stox 12 | ## Import All Needed Data (Price, Prediction, Analysis, etc.) 13 | df['Price'] = data[1] 14 | df['Prediction'] = data[2] 15 | df['Analysis'] = data[3] 16 | df['DateFor'] = data[4] 17 | ## Run Scan For Buy/Up/Down/Sell 18 | if data[2] - data[1] >= data[1] * 0.02: 19 | if data[3] == "Bullish (Starting)": 20 | df['Signal'] = "Buy" 21 | elif data[3] == "Bullish (Already)": 22 | df['Signal'] = "Up" 23 | elif data[2] - data[1] <= data[1] * -0.02: 24 | if data[3] == "Bearish (Starting)": 25 | df['Signal'] = "Sell" 26 | elif data[3] == "Bearish (Already)": 27 | df['Signal'] = "Down" 28 | else: 29 | df['Signal'] = "None" 30 | x = x+1 31 | df.to_csv("output.csv") ## Export To CSV 32 | print("Done") ## Print 'Done' After Complete 33 | -------------------------------------------------------------------------------- /Examples/SingleStock/main.py: -------------------------------------------------------------------------------- 1 | ## Import The Modules 2 | import stox 3 | 4 | script = input("Stock Ticker Symbol: ") ## Take Input Of Ticker Symbol 5 | data = stox.stox.exec(script,'message') ## Get Result From Stox 6 | 7 | print(data) ## Give Output As Message -------------------------------------------------------------------------------- /License.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | Copyright (c) 2021-Present Vedant Kothari 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | The above copyright notice and this permission notice shall be included in all 10 | copies or substantial portions of the Software. 11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 12 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 13 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 14 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 15 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 16 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 17 | SOFTWARE. 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 | Stox
4 |
5 |
6 | 7 | ⚡ A Python Module For The Stock Market ⚡
8 | 9 |

10 | 11 | A Module to predict the "close price" for the next day and give "technical analysis". It 12 | uses a Neural Network and the LSTM algorithm to predict the price. It uses a technical 13 | indicator algorithm developed by the Stox team for technical analysis. 14 | 15 | ## Installation 16 | Get it from [PyPi](https://pypi.org/project/stox/): 17 | ``` 18 | pip3 install stox 19 | ``` 20 | Clone it from github: 21 | ``` 22 | git clone https://github.com/dopevog/stox.git 23 | cd stox 24 | python3 setup.py install 25 | ``` 26 | 27 | ## Usage 28 | ### Arguments: 29 | ``` 30 | stock (str): stock ticker symbol 31 | output (str): 'list' or 'message' (Format Of Output) 32 | years (int or float): years of data to be considered 33 | chart (bool): generate performance plot 34 | ``` 35 | 36 | ### Returns: 37 | List: 38 | ``` 39 | [company name, current price, predicted price, technical analysis, date (For)] 40 | ``` 41 | Message: 42 | ``` 43 | company name 44 | current price 45 | predicted price 46 | technical analysis 47 | data (for) 48 | ``` 49 | 50 | ### Examples: 51 | #### Basic 52 | ``` 53 | import stox 54 | 55 | script = input("Stock Ticker Symbol: ") 56 | data = stox.stox.exec(script,'list') 57 | 58 | print(data) 59 | ``` 60 | ``` 61 | $ stox> python3 main.py 62 | $ Stock Ticker Symbol: AAPL 63 | $ ['Apple Inc.', 125.43000030517578, 124.91, 'Bearish (Already)', '2021-05-24'] 64 | ``` 65 | #### Intermediate 66 | ``` 67 | import stox 68 | import pandas as pd 69 | 70 | stock_list = pd.read_csv("SPX500.csv") 71 | df = stock_list 72 | number_of_stocks = 505 73 | x = 0 74 | while x < number_of_stocks: 75 | ticker = stock_list.iloc[x]["Symbols"] 76 | data = stox.stox.exec(ticker,'list') 77 | df['Price'] = data[1] 78 | df['Prediction'] = data[2] 79 | df['Analysis'] = data[3] 80 | df['DateFor'] = data[4] 81 | if data[2] - data[1] >= data[1] * 0.02: 82 | if data[3] == "Bullish (Starting)": 83 | df['Signal'] = "Buy" 84 | elif data[3] == "Bullish (Already)": 85 | df['Signal'] = "Up" 86 | elif data[2] - data[1] <= data[1] * -0.02: 87 | if data[3] == "Bearish (Starting)": 88 | df['Signal'] = "Sell" 89 | elif data[3] == "Bearish (Already)": 90 | df['Signal'] = "Down" 91 | else: 92 | df['Signal'] = "None" 93 | x = x+1 94 | df.to_csv("output.csv") 95 | print("Done") 96 | ``` 97 | ``` 98 | $ stox> python3 main.py 99 | $ Done 100 | ``` 101 | #### More Examples Including These Ones Can Be Found [Here](https://github.com/cstox/stox/tree/main/Examples) 102 | 103 | ### Possible Implentations 104 | * Algorithmic Trading 105 | * Single Stock Analysis 106 | * Multistock Analysis 107 | * And Much More! 108 | 109 | ## Credits 110 | * [Dopevog](https://github.com/dopevog) 111 | * [Gerard López](https://macosicons.com/u/Gerard%20L%C3%B3pez) - Logo 112 | 113 | ## License 114 | This Project Has Been [MIT Licensed](https://github.com/cstox/stox/blob/main/License.txt) 115 | -------------------------------------------------------------------------------- /favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dopevog/stox/ff0db6610f401c63e6df4fa643cd5cd5f8e1871e/favicon.png -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [metadata] 2 | description-file = README.md -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup 2 | with open("README.md", "r") as fh: 3 | long_description = fh.read() 4 | 5 | setup( 6 | name='stox', 7 | packages=['stox'], 8 | version='0.5', 9 | description='Stock Price Prediction And Analysis', 10 | long_description=long_description, 11 | long_description_content_type="text/markdown", 12 | author='Vedant Kothari', 13 | author_email='stox.org@gmail.com', 14 | url='https://github.com/cstox/stox', 15 | keywords=['stock price prediction','stock analysis','stock signals''stock ai'], 16 | classifiers=['Programming Language :: Python :: 3', 17 | 'Natural Language :: English', 18 | 'Topic :: Utilities'], 19 | install_requires=['numpy==1.19.5','pandas-datareader','pytrends','pandas','requests','scikit-learn','keras','tensorflow','matplotlib','pandas-ta',] 20 | ) 21 | -------------------------------------------------------------------------------- /stox/__init__.py: -------------------------------------------------------------------------------- 1 | from . import stox 2 | from . import data 3 | from . import predicter 4 | -------------------------------------------------------------------------------- /stox/data.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | from pandas_datareader import data 3 | import datetime as dt 4 | import pandas_ta 5 | from pytrends.request import TrendReq 6 | 7 | def main(stock, years=1): 8 | end = dt.datetime.today().strftime('%Y-%m-%d') 9 | start = (dt.datetime.today() - dt.timedelta(days=365*years)).strftime('%Y-%m-%d') 10 | df = data.DataReader(stock, 'yahoo', start, end) 11 | 12 | return df, start, end 13 | 14 | def add_rsi(df): 15 | close = df["Close"] 16 | df['RSI'] = pandas_ta.momentum.rsi(close, length=None, scalar=None, drift=None, offset=None) 17 | 18 | return df 19 | 20 | def add_ma50(df): 21 | df['MA50'] = df.Close.rolling(50, min_periods=1).mean() 22 | 23 | return df 24 | 25 | def receive(stock, years=1, indicators=True): 26 | df, start, end = main(stock, years=years) 27 | 28 | if indicators: 29 | df = add_rsi(df) 30 | df = add_ma50(df) 31 | df['RSIUP'] = df.RSI>50 32 | df['PRICEUP'] = df.Close>df.MA50 33 | df['RSIDOWN'] = df.RSI<50 34 | df['PRICEDOWN'] = df.Close limit].index.tolist() 49 | 50 | return features 51 | -------------------------------------------------------------------------------- /stox/predicter.py: -------------------------------------------------------------------------------- 1 | from keras.models import Sequential 2 | from keras.layers import Dense, LSTM, Dropout 3 | from sklearn.preprocessing import MinMaxScaler 4 | import numpy as np 5 | 6 | 7 | def data(df, features=[]): 8 | columns = ['Close'] 9 | if len(features) > 0: 10 | for i in range(len(features)): 11 | columns.append(features[i]) 12 | 13 | df = df[columns] 14 | 15 | return df 16 | 17 | 18 | def get_predicter_input(data, steps=1): 19 | samples = [] 20 | for i in range(steps, data.shape[0]): 21 | features = [] 22 | for j in range(steps): 23 | features.append(data[i - steps + j, :]) 24 | features.append(data[i, :]) 25 | samples.append(features) 26 | 27 | features = [] 28 | for j in range(steps + 1): 29 | features.append(data[-1, :]) 30 | 31 | samples.append(features) 32 | samples = np.asarray(samples) 33 | return samples 34 | 35 | 36 | def run(df, features=[], steps=1, training=0.9): 37 | 38 | new_df = data(df, features) 39 | 40 | scaler = MinMaxScaler(feature_range=(0, 1)) 41 | scaled = scaler.fit_transform(new_df) 42 | reframed = get_predicter_input(scaled, steps) 43 | 44 | rows = round(len(df) * training) 45 | 46 | train = reframed[:rows, :, :] 47 | test = reframed[rows:, :, :] 48 | 49 | train_x, train_y = train[:, :steps, :], train[:, steps, 0] 50 | test_x, test_y = test[:, :steps, :], test[:-1, steps, 0] 51 | 52 | model = Sequential() 53 | model.add(LSTM(50, input_shape=(train_x.shape[1], train_x.shape[2]))) 54 | model.add(Dropout(0.2)) 55 | model.add(Dense(1)) 56 | model.compile(loss='mae', optimizer='adam') 57 | model.fit(train_x, train_y, epochs=100, batch_size=70, verbose=0) 58 | 59 | mod1 = rows + steps - 1 60 | mod2 = rows + steps 61 | 62 | prediction = model.predict(test_x) 63 | new_scaled = np.copy(scaled) 64 | for x in range(mod1, new_scaled.shape[0]): 65 | new_scaled[x, 0] = prediction[x-mod1] 66 | 67 | 68 | y_predicted = scaler.inverse_transform(new_scaled) 69 | y_predicted = y_predicted[mod1:, 0] 70 | y = scaler.inverse_transform(scaled) 71 | y = y[mod2:, 0] 72 | 73 | finalprice = round(y_predicted[-1], 2) 74 | y_predicted = y_predicted[:-1] 75 | 76 | result = [finalprice] 77 | 78 | return result, y_predicted, new_df[-len(y):] 79 | 80 | -------------------------------------------------------------------------------- /stox/stox.py: -------------------------------------------------------------------------------- 1 | from stox.data import receive 2 | from stox.predicter import run 3 | import datetime as dt 4 | import pandas as pd 5 | import requests 6 | 7 | def exec(stock, output='list', years=1, chart=False): 8 | 9 | techgood = False 10 | alreadygood = False 11 | techbad = False 12 | alreadybad = False 13 | 14 | stock_data = receive(stock, years=years) 15 | data = stock_data 16 | url = "http://d.yimg.com/autoc.finance.yahoo.com/autoc?query={}®ion=1&lang=en".format(stock) 17 | company = requests.get(url).json()['ResultSet']['Result'][0]['name'] 18 | 19 | techgood = False 20 | alreadygood = False 21 | techbad = False 22 | alreadybad = False 23 | 24 | df = data.iloc[-3:] 25 | 26 | df.to_csv('df.csv') 27 | df = pd.read_csv('df.csv') 28 | 29 | cu = df.at[2,'RSIUP'] 30 | cy = df.at[1,'RSIUP'] 31 | su = df.at[2,'PRICEUP'] 32 | sy = df.at[1,'PRICEUP'] 33 | 34 | bu = df.at[2,'RSIDOWN'] 35 | by = df.at[1,'RSIDOWN'] 36 | du = df.at[2,'PRICEDOWN'] 37 | dy = df.at[1,'PRICEDOWN'] 38 | 39 | cmp = df.at[2,'Close'] 40 | 41 | if cu == True & su == True: 42 | if cy == False or sy == False: 43 | techgood = True 44 | else: 45 | alreadygood = True 46 | elif bu == True & du == True: 47 | if by == False or dy == False: 48 | techbad = True 49 | else: 50 | alreadybad = True 51 | 52 | cmp = df.at[2,'Close'] 53 | 54 | result, y_predicted, df = run(stock_data, [], 1, 0.9) 55 | 56 | date = (dt.datetime.today() + dt.timedelta(days=1)) 57 | while date.weekday() == 5 or date.weekday() == 6: 58 | date = date + dt.timedelta(days=1) 59 | date = date.strftime('%Y-%m-%d') 60 | if techgood == True: 61 | result.append("Bullish (Starting)") 62 | elif alreadygood == True: 63 | result.append("Bullish (Already)") 64 | elif techbad == True: 65 | result.append("Bearish (Starting)") 66 | elif alreadybad == True: 67 | result.append("Bearish (Already)") 68 | else: 69 | result.append("None") 70 | result.append(cmp) 71 | result.append(date) 72 | 73 | priceprediction = result[0] 74 | techanalysis = result[1] 75 | ltp = result[2] 76 | datefor = result[3] 77 | result = [] 78 | result = result+[company] 79 | result = result+[ltp] 80 | result = result+[priceprediction] 81 | result = result+[techanalysis] 82 | result = result+[datefor] 83 | 84 | if output == 'list': 85 | result = result 86 | elif output == 'message': 87 | result = f''' 88 | Company Name = {company} 89 | Current Price = {ltp} 90 | Predicted Price = {priceprediction} 91 | Technical Analysis = {techanalysis} 92 | Data (For) = {datefor}''' 93 | 94 | if not chart: 95 | return result 96 | 97 | if chart: 98 | dates = df.index.tolist() 99 | from pandas.plotting import register_matplotlib_converters 100 | register_matplotlib_converters() 101 | import matplotlib.pyplot as plt 102 | plt.plot(dates, y_predicted) 103 | plt.plot(dates, df.Close.tolist()) 104 | plt.title(stock + ' - %1.2f' % result[0] + ' - %1.3f' % result[1] + '% - ' + result[2]) 105 | plt.xlabel('Date') 106 | plt.ylabel('Close price (USD)') 107 | plt.legend(['Predicted', 'True']) 108 | plt.gcf().autofmt_xdate() 109 | plt.show() 110 | 111 | return result 112 | --------------------------------------------------------------------------------