Example #1
0
def lookup_driver_asset(driver):
    session = Session()
    asset = session.query(Asset).filter(Asset.id == driver.asset_id).first()
    if hasattr(asset, 'expiry'):
        # pre-load asset expiry for Derivative type assets
        asset.expiry
    session.close()
    return asset
def get_forward_rate_assets(discount_curve):
    asset_class_id = discount_curve.asset_class_id
    max_expiration_date = max((ei.expiry.expiration_date for ei in discount_curve.expiry_impls)) + timedelta(days=180)
    session = Session()
    assets = session.query(Future)\
        .join(Expiry)\
        .filter(Future.asset_class_id == asset_class_id)\
        .filter(Expiry.expiration_date <= max_expiration_date)\
        .filter(Expiry.expiration_date >= datetime.today())\
        .options(subqueryload(Future.expiry))\
        .order_by(Expiry.expiration_date)\
        .all()
    session.close()
    return assets