Hi
why is it NOT executing buy orders based on the filters given?
Iteration over the asset is deprecated. How do I apply proper migration?
Thanks in advance
def initialize(context):
context.limit = 10
def before_trading_start(context):
context.fundamentals= get_fundamentals(
query(
fundamentals.valuation_ratios.pb_ratio,
fundamentals.valuation_ratios.pe_ratio
# put your query in here by typing "fundamentals."
)
.filter(
fundamentals.valuation_ratios.pe_ratio < 14
# put your filters here
.filter(
fundamentals.valuation_ratios.pb_ratio < 2
# put your filters here
)
.order_by(
fundamentals.valuation.market_cap.desc()
# sort your query
)
.limit(context.limit)
)
def handle_data(context, data):
#context:tracking info about our portfolio
#data: referts to the universe
cash = context.portfolio.cash
current_position = context.portfolio.positions
for stock in data:
current_position = context.portfolio.positions[stock].amount
stock_price = data[stock].price
plausible_investment = cash/10.0
share_amount = int(plausible_investment/stock_price)
try:
if stock_price < plausible_investment:
if current_position == 0:
if context.fundamentals[stock]['pe_ratio'] < 11:
order(stock, share_amount)
except Exception as e:
print(str(e))