Skip to content
This repository has been archived by the owner on Jun 3, 2023. It is now read-only.

Added in depth comments to the analysis.py file #46

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ def should_trade(strategy, date, previous_trade_date):
date.replace(hour=0, minute=0, second=0)):
return False

# The strategy needs to be active.
# The strategy needs to be active for the trade to occur.
if strategy["action"] == "hold":
return False

# We need to know the stock price.
# We need to know the stock price before trading.
if not strategy["price_at"] or not strategy["price_eod"]:
return False

Expand Down Expand Up @@ -138,11 +138,11 @@ def should_trade(strategy, date, previous_trade_date):
strategies = []
for company in companies:

# What would have been the strategy?
# Uses the market status to find the trading strategy
market_status = get_market_status(timestamp)
strategy = trading.get_strategy(company, market_status)

# What was the price at tweet and at EOD?
# Returns the price of the stock when the tweet was sent and at the end of the day
price = trading.get_historical_prices(
company["ticker"], timestamp)
if price:
Expand Down Expand Up @@ -179,7 +179,7 @@ def should_trade(strategy, date, previous_trade_date):
print ("Here's each tweet with the results of its analysis and individual "
"market performance.")

for event in events:
for event in events:##formats the data given into a table
strategies = event["strategies"]

if strategies:
Expand All @@ -192,7 +192,7 @@ def should_trade(strategy, date, previous_trade_date):
print
print "*Strategy*"
print
print "Company | Root | Sentiment | Strategy | Reason"
print "Company | Root | Sentiment | Strategy | Reason"##The Strategy Table is organized in this format
print "--------|------|-----------|----------|-------"

for strategy in strategies:
Expand All @@ -210,7 +210,7 @@ def should_trade(strategy, date, previous_trade_date):
print
print "*Performance*"
print
print "Ticker | Exchange | Price @ tweet | Price @ close | Gain"
print "Ticker | Exchange | Price @ tweet | Price @ close | Gain"##The Performance Table is organized in this format
print "-------|----------|---------------|---------------|-----"

for strategy in strategies:
Expand Down Expand Up @@ -250,7 +250,7 @@ def should_trade(strategy, date, previous_trade_date):
date = event["timestamp"]
strategies = event["strategies"]

# Figure out what to spend on each trade.
# Figure out how much to spend on each trade.
num_actionable_strategies = sum(
[1 for strategy in strategies if should_trade(
strategy, date, previous_trade_date)])
Expand Down Expand Up @@ -281,10 +281,10 @@ def should_trade(strategy, date, previous_trade_date):
quantity = 0

total_ratio = value / FUND_DOLLARS
total_return = format_ratio(total_ratio)
total_return = format_ratio(total_ratio)##Calculates and formats the total ratio

if date != start_date:
days = (date - start_date).days
days = (date - start_date).days##Calculates the number of days trading has occurred for
if days > 0:
annualized_ratio = pow(total_ratio, 365.0 / days)
else:
Expand All @@ -298,7 +298,7 @@ def should_trade(strategy, date, previous_trade_date):
strategy["ticker"],
get_sentiment_emoji(strategy["sentiment"]))
ratio = get_ratio(strategy)
gain = format_ratio(ratio)
gain = format_ratio(ratio)##gets the ratio and formats it

if trade:
date_str = "**%s**" % date_str
Expand Down