<jupyter_start><jupyter_text>Buy call spread, sell out-of-the-money put<jupyter_code># Portfolio def

ccy = 'USD'
expiry = '1y'
tail = '10y'
rate_option = 'USD-LIBOR-BBA'
pay_rec = ['Receiver', 'Receive', 'Pay']
strikes = ['A-50', 'A-25', 'A+50']
direction = [-1, 1, -1]
notional_inception = round(strategy_notional/(ramp_up_period+1), 0)

port = []
for i in range(len(pay_rec)):
    opt = IRSwaption(pay_or_receive=pay_rec[i],
                     termination_date=tail,
                     notional_currency=ccy,
                     expiration_date=expiry,
                     notional_amount=direction[i]*notional_inception,
                     strike = strikes[i],
                     floating_rate_option=rate_option,
                     name='swaption'+str(i))
    port.append(opt)

csa_string = ccy + '-1'    
    
seagull = Portfolio(port, name='Seagull')
seagull.to_frame().transpose()
# Define deltas
myParallelDelta = IRDelta(currency='local', aggregation_level=AggregationLevel.Type)

# Define backtest
trade_action = AddTradeAction(seagull, holding_period)
trigger = PeriodicTrigger(PeriodicTriggerRequirements(start_date=start, end_date=end, frequency=freq), [trade_action])
strategy = Strategy(None, trigger)

# Select an engine
GE = GenericEngine()
backtest = GE.run_backtest(strategy, start=start, end=end,frequency=freq, risks=[Price, myParallelDelta], 
                           show_progress=True, csa_term=csa_string)
backtest_summary = backtest.result_summary
backtest_summary
backtest_dates_reduced = backtest_summary.index

with HistoricalPricingContext(dates = backtest_dates_reduced, show_progress=True):
    ir_rates = seagull[0].calc([IRFwdRate, IRDailyImpliedVol])
    entry = seagull.calc([DollarPrice])


premium = entry.result().to_frame()
raw_data = ir_rates.result().to_frame()
raw_data[IRFwdRate] *= 1e4
raw_data['entry_premium'] = (premium.iloc[:,0]+premium.iloc[:,1]+premium.iloc[:,2])
raw_data.describe()
(backtest_summary['Cumulative Cash']/1e6).plot(title='Rolling Seagull vs Delta Proxy', legend=True, label='Strategy', figsize=(20, 10))
(backtest_summary.iloc[5, 1] * (raw_data[IRFwdRate]-raw_data[IRFwdRate][0])/1e6).plot(legend=True, 
                            label=f'Delta Proxy ({round(backtest_summary.iloc[5, 1]/1e3, 0)}k per bp)')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13540319103061665, 'fraction_numerical': 0.015955153083225527, 'mean_word_length': 4.333333333333333, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '640392', 'license': 'Apache-2.0', 'n_tokens_mistral': 846, 'n_tokens_neox': 802, 'n_words': 128, 'path': 'gs_quant/documentation/04_backtesting/examples/03_GenericEngine/040307_strategy_seagull_bullish.ipynb', 'repo_name': 'webclinic017/gs-quant', 'size': '2319'}