/
NewsTrader.py
75 lines (53 loc) · 2.52 KB
/
NewsTrader.py
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
#########################################################################
#########################################################################
### VIVEK PATEL ###
### TRADING STRATEGIES AND SYSTEMS, SPRING 2011 ###
### PROFESSOR DHAR ###
#########################################################################
#########################################################################
"""
Main class.
Here we control everything:
1. We first create a query object, and query the database, returning a tuple with dates altered to compare with yahoo's stock dates.
2. Go through each line of the query, each article, and check the positive, negative, and uncertain words. Then calculate the sentiment.
3. Create a query object, and get the historical prices - start and last day is the date of the first and last article, respectively.
4. Merge reuterVector and yahooVector to make a mergeObj, with which you can start running tests on.
5. Run the strategy - get lagged correlations, get a 10 day MA of those lagged correlations to get a more accurate feeling of sentiment.
Get signals from day10MA, take a position.
Realize the returns the day after.
Run strategy metrics.
6. Print output of results.
Plot results.
"""
from ReutersQuery import ReutersQuery
from Sentiment import Sentiment
from YahooQuery import YahooQuery
from DateFormat import DateFormat
from Merge import Merge
from Strategy import Strategy
from Output import Output
import warnings
def fxn():
warnings.warn("deprecated", DeprecationWarning)
with warnings.catch_warnings():
warnings.simplefilter("ignore")
fxn()
def main():
ticker = raw_input("\n\n\n----------------------------------------------\nWelcome. Ready to trade? Pick a stock ticker: ")
reuterObj = ReutersQuery()
reuterVector = reuterObj.getQuery(ticker)
sentimentObj = Sentiment()
sentiments = sentimentObj.sentimentVectorize(reuterVector)
yahooObj = YahooQuery()
yahooVector = yahooObj.doYahooQuery(ticker, reuterVector)
reuterDates = DateFormat()
dates = reuterDates.fixDates(reuterVector)
mergeObj = Merge()
merged = mergeObj.mergeEverything(sentiments, yahooVector, dates)
strategyObj = Strategy()
metrics = strategyObj.runStrategy(ticker, merged)
outputObj = Output()
outputObj.putOutput(ticker, metrics, yahooVector, merged)
print '\nThanks for trading with Vivek! Get money, get paid!'
if __name__ == "__main__":
main()