def single_MC_run(): # gatherer = MeanGatherer() gatherer = SDGatherer() gatherer_ct = ConvergenceTable(gatherer, numofpaths) path_gen = GeneratorGBM(market_params=market_params) pricer_mc = VanillaMCPricer(spot=Spot, rate=rate, Vol=Vol, generator=path_gen, gatherer=gatherer_ct, num_paths=numofpaths) po = VanillaCall(Strike=Strike) option = VanillaOption(Expiry=Expiry, PayOff=po) pricer_mc.do_trade(trade=option) print "MC price", pricer_mc.price res_table = pd.DataFrame(gatherer_ct.table)[['mean', 'sd', 'paths_done']] res_table['smean_sd'] = res_table['sd'] / res_table['paths_done'] print res_table
def CallMCDelbmp_WithSeedReset(x): """ This function for testing bump delta but WITH seed setting Should give good result Note that dependence on spot is actually in the path generator """ gatherer = SDGatherer() market_params2 = dict(market_params) market_params2['spot'] = x path_gen = GeneratorGBM(market_params=market_params2) path_gen.generator.set_seed(seed=0) pricer_mc = VanillaMCPricer(spot=x, rate=rate, Vol=Vol, generator=path_gen, gatherer=gatherer, num_paths=numofpaths) po = VanillaCall(Strike=Strike) option = VanillaOption(Expiry=Expiry, PayOff=po) pricer_mc.do_trade(trade=option) return pricer_mc.price
def single_MC_run(): # gatherer = MeanGatherer() gatherer = SDGatherer() gatherer_ct = ConvergenceTable(gatherer,numofpaths) path_gen = GeneratorGBM(market_params=market_params) pricer_mc= VanillaMCPricer(spot=Spot, rate=rate, Vol=Vol, generator=path_gen, gatherer=gatherer_ct, num_paths=numofpaths) po = VanillaCall(Strike=Strike) option = VanillaOption(Expiry=Expiry, PayOff=po) pricer_mc.do_trade(trade=option) print "MC price", pricer_mc.price res_table = pd.DataFrame(gatherer_ct.table)[['mean','sd','paths_done']] res_table['smean_sd']= res_table['sd']/res_table['paths_done'] print res_table
def CallMCDelbmp_WithSeedReset(x): """ This function for testing bump delta but WITH seed setting Should give good result Note that dependence on spot is actually in the path generator """ gatherer = SDGatherer() market_params2 = dict(market_params) market_params2['spot'] = x path_gen = GeneratorGBM(market_params = market_params2) path_gen.generator.set_seed(seed=0) pricer_mc= VanillaMCPricer(spot=x, rate=rate, Vol=Vol, generator=path_gen, gatherer=gatherer, num_paths=numofpaths) po = VanillaCall(Strike=Strike) option = VanillaOption(Expiry=Expiry, PayOff=po) pricer_mc.do_trade(trade=option) return pricer_mc.price
def range_pars_sim(do_plots=True): Spots = np.linspace(90, 110, num=40) Vols = np.array([0.01, 0.05, 0.1, 0.2, 0.5]) Expiries = np.array([0.1, 0, 25, 0.5, 1, 5]) vcall_anal = [ BSAnalyticFormulas(thisSpot, Strike, rate, Vol, Expiry, dividend).CallPrice() for thisSpot in Spots ] vcall_mc = [] #Do MC for thisSpot in Spots: gatherer = SDGatherer() ngen = NormalGenerator() path_gen = GeneratorGBM(spot=thisSpot, rate=rate, vol=Vol, times=[Expiry]) pricer_mc = VanillaMCPricer(spot=Spot, rate=rate, Vol=Vol, generator=path_gen, gatherer=gatherer, num_paths=numofpaths) po = VanillaCall(Strike=Strike) # po= VanillaDigitalPut(Strike=Strike) option = VanillaOption(Expiry=Expiry, PayOff=po) pricer_mc.do_trade(trade=option) vcall_mc += [pricer_mc.price] print vcall_mc[0:5] print Spots[0:5] import matplotlib.pyplot as plt if do_plots: plt.plot(Spots, vcall_mc) plt.show()
def range_pars_sim(do_plots=True): Spots = np.linspace(90, 110, num=40) Vols = np.array([0.01,0.05,0.1,0.2,0.5]) Expiries = np.array([0.1,0,25,0.5,1,5]) vcall_anal = [ BSAnalyticFormulas(thisSpot,Strike,rate,Vol,Expiry,dividend).CallPrice() for thisSpot in Spots] vcall_mc = [] #Do MC for thisSpot in Spots: gatherer = SDGatherer() ngen = NormalGenerator() path_gen = GeneratorGBM(spot=thisSpot, rate=rate, vol=Vol, times=[Expiry]) pricer_mc= VanillaMCPricer(spot=Spot, rate=rate, Vol=Vol, generator=path_gen, gatherer=gatherer, num_paths=numofpaths) po = VanillaCall(Strike=Strike) # po= VanillaDigitalPut(Strike=Strike) option = VanillaOption(Expiry=Expiry, PayOff=po) pricer_mc.do_trade(trade=option) vcall_mc += [pricer_mc.price] print vcall_mc[0:5] print Spots[0:5] import matplotlib.pyplot as plt if do_plots: plt.plot(Spots,vcall_mc) plt.show()