Just for testing. ...
I cloned the algo "Google Search Terms predict market movements",
but instead of using Google Search, I am using the 1 month of News sentiment data on Apple from historical FinSentS data.
import numpy as np
Average over 2 weeks, free parameter.
delta_t = 5
This is the search query we are using, this is tied to the csv file.
context.query = 'Sentiment'
Use fetcher to get data.
News sentiment data extracted from the files and format it in another excel file. This is purely a test data, please feel free to use.
Note: To my understanding it is a daily score that represent average of sentiment scores of Articles mentioning Apple in Business and Financial News.
context.order_size = 1000
context.sec_id = 24
context.security = sid(24) # Apple
def handle_data(context, data):
c = context
if c.query not in data[c.query]:
Extract Sentiment scores of search query.
indicator = data[c.query][c.query]
Buy and hold strategy that enters on the first day of the week and exits after one week.
# if data[c.security].dt.weekday() == 0: # Monday
# Compute average over weeks in range [t-delta_t-1, t[
mean_indicator = mean_past_queries(data, c.query)
if mean_indicator is None:
amount = c.portfolio['positions'][c.sec_id].amount
if (amount < 0) and (mean_indicator < indicator):
if (amount > 0) and (mean_indicator > indicator):
# amountA = c.portfolio['positions'][c.sec_id].amount
# log.info('amount after')
Long or short depending on whether sentiment is clearly down or up, respectively.
#if indicator > mean_indicator and indicator < 35:
if indicator < 35:
#if (indicator < mean_indicator) and (indicator < 35):
if indicator > 70:
# if (indicator > mean_indicator) and (indicator > 70):
def mean_past_queries(data, query):
# Compute mean over all events except most current one.
This is quite simple and not very realistic...