@@ -15,35 +15,58 @@ def main():
1515 # solver1 = pde.Heat1DCNSolver(equation1)
1616 # solver2 = pde.Heat1DExplicitSolver(equation1)
1717
18- # testing for monte carlo pricing
18+ # testing 2d heat equation
19+
20+ xLength = 10 # Lx
21+ yLength = 10 # Ly
22+ maxTime = 0.5 # tmax
23+ diffusivityConstant = 4 # kappa
24+ numPointsSpace = 50 # x_points = y_points
25+ numPointsTime = 2000 # t_points
26+
27+ equation = (pde .HeatEquation2D (maxTime , numPointsTime , diffusivityConstant , xLength , numPointsSpace ))
28+ equation .set_initial_temp (lambda x , y : 10 * np .exp (- ((x - xLength / 2 )** 2 + (y - yLength / 2 )** 2 ) / 2 ))
29+ equation .set_right_boundary_temp (lambda t , y : 20 + 100 * y * (yLength - y )** 3 * (t - 1 )** 2 * (t > 1 ))
30+ equation .set_left_boundary_temp (lambda t , y : 20 + 10 * y * (yLength - y ) * t ** 2 )
31+ equation .set_top_boundary_temp (lambda t , x : 20 + 5 * x * (xLength - x ) * t ** 4 )
32+ equation .set_bottom_boundary_temp (lambda t , x : 20 )
1933
20- ticker = 'AAPL'
34+ solver1 = pde .Heat2DExplicitSolver (equation )
35+ solver1 = pde .Heat2DCNSolver (equation )
36+ solution1 = solver1 .solve ()
37+ solution1 .animate (filename = "Explicit" )
38+ solver2 = pde .Heat2DCNSolver (equation )
39+ solution2 = solver2 .solve ()
40+ solution2 .animate (filename = "Crank-Nicolson" )
41+
42+ # testing for monte carlo pricing
43+ # ticker = 'AAPL'
2144
22- # STOCK
23- historical_data = pde .HistoricalStockData (ticker )
24- historical_data .fetch_stock_data ( "2024-03-21" ,"2025-03-21" )
25- sigma , r = historical_data .estimate_metrics ()
26- current_price = historical_data .get_latest_stock_price ()
45+ # # STOCK
46+ # historical_data = pde.HistoricalStockData(ticker)
47+ # historical_data.fetch_stock_data( "2024-03-21","2025-03-21")
48+ # sigma, r = historical_data.estimate_metrics()
49+ # current_price = historical_data.get_latest_stock_price()
2750
28- equation2 = pde .BlackScholesEquation (pde .OptionType .EUROPEAN_CALL , current_price , 100 , r , sigma , 1 , 100 , 20000 )
51+ # equation2 = pde.BlackScholesEquation(pde.OptionType.EUROPEAN_CALL, current_price, 100, r, sigma, 1, 100, 20000)
2952
30- solver1 = pde .BlackScholesCNSolver (equation2 )
31- solver2 = pde .BlackScholesExplicitSolver (equation2 )
32- sol1 = solver1 .solve ()
33- sol1 .plot ()
53+ # solver1 = pde.BlackScholesCNSolver(equation2)
54+ # solver2 = pde.BlackScholesExplicitSolver(equation2)
55+ # sol1 = solver1.solve()
56+ # sol1.plot()
3457
35- # COMPARISON
36- # look to see the corresponding option price for the expiration date and strike price
37- pricing_1 = pde .BlackScholesFormula (pde .OptionType .EUROPEAN_CALL , current_price , 100 , r , sigma , 1 )
38- pricing_2 = pde .MonteCarloPricing (pde .OptionType .EUROPEAN_CALL , current_price , 100 , r , sigma , 1 , 365 , 1000 )
58+ # # COMPARISON
59+ # # look to see the corresponding option price for the expiration date and strike price
60+ # pricing_1 = pde.BlackScholesFormula(pde.OptionType.EUROPEAN_CALL, current_price, 100, r, sigma, 1)
61+ # pricing_2 = pde.MonteCarloPricing(pde.OptionType.EUROPEAN_CALL, current_price, 100, r, sigma, 1, 365, 1000)
3962
40- bs_price = pricing_1 .get_black_scholes_merton_price ()
41- monte_carlo_price = pricing_2 .get_monte_carlo_option_price ()
63+ # bs_price = pricing_1.get_black_scholes_merton_price()
64+ # monte_carlo_price = pricing_2.get_monte_carlo_option_price()
4265
43- pde_price = sol1 .get_result ()[- 1 , 0 ]
44- print (f"PDE Price: { pde_price } " )
45- print (f"Black-Scholes Price: { bs_price } " )
46- print (f"Monte-Carlo Price: { monte_carlo_price } " )
66+ # pde_price = sol1.get_result()[-1, 0]
67+ # print(f"PDE Price: {pde_price}")
68+ # print(f"Black-Scholes Price: {bs_price}")
69+ # print(f"Monte-Carlo Price: {monte_carlo_price}")
4770
4871if __name__ == "__main__" :
4972 main ()
0 commit comments