Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdb8b668

Browse files
committed
added intro to finance & technical indicators tutorial
1 parent189dc86 commitdb8b668

File tree

5 files changed

+302
-0
lines changed

5 files changed

+302
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ This is a repository of all the tutorials of [The Python Code](https://www.thepy
5252
-[How to Predict Stock Prices in Python using TensorFlow 2 and Keras](https://www.thepythoncode.com/article/stock-price-prediction-in-python-using-tensorflow-2-and-keras). ([code](machine-learning/stock-prediction))
5353
-[How to Convert Text to Speech in Python](https://www.thepythoncode.com/article/convert-text-to-speech-in-python). ([code](machine-learning/text-to-speech))
5454
-[How to Perform Voice Gender Recognition using TensorFlow in Python](https://www.thepythoncode.com/article/gender-recognition-by-voice-using-tensorflow-in-python). ([code](https://github.com/x4nth055/gender-recognition-by-voice))
55+
-[Introduction to Finance and Technical Indicators with Python](https://www.thepythoncode.com/article/introduction-to-finance-and-technical-indicators-with-python). ([code](machine-learning/technical-indicators))
5556

5657

5758
-###[General Python Topics](https://www.thepythoncode.com/topic/general-python-topics)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#[Introduction to Finance and Technical Indicators with Python](https://www.thepythoncode.com/article/introduction-to-finance-and-technical-indicators-with-python)
2+
To run this:
3+
-`pip3 install -r requirements.txt`
4+
- Please check[the notebook](technical_indicators.ipynb) or the[Python script](technical_indicators.py)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
pandas-datareader
2+
yfinance
3+
mpl-finance
4+
stockstats

‎machine-learning/technical-indicators/technical_indicators.ipynb

Lines changed: 222 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# To add a new cell, type '# %%'
2+
# To add a new markdown cell, type '# %% [markdown]'
3+
4+
# %%
5+
importyfinanceasyf
6+
importpandas_datareaderaspdr
7+
frommpl_financeimportcandlestick_ohlc
8+
importmatplotlib.pyplotasplt
9+
10+
11+
# %%
12+
# import SPY stock price
13+
df_spy=pdr.get_data_yahoo("SPY",start="2019-01-01",end="2019-09-30")
14+
# import AAPL stock price
15+
df_aapl=pdr.get_data_yahoo("AAPL",start="2019-01-01",end="2019-09-30")
16+
17+
18+
# %%
19+
df_spy.head()
20+
21+
22+
# %%
23+
df_aapl[["Open","High","Low","Close"]].plot()
24+
plt.show()
25+
26+
27+
# %%
28+
fig=plt.figure(figsize=(10,10))
29+
ax=plt.subplot()
30+
31+
plot_data= []
32+
foriinrange(150,len(df_aapl)):
33+
row= [
34+
i,
35+
df_aapl.Open.iloc[i],
36+
df_aapl.High.iloc[i],
37+
df_aapl.Low.iloc[i],
38+
df_aapl.Close.iloc[i],
39+
]
40+
plot_data.append(row)
41+
candlestick_ohlc(ax,plot_data)
42+
plt.show()
43+
44+
45+
# %%
46+
fromstockstatsimportStockDataFrame
47+
stocks=StockDataFrame.retype(df_aapl[["Open","Close","High","Low","Volume"]])
48+
49+
50+
# %%
51+
plt.plot(stocks["close_10_sma"],color="b",label="SMA")
52+
plt.plot(df_aapl.Close,color="g",label="Close prices")
53+
plt.legend(loc="lower right")
54+
plt.show()
55+
56+
57+
# %%
58+
plt.plot(stocks["close_10_sma"],color="b",label="SMA")# plotting SMA
59+
plt.plot(stocks["close_10_ema"],color="k",label="EMA")
60+
plt.plot(df_aapl.Close,color="g",label="Close prices")# plotting close prices
61+
plt.legend(loc="lower right")
62+
plt.show()
63+
64+
65+
# %%
66+
plt.plot(stocks["macd"],color="b",label="MACD")
67+
plt.plot(stocks["macds"],color="g",label="Signal Line")
68+
plt.legend(loc="lower right")
69+
plt.show()
70+
71+

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp