I am satisfied.
credit to @sentdex
Thank Harrison, you are very informative!
I am satisfied.
credit to @sentdex
Thank Harrison, you are very informative!
Nice sentiment :) (algo utilizes sentimental analysis)
Sorry to say there's more to do, you'll want to address the leverage, currently over 10. Max 3 for contest.
def initialize(context):
context.max_lvrg = 0
def handle_data(context, data):
if context.account.leverage > context.max_lvrg:
context.max_lvrg = context.account.leverage
record( max_lvrg = context.max_lvrg )
As the try/except is to avoid: 'SIDData' object has no attribute 'price' ...
I would think this could obviate the need for it however I don't know why the output is different.
for s in data:
if 'price' not in data[s]: continue
f (sentiment > 5) and (current == 0):
if cash > context.investment_size:
order_value(s, context.investment_size, style = StopOrder(context.stop_loss_pct*current))
cash -= context.investment_size
Are you intending to put a stop loss of 0% ? Since current == 0 for this condition
@Alon Yariv
I am not used to fetcher . But I tried to tweak your algo . Doesn't seem to be producing any results though , mind having a look ?
def initialize(context):
context.max_invest = (context.portfolio.portfolio_value/10)
set_symbol_lookup_date('2012-10-1')
context.stocks =symbols('AAPL','C','TM','MSFT','EBAY','WMT','IBM','XOM','NOK','FB','MCD')
fetch_csv('http://sentdex.com/api/finance/sentiment-signals/sample/')
def handle_data(context,data):
for s in data:
if 'sentiment_signal' in data[s]:
sentiment = data[s]['sentiment_signal']
if sentiment < 3 and s in context.portfolio.positions:
order_target(s,0)
if sentiment > 3 and context.portfolio.cash > context.max_invest:
if s not in context.portfolio.positions:
order_value(s,context.max_invest,style = StopOrder(context.max_invest*0.9))
if (data[s].mavg(200) > data[s].mavg[50]) and (sentiment<1):
if s not in context.portfolio.positions:
order_target_value(s,(-1)*context.max_invest)