-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathweek6.html
232 lines (210 loc) · 8.38 KB
/
week6.html
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Week 6: Pandas and Financial Data Analysis</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<style>
.key-concept {
background-color: #f8f9fa;
border-left: 4px solid #007bff;
padding: 15px;
margin: 15px 0;
}
.exercise {
background-color: #e9ecef;
padding: 15px;
margin: 10px 0;
border-radius: 5px;
}
.resource-link {
background-color: #fff;
padding: 10px;
margin: 5px 0;
border: 1px solid #dee2e6;
border-radius: 5px;
}
.research-tip {
background-color: #d1ecf1;
border: 1px solid #bee5eb;
padding: 10px;
margin: 10px 0;
border-radius: 5px;
font-size: 0.9em;
}
.chatgpt-tip {
background-color: #d1ecf1;
border: 1px solid #bee5eb;
padding: 15px;
margin: 15px 0;
border-radius: 5px;
}
.code-example {
background-color: #f8f9fa;
padding: 15px;
border-radius: 5px;
font-family: monospace;
margin: 10px 0;
}
</style>
</head>
<body>
<nav>
<ul class="nav-links" style="display: flex; gap: 20px; list-style-type: none; padding: 0; font-weight: bold; font-size: 1.2em; justify-content: center;">
<li><a href="index.html" style="text-decoration: none; color: #007bff;">Home</a></li>
<li><a href="about.html" style="text-decoration: none; color: #007bff;">About</a></li>
<li><a href="contact.html" style="text-decoration: none; color: #007bff;">Contact</a></li>
</ul>
</nav>
<div class="container">
<div class="key-concept">
<h2>Week 6: Pandas and Financial Data Analysis</h2>
<p class="lead">Learn how to use pandas for financial data analysis and fetch real market data using yfinance and pandas_datareader.</p>
</div>
<h3>Learning Objectives:</h3>
<ul>
<li>✓ Master pandas DataFrame operations for financial data</li>
<li>✓ Learn to fetch real market data using yfinance</li>
<li>✓ Understand time series analysis with pandas</li>
<li>✓ Create financial reports and visualizations</li>
</ul>
<div class="resource-link">
<h4>1. Introduction to Pandas</h4>
<p>Understanding pandas DataFrame basics for financial data.</p>
<div class="code-example">
<pre>
import pandas as pd
import numpy as np
# Create a DataFrame with stock data
data = {
'Symbol': ['AAPL', 'MSFT', 'GOOGL'],
'Price': [190.50, 375.00, 140.50],
'Shares': [100, 50, 75]
}
df = pd.DataFrame(data)
# Calculate position values
df['Position Value'] = df['Price'] * df['Shares']
# Basic statistics
print(df.describe()) # Summary statistics
print(df.groupby('Symbol').sum()) # Group by symbol</pre>
</div>
<a href="https://pandas.pydata.org/docs/getting_started/index.html" target="_blank">Read more about Pandas</a>
<div class="research-tip">
<p>📚 <strong>Can't access the link?</strong> Use <a href="https://www.perplexity.ai/" target="_blank">Perplexity.ai</a> and search for "pandas DataFrame tutorial for finance"</p>
</div>
</div>
<div class="resource-link">
<h4>2. Fetching Market Data</h4>
<p>Using yfinance and pandas_datareader to get real market data.</p>
<div class="code-example">
<pre>
import yfinance as yf
import pandas_datareader as pdr
# Download Apple stock data
aapl = yf.download('AAPL',
start='2023-01-01',
end='2023-12-31')
# Calculate daily returns
aapl['Returns'] = aapl['Adj Close'].pct_change()
# Get multiple stocks using pandas_datareader
tickers = ['AAPL', 'MSFT', 'GOOGL']
portfolio = pdr.get_data_yahoo(tickers,
start='2023-01-01',
end='2023-12-31')['Adj Close']
# Calculate correlation matrix
correlation = portfolio.corr()</pre>
</div>
<a href="https://pypi.org/project/yfinance/" target="_blank">Read more about yfinance</a>
</div>
<div class="resource-link">
<h4>3. Time Series Analysis</h4>
<p>Working with financial time series in pandas.</p>
<div class="code-example">
<pre>
# Resample data to monthly frequency
monthly = aapl['Adj Close'].resample('M').last()
# Calculate moving averages
aapl['MA50'] = aapl['Adj Close'].rolling(window=50).mean()
aapl['MA200'] = aapl['Adj Close'].rolling(window=200).mean()
# Generate trading signals
aapl['Signal'] = np.where(aapl['MA50'] > aapl['MA200'], 1, -1)
# Calculate returns by time period
returns = {
'Daily': aapl['Returns'].mean(),
'Monthly': aapl['Returns'].resample('M').mean(),
'Annual': aapl['Returns'].resample('Y').mean()
}</pre>
</div>
</div>
<h3>Exercises:</h3>
<div class="exercise">
<ol>
<li>Create a market data dashboard:
<ul>
<li>Download data for multiple stocks using yfinance</li>
<li>Calculate daily returns and volatility</li>
<li>Generate performance summary using pandas</li>
</ul>
</li>
<li>Implement a technical analysis system:
<ul>
<li>Calculate various moving averages</li>
<li>Generate trading signals</li>
<li>Backtest strategy performance</li>
</ul>
</li>
<li>Build a portfolio analysis tool:
<ul>
<li>Track multiple stocks performance</li>
<li>Calculate portfolio statistics</li>
<li>Generate risk metrics (Beta, Sharpe Ratio)</li>
</ul>
</li>
<li>Create a market sentiment analyzer:
<ul>
<li>Download index data (S&P 500, NASDAQ)</li>
<li>Calculate market breadth indicators</li>
<li>Generate market health report</li>
</ul>
</li>
<li>Develop a dividend analysis tool:
<ul>
<li>Download dividend history</li>
<li>Calculate dividend growth rates</li>
<li>Project future dividend income</li>
</ul>
</li>
<li>Create a sector rotation analysis:
<ul>
<li>Download sector ETF data</li>
<li>Compare sector performance</li>
<li>Identify sector trends</li>
</ul>
</li>
</ol>
</div>
<div class="chatgpt-tip">
<h4>💡 ChatGPT Learning Tips</h4>
<p>Use these prompts to enhance your learning:</p>
<ol>
<li>"Show me how to handle missing data in pandas with financial time series"</li>
<li>"Explain how to calculate rolling statistics for stock prices"</li>
<li>"Help me understand how to merge data from different sources in pandas"</li>
<li>"What are the best practices for handling dates in financial data analysis?"</li>
</ol>
</div>
</div>
<div style="text-align: center; margin-top: 20px;">
<a href="week5.html">← Previous Week</a>
|
<a href="week7.html">Next Week →</a>
</div>
<div class="back-to-home">
<a href="index.html">← Back to Home</a>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</body>
</html>