-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
954 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
291 changes: 291 additions & 0 deletions
291
app/Python Programming and its Applications in Stock Trading.py
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,190 @@ | ||
amqp==2.5.0 | ||
appnope==0.1.0 | ||
asn1crypto==0.24.0 | ||
astroid==2.3.3 | ||
atomicwrites==1.3.0 | ||
attrs==19.1.0 | ||
awscli==1.16.177 | ||
backcall==0.1.0 | ||
bandit==1.6.1 | ||
beautifulsoup4==4.8.2 | ||
billiard==3.6.0.0 | ||
bleach==3.1.0 | ||
bob-builder==0.0.17 | ||
boto==2.48.0 | ||
boto3==1.9.163 | ||
botocore==1.12.167 | ||
browsermob-proxy==0.8.0 | ||
bs4==0.0.1 | ||
cachetools==3.1.1 | ||
celery==4.3.0 | ||
certifi==2019.11.28 | ||
cffi==1.12.3 | ||
chardet==3.0.4 | ||
Click==7.0 | ||
cms==0.0.2 | ||
colorama==0.4.3 | ||
cryptography==2.7 | ||
cycler==0.10.0 | ||
decorator==4.4.0 | ||
defusedxml==0.6.0 | ||
distro==1.4.0 | ||
dj-database-url==0.5.0 | ||
Django==2.1.8 | ||
django-classy-tags==0.9.0 | ||
django-cms==3.6.0 | ||
django-filer==1.5.0 | ||
django-formtools==2.1 | ||
django-js-asset==1.2.2 | ||
django-modelcluster==4.4 | ||
django-mptt==0.10.0 | ||
django-polymorphic==2.0.3 | ||
django-sekizai==1.0.0 | ||
django-taggit==0.24.0 | ||
django-treebeard==4.3 | ||
djangocms-admin-style==1.2.9 | ||
djangocms-attributes-field==1.1.0 | ||
djangocms-column==1.9.0 | ||
djangocms-file==2.3.0 | ||
djangocms-googlemap==1.2.0 | ||
djangocms-installer==1.1.0 | ||
djangocms-link==2.4.0 | ||
djangocms-picture==2.0.8 | ||
djangocms-snippet==2.1.0 | ||
djangocms-style==2.2.0 | ||
djangocms-text-ckeditor==3.7.0 | ||
djangocms-video==2.0.5 | ||
djangorestframework==3.9.4 | ||
docopt==0.6.2 | ||
docutils==0.14 | ||
draftjs-exporter==2.1.5 | ||
easy-thumbnails==2.6 | ||
entrypoints==0.3 | ||
Flask==1.0.3 | ||
fpdf==1.7.2 | ||
GDAL==2.4.2 | ||
gensim==3.8.1 | ||
gitdb2==2.0.5 | ||
GitPython==2.1.11 | ||
google-api-python-client==1.7.9 | ||
google-auth==1.6.3 | ||
google-auth-httplib2==0.0.3 | ||
google-auth-oauthlib==0.3.0 | ||
html5lib==1.0.1 | ||
httplib2==0.12.3 | ||
idna==2.8 | ||
importlib-metadata==0.18 | ||
ipykernel==5.1.1 | ||
ipython==7.5.0 | ||
ipython-genutils==0.2.0 | ||
ipywidgets==7.4.2 | ||
isort==4.3.21 | ||
itsdangerous==1.1.0 | ||
jedi==0.13.3 | ||
Jinja2==2.10.1 | ||
jmespath==0.9.4 | ||
joblib==0.14.0 | ||
jsonschema==3.0.1 | ||
jupyter==1.0.0 | ||
jupyter-client==5.2.4 | ||
jupyter-console==6.0.0 | ||
jupyter-core==4.4.0 | ||
kiwisolver==1.1.0 | ||
kombu==4.6.0 | ||
lazy-object-proxy==1.4.3 | ||
lxml==4.5.0 | ||
MarkupSafe==1.1.1 | ||
matplotlib==3.1.1 | ||
mccabe==0.6.1 | ||
mistune==0.8.4 | ||
more-itertools==7.1.0 | ||
nbconvert==5.5.0 | ||
nbformat==4.4.0 | ||
networkx==2.3 | ||
node2vec==0.3.1 | ||
nose==1.3.7 | ||
notebook==5.7.8 | ||
numpy==1.16.4 | ||
oauth2client==4.1.3 | ||
oauthlib==3.0.1 | ||
packaging==19.0 | ||
pandas==0.24.2 | ||
pandas-datareader==0.9.0 | ||
pandocfilters==1.4.2 | ||
parso==0.4.0 | ||
pause==0.1.2 | ||
pbr==5.3.0 | ||
pdfminer3k==1.3.1 | ||
pexpect==4.7.0 | ||
pickleshare==0.7.5 | ||
Pillow==5.4.1 | ||
pluggy==0.12.0 | ||
ply==3.11 | ||
prometheus-client==0.6.0 | ||
prompt-toolkit==2.0.9 | ||
protobuf==3.10.0 | ||
ptyprocess==0.6.0 | ||
py==1.8.0 | ||
pyasn1==0.4.5 | ||
pyasn1-modules==0.2.5 | ||
pycparser==2.19 | ||
Pygments==2.4.0 | ||
pylint==2.4.4 | ||
pyOpenSSL==19.0.0 | ||
pyparsing==2.4.0 | ||
PyPDF2==1.26.0 | ||
pyrsistent==0.15.2 | ||
PySocks==1.7.0 | ||
pytest==5.0.1 | ||
python-dateutil==2.7.3 | ||
python-epo-ops-client==2.3.2 | ||
pytz==2019.1 | ||
PyYAML==3.13 | ||
pyzmq==18.0.1 | ||
qtconsole==4.4.4 | ||
requests==2.22.0 | ||
requests-futures==1.0.0 | ||
requests-oauthlib==1.2.0 | ||
rsa==3.4.2 | ||
s3transfer==0.2.1 | ||
scikit-learn==0.21.3 | ||
scipy==1.3.1 | ||
selenium==3.14.0 | ||
Send2Trash==1.5.0 | ||
six==1.11.0 | ||
sklearn==0.0 | ||
slate3k==0.5.3 | ||
smart-open==1.8.4 | ||
smmap2==2.0.5 | ||
soupsieve==2.0 | ||
sqlparse==0.3.0 | ||
stem==1.8.0 | ||
stevedore==1.30.1 | ||
tabula-py==1.3.1 | ||
tabulate==0.8.6 | ||
terminado==0.8.2 | ||
testpath==0.4.2 | ||
tornado==6.0.2 | ||
torrequest==0.1.0 | ||
tqdm==4.36.1 | ||
traitlets==4.3.2 | ||
tweepy==3.8.0 | ||
twython==3.7.0 | ||
typed-ast==1.4.1 | ||
tzlocal==1.5.1 | ||
Unidecode==1.0.23 | ||
uritemplate==3.0.0 | ||
urllib3==1.23 | ||
vine==1.3.0 | ||
virtualenv==16.6.1 | ||
virtualenv-clone==0.5.3 | ||
virtualenvwrapper==4.8.4 | ||
wagtail==2.5.1 | ||
wcwidth==0.1.7 | ||
webencodings==0.5.1 | ||
Werkzeug==0.15.4 | ||
widgetsnbextension==3.4.2 | ||
Willow==1.1 | ||
wrapt==1.11.2 | ||
xlrd==1.2.0 | ||
zipp==0.5.2 |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import pandas as pd | ||
import pandas_datareader as web | ||
import matplotlib.pyplot as plt | ||
import datetime | ||
|
||
def get_prices(ticker,startdate,enddate): | ||
prices_df = web.get_data_yahoo(ticker, | ||
start = startdate, | ||
end = enddate) | ||
prices_df = prices_df.drop(columns=['High', 'Low','Open','Close','Volume']) | ||
return prices_df | ||
|
||
def bollinger_bands(prices,ticker): | ||
prices['20 Day MA'] = prices['Adj Close'].rolling(window=20).mean() | ||
|
||
# set .std(ddof=0) for population std instead of sample | ||
prices['20 Day STD'] = prices['Adj Close'].rolling(window=20).std() | ||
|
||
prices['Upper Band'] = prices['20 Day MA'] + (prices['20 Day STD'] * 1.96) | ||
prices['Lower Band'] = prices['20 Day MA'] - (prices['20 Day STD'] * 1.96) | ||
|
||
# Simple Plot | ||
# set style, empty figure and axes | ||
plt.style.use('fivethirtyeight') | ||
fig = plt.figure(figsize=(12,6)) | ||
ax = fig.add_subplot(111) | ||
|
||
# Get index values for the X axis for facebook DataFrame | ||
x_axis = prices.index.get_level_values(0) | ||
|
||
# Plot shaded 21 Day Bollinger Band for Facebook | ||
ax.fill_between(x_axis, prices['Upper Band'], prices['Lower Band'], color='grey') | ||
|
||
# Plot Adjust Closing Price and Moving Averages | ||
ax.plot(x_axis, prices['Adj Close'], color='blue', lw=2) | ||
ax.plot(x_axis, prices['20 Day MA'], color='black', lw=2) | ||
|
||
# Set Title & Show the Image | ||
ax.set_title('20 Day Bollinger Band For ' + ticker) | ||
ax.set_xlabel('Date') | ||
ax.set_ylabel('Price(USD)') | ||
ax.legend(prices[['Adj Close', '20 Day MA']]) | ||
plt.show() | ||
|
||
|
||
def main(): | ||
|
||
ticker = input("Please input the stock ticker:").upper() | ||
startdate = input("Please input the start date in YYYY-MM-DD format:") | ||
enddate = input("Please input the end date in YYYY-MM-DD format:") | ||
|
||
prices = get_prices(ticker,startdate,enddate) | ||
bollinger_bands(prices,ticker) | ||
|
||
if __name__ == "__main__": | ||
main() |
Binary file not shown.
Oops, something went wrong.