-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmoon.py
More file actions
40 lines (31 loc) · 1.07 KB
/
moon.py
File metadata and controls
40 lines (31 loc) · 1.07 KB
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
""" playing with the moon """
import os
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import pandas_datareader.data as web
def symbol_to_path(symbol, base_dir="data"):
"""Return CSV file path given ticker symbol."""
return os.path.join(base_dir, "{}.csv".format(str(symbol)))
def get_data(tickers, start, end):
dates = pd.date_range(start, end)
df = pd.DataFrame(index=dates)
for ticker in tickers:
dftemp = web.DataReader(ticker, "yahoo", start, end)
dftemp = pd.DataFrame(dftemp, columns=["Adj Close"])
dftemp = dftemp.rename(columns={"Adj Close": ticker})
df = df.join(dftemp)
dftemp = pd.read_csv(symbol_to_path("moon"), index_col='date',
parse_dates=True, usecols=['date', 'phaseid'], na_values=['nan'])
print dftemp.head()
df = df.join(dftemp * 2 + 10)
df = df.fillna(method="ffill")
return df
def main():
df = get_data(["SLV"], '2015-01-01', '2016-02-29')
print df.head(10)
print df.tail(10)
df.plot()
plt.show()
if __name__ == "__main__":
main()