Hi everyone,
First of all, i'd like to say that Quantopian is looking great and seems a very interesting platform.
I've been playing around with Quantopian. And i've noticed there are some strange discrepancies.
- I've yet to find a way to access single Transaction details. As I understand it is impossible to get properties on open positions from the same stock. I.e. If I buy Apple once at 100 and then later at 110, there is no way of retrieving the return on each transaction separately, as well as closing the separately. (Yes, I realise for many things it doesn't change much)
- It seems the Cost Basis isn't working properly. If I buy a stock and
log the cost basis, its not the same as the price paid, even though
no further stocks have been purchased. I assume i'm doing something
wrong...
cost_basis
Float: The volume-weighted average price paid (price and commission) per share in this position.
Output:
2014-05-05startportfolio:84INFOSetting up basic portfolio...
2014-05-05startportfolio:91INFOBuying ADBE : [email protected]**61.43** : 491.44
2014-05-05handle_data:52INFOCost Basis: ADBE : 0.0
2014-05-06handle_data:52INFOCost Basis: ADBE : 59.48
- Returns method
When using the returns method I keep getting an error. While any other method for data[sid] does seem to work in my code.
---error----
There was a runtime error.
RuntimeInvalidTransform: 0064 You accessed data in some way other than data[sid].returns. We do not support calling returns in other ways.
Code:
def handle_data(context, data):
# Implement your algorithm logic here.
# data[sid(X)] holds the trade event data for that stocks.
# context.portfolio holds the current portfolio state.
#General Vars
cash = context.portfolio.cash
#margin = int(cash/10)
#free_cash = int(cash - margin)
free_cash = cash
handle_data.target = int(free_cash * context.weight)
#log.info("Current Cash: %s" % (cash))
#log.info("Margin: %s" % (margin))
#log.info("Free Cash: %s" % (free_cash))
if context.portfolio.positions_value <= 0:
startportfolio(context, data)
#for stock in context.stocks:
returns = data[114].returns
log.info('Return %s' % (returns))
def startportfolio(context, data):
log.info("Setting up basic portfolio...")
for stock in context.stocks:
p_current_price = float(data[stock].price)
p_amount_order = int(0.5 * handle_data.target / p_current_price)
p_costs = p_amount_order * p_current_price
order(stock, +p_amount_order)
log.info('Buying %s' % (stock.symbol) + " - " + str(p_amount_order) + "@" + str(p_current_price) + " - %s" %p_costs )