I desparately need help replacing my Quantopian language with QuantConnect language. Can anyone advise how I can replace items 1 through 5 below? See the log below the code to see the result.

#The following code has been adapted to ask the above question in forum.
for stock in context.portfolio.positions:
avg_price = context.portfolio.positions[stock].cost_basis
shares_qty = context.portfolio.positions[stock].amount
total_cost = avg_price * shares_qty
context.do[stock] = 1
print "1-" #Identifier to aid with reading log.
print context.portfolio.positions #Outputs dictionary, with info on stock and related info
print "2-"
print context.portfolio.positions[stock].cost_basis # Average cost per share for stock.
print "3-"
print context.portfolio.positions[stock].amount # Number of shares owned of this stock
print "4-"
print context.portfolio.positions[stock].last_sale_date #When did this position open? (my algo only opens and closes, no rebalancing, so it will be the date when position opened)
print "5-"
print context.portfolio.portfolio_value #Whats the total account value? = Cash + Current value of positions.

2017-07-24 08:45 PRINT 1-

2017-07-24 08:45 PRINT {Equity(3496 [HD]): Position({'last_sale_date': Timestamp('2017-07-21 14:01:00+0000', tz='UTC'), 'amount': 24, 'last_sale_price': 146.6, 'asset': Equity(3496 [HD]), 'cost_basis': 146.42667096119587})}

2017-07-24 08:45 PRINT 2-

2017-07-24 08:45 PRINT 146.426670961

2017-07-24 08:45 PRINT 3-

2017-07-24 08:45 PRINT 24

2017-07-24 08:45 PRINT 4-

2017-07-24 08:45 PRINT 2017-07-21 14:01:00+00:00

2017-07-24 08:45 PRINT 5-

2017-07-24 08:45 PRINT 7504.15989693

 

Author